Struct cargo_test_support::Execs
source · pub struct Execs {Show 17 fields
pub(crate) ran: bool,
pub(crate) process_builder: Option<ProcessBuilder>,
pub(crate) expect_stdout: Option<String>,
pub(crate) expect_stdin: Option<String>,
pub(crate) expect_stderr: Option<String>,
pub(crate) expect_exit_code: Option<i32>,
pub(crate) expect_stdout_contains: Vec<String>,
pub(crate) expect_stderr_contains: Vec<String>,
pub(crate) expect_stdout_contains_n: Vec<(String, usize)>,
pub(crate) expect_stdout_not_contains: Vec<String>,
pub(crate) expect_stderr_not_contains: Vec<String>,
pub(crate) expect_stdout_unordered: Vec<String>,
pub(crate) expect_stderr_unordered: Vec<String>,
pub(crate) expect_stderr_with_without: Vec<(Vec<String>, Vec<String>)>,
pub(crate) expect_json: Option<String>,
pub(crate) expect_json_contains_unordered: Option<String>,
pub(crate) stream_output: bool,
}
Fields§
§ran: bool
§process_builder: Option<ProcessBuilder>
§expect_stdout: Option<String>
§expect_stdin: Option<String>
§expect_stderr: Option<String>
§expect_exit_code: Option<i32>
§expect_stdout_contains: Vec<String>
§expect_stderr_contains: Vec<String>
§expect_stdout_contains_n: Vec<(String, usize)>
§expect_stdout_not_contains: Vec<String>
§expect_stderr_not_contains: Vec<String>
§expect_stdout_unordered: Vec<String>
§expect_stderr_unordered: Vec<String>
§expect_stderr_with_without: Vec<(Vec<String>, Vec<String>)>
§expect_json: Option<String>
§expect_json_contains_unordered: Option<String>
§stream_output: bool
Implementations§
source§impl Execs
impl Execs
pub fn with_process_builder(self, p: ProcessBuilder) -> Execs
sourcepub fn with_stdout<S: ToString>(&mut self, expected: S) -> &mut Self
pub fn with_stdout<S: ToString>(&mut self, expected: S) -> &mut Self
Verifies that stdout is equal to the given lines.
See compare
for supported patterns.
sourcepub fn with_stderr<S: ToString>(&mut self, expected: S) -> &mut Self
pub fn with_stderr<S: ToString>(&mut self, expected: S) -> &mut Self
Verifies that stderr is equal to the given lines.
See compare
for supported patterns.
sourcepub fn with_stdin<S: ToString>(&mut self, expected: S) -> &mut Self
pub fn with_stdin<S: ToString>(&mut self, expected: S) -> &mut Self
Writes the given lines to stdin.
sourcepub fn with_status(&mut self, expected: i32) -> &mut Self
pub fn with_status(&mut self, expected: i32) -> &mut Self
Verifies the exit code from the process.
This is not necessary if the expected exit code is 0
.
sourcepub fn without_status(&mut self) -> &mut Self
pub fn without_status(&mut self) -> &mut Self
Removes exit code check for the process.
By default, the expected exit code is 0
.
sourcepub fn with_stdout_contains<S: ToString>(&mut self, expected: S) -> &mut Self
pub fn with_stdout_contains<S: ToString>(&mut self, expected: S) -> &mut Self
Verifies that stdout contains the given contiguous lines somewhere in its output.
See compare
for supported patterns.
sourcepub fn with_stderr_contains<S: ToString>(&mut self, expected: S) -> &mut Self
pub fn with_stderr_contains<S: ToString>(&mut self, expected: S) -> &mut Self
Verifies that stderr contains the given contiguous lines somewhere in its output.
See compare
for supported patterns.
sourcepub fn with_stdout_contains_n<S: ToString>(
&mut self,
expected: S,
number: usize
) -> &mut Self
pub fn with_stdout_contains_n<S: ToString>( &mut self, expected: S, number: usize ) -> &mut Self
Verifies that stdout contains the given contiguous lines somewhere in
its output, and should be repeated number
times.
See compare
for supported patterns.
sourcepub fn with_stdout_does_not_contain<S: ToString>(
&mut self,
expected: S
) -> &mut Self
pub fn with_stdout_does_not_contain<S: ToString>( &mut self, expected: S ) -> &mut Self
Verifies that stdout does not contain the given contiguous lines.
See compare
for supported patterns.
See note on Self::with_stderr_does_not_contain
.
sourcepub fn with_stderr_does_not_contain<S: ToString>(
&mut self,
expected: S
) -> &mut Self
pub fn with_stderr_does_not_contain<S: ToString>( &mut self, expected: S ) -> &mut Self
Verifies that stderr does not contain the given contiguous lines.
See compare
for supported patterns.
Care should be taken when using this method because there is a limitless number of possible things that won’t appear. A typo means your test will pass without verifying the correct behavior. If possible, write the test first so that it fails, and then implement your fix/feature to make it pass.
sourcepub fn with_stdout_unordered<S: ToString>(&mut self, expected: S) -> &mut Self
pub fn with_stdout_unordered<S: ToString>(&mut self, expected: S) -> &mut Self
Verifies that all of the stdout output is equal to the given lines, ignoring the order of the lines.
See Execs::with_stderr_unordered
for more details.
sourcepub fn with_stderr_unordered<S: ToString>(&mut self, expected: S) -> &mut Self
pub fn with_stderr_unordered<S: ToString>(&mut self, expected: S) -> &mut Self
Verifies that all of the stderr output is equal to the given lines, ignoring the order of the lines.
See compare
for supported patterns.
This is useful when checking the output of cargo build -v
since
the order of the output is not always deterministic.
Recommend use with_stderr_contains
instead unless you really want to
check every line of output.
Be careful when using patterns such as [..]
, because you may end up
with multiple lines that might match, and this is not smart enough to
do anything like longest-match. For example, avoid something like:
[RUNNING] `rustc [..]
[RUNNING] `rustc --crate-name foo [..]
This will randomly fail if the other crate name is bar
, and the
order changes.
sourcepub fn with_stderr_line_without<S: ToString>(
&mut self,
with: &[S],
without: &[S]
) -> &mut Self
pub fn with_stderr_line_without<S: ToString>( &mut self, with: &[S], without: &[S] ) -> &mut Self
Verify that a particular line appears in stderr with and without the given substrings. Exactly one line must match.
The substrings are matched as contains
. Example:
use cargo_test_support::execs;
execs().with_stderr_line_without(
&[
"[RUNNING] `rustc --crate-name build_script_build",
"-C opt-level=3",
],
&["-C debuginfo", "-C incremental"],
);
This will check that a build line includes -C opt-level=3
but does
not contain -C debuginfo
or -C incremental
.
Be careful writing the without
fragments, see note in
with_stderr_does_not_contain
.
sourcepub fn with_json(&mut self, expected: &str) -> &mut Self
pub fn with_json(&mut self, expected: &str) -> &mut Self
Verifies the JSON output matches the given JSON.
This is typically used when testing cargo commands that emit JSON. Each separate JSON object should be separated by a blank line. Example:
assert_that(
p.cargo("metadata"),
execs().with_json(r#"
{"example": "abc"}
{"example": "def"}
"#)
);
- Objects should match in the order given.
- The order of arrays is ignored.
- Strings support patterns described in
compare
. - Use
"{...}"
to match any object.
sourcepub fn with_json_contains_unordered(&mut self, expected: &str) -> &mut Self
pub fn with_json_contains_unordered(&mut self, expected: &str) -> &mut Self
Verifies JSON output contains the given objects (in any order) somewhere in its output.
CAUTION: Be very careful when using this. Make sure every object is unique (not a subset of one another). Also avoid using objects that could possibly match multiple output lines unless you’re very sure of what you are doing.
See with_json
for more detail.
sourcepub fn stream(&mut self) -> &mut Self
pub fn stream(&mut self) -> &mut Self
Forward subordinate process stdout/stderr to the terminal. Useful for printf debugging of the tests. CAUTION: CI will fail if you leave this in your test!
pub fn arg<T: AsRef<OsStr>>(&mut self, arg: T) -> &mut Self
pub fn cwd<T: AsRef<OsStr>>(&mut self, path: T) -> &mut Self
pub(crate) fn get_cwd(&self) -> Option<&Path>
pub fn env<T: AsRef<OsStr>>(&mut self, key: &str, val: T) -> &mut Self
pub fn env_remove(&mut self, key: &str) -> &mut Self
pub fn exec_with_output(&mut self) -> Result<Output>
pub fn build_command(&mut self) -> Command
sourcepub fn masquerade_as_nightly_cargo(&mut self, reasons: &[&str]) -> &mut Self
pub fn masquerade_as_nightly_cargo(&mut self, reasons: &[&str]) -> &mut Self
Enables nightly features for testing
The list of reasons should be why nightly cargo is needed. If it is
because of an unstable feature put the name of the feature as the reason,
e.g. &["print-im-a-teapot"]
sourcepub fn replace_crates_io(&mut self, url: &Url) -> &mut Self
pub fn replace_crates_io(&mut self, url: &Url) -> &mut Self
Overrides the crates.io URL for testing.
Can be used for testing crates-io functionality where alt registries cannot be used.
pub fn enable_split_debuginfo_packed(&mut self) -> &mut Self
pub fn enable_mac_dsym(&mut self) -> &mut Self
pub fn run(&mut self)
pub fn run_expect_error(&mut self)
sourcepub fn run_json(&mut self) -> Value
pub fn run_json(&mut self) -> Value
Runs the process, checks the expected output, and returns the first JSON object on stdout.
pub fn run_output(&mut self, output: &Output)
pub(crate) fn verify_checks_output(&self, stdout: &[u8], stderr: &[u8])
pub(crate) fn match_process( &self, process: &ProcessBuilder ) -> Result<RawOutput>
pub(crate) fn match_output( &self, code: Option<i32>, stdout: &[u8], stderr: &[u8] ) -> Result<()>
Trait Implementations§
Auto Trait Implementations§
impl RefUnwindSafe for Execs
impl Send for Execs
impl Sync for Execs
impl Unpin for Execs
impl UnwindSafe for Execs
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> Instrument for T
impl<T> Instrument for T
source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
source§impl<T> WithSubscriber for T
impl<T> WithSubscriber for T
source§fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>where
S: Into<Dispatch>,
fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>where S: Into<Dispatch>,
source§fn with_current_subscriber(self) -> WithDispatch<Self>
fn with_current_subscriber(self) -> WithDispatch<Self>
Layout§
Note: Most layout information is completely unstable and may even differ between compilations. The only exception is types with certain repr(...)
attributes. Please see the Rust Reference's “Type Layout” chapter for details on type layout guarantees.
Size: 488 bytes