pub struct Execs {Show 13 fields
pub(crate) ran: bool,
pub(crate) process_builder: Option<ProcessBuilder>,
pub(crate) expect_stdin: Option<String>,
pub(crate) expect_exit_code: Option<i32>,
pub(crate) expect_stdout_data: Option<Data>,
pub(crate) expect_stderr_data: Option<Data>,
pub(crate) expect_stdout_contains: Vec<String>,
pub(crate) expect_stderr_contains: Vec<String>,
pub(crate) expect_stdout_not_contains: Vec<String>,
pub(crate) expect_stderr_not_contains: Vec<String>,
pub(crate) expect_stderr_with_without: Vec<(Vec<String>, Vec<String>)>,
pub(crate) stream_output: bool,
pub(crate) assert: Assert,
}
Expand description
Fields§
§ran: bool
§process_builder: Option<ProcessBuilder>
§expect_stdin: Option<String>
§expect_exit_code: Option<i32>
§expect_stdout_data: Option<Data>
§expect_stderr_data: Option<Data>
§expect_stdout_contains: Vec<String>
§expect_stderr_contains: Vec<String>
§expect_stdout_not_contains: Vec<String>
§expect_stderr_not_contains: Vec<String>
§expect_stderr_with_without: Vec<(Vec<String>, Vec<String>)>
§stream_output: bool
§assert: Assert
Implementations§
Source§impl Execs
impl Execs
pub fn with_process_builder(self, p: ProcessBuilder) -> Execs
Source§impl Execs
impl Execs
§Configure assertions
Sourcepub fn with_stdout_data(&mut self, expected: impl IntoData) -> &mut Self
pub fn with_stdout_data(&mut self, expected: impl IntoData) -> &mut Self
Verifies that stdout is equal to the given lines.
See compare::assert_e2e
for assertion details.
Prefer passing in str!
for expected
to get snapshot updating.
If format!
is needed for content that changes from run to run that you don’t care about,
consider whether you could have compare::assert_e2e
redact the content.
If nothing else, a wildcard ([..]
, ...
) may be useful.
However, ""
may be preferred for intentionally empty output so people don’t accidentally
bless a change.
§Examples
use cargo_test_support::prelude::*;
use cargo_test_support::str;
use cargo_test_support::execs;
execs().with_stdout_data(str![r#"
Hello world!
"#]);
Non-deterministic compiler output
use cargo_test_support::prelude::*;
use cargo_test_support::str;
use cargo_test_support::execs;
execs().with_stdout_data(str![r#"
[COMPILING] foo
[COMPILING] bar
"#].unordered());
jsonlines
use cargo_test_support::prelude::*;
use cargo_test_support::str;
use cargo_test_support::execs;
execs().with_stdout_data(str![r#"
[
{},
{}
]
"#].is_json().against_jsonlines());
Sourcepub fn with_stderr_data(&mut self, expected: impl IntoData) -> &mut Self
pub fn with_stderr_data(&mut self, expected: impl IntoData) -> &mut Self
Verifies that stderr is equal to the given lines.
See compare::assert_e2e
for assertion details.
Prefer passing in str!
for expected
to get snapshot updating.
If format!
is needed for content that changes from run to run that you don’t care about,
consider whether you could have compare::assert_e2e
redact the content.
If nothing else, a wildcard ([..]
, ...
) may be useful.
However, ""
may be preferred for intentionally empty output so people don’t accidentally
bless a change.
§Examples
use cargo_test_support::prelude::*;
use cargo_test_support::str;
use cargo_test_support::execs;
execs().with_stderr_data(str![r#"
Hello world!
"#]);
Non-deterministic compiler output
use cargo_test_support::prelude::*;
use cargo_test_support::str;
use cargo_test_support::execs;
execs().with_stderr_data(str![r#"
[COMPILING] foo
[COMPILING] bar
"#].unordered());
jsonlines
use cargo_test_support::prelude::*;
use cargo_test_support::str;
use cargo_test_support::execs;
execs().with_stderr_data(str![r#"
[
{},
{}
]
"#].is_json().against_jsonlines());
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.
Prefer Execs::with_stdout_data
where possible.
expected
cannot be snapshottedexpected
can end up being ambiguous, causing the assertion to succeed when it should fail
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.
Prefer Execs::with_stderr_data
where possible.
expected
cannot be snapshottedexpected
can end up being ambiguous, causing the assertion to succeed when it should fail
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
.
Prefer Execs::with_stdout_data
where possible.
expected
cannot be snapshotted- The absence of
expected
can either mean success or that the string being looked for changed.
To mitigate this, consider matching this up with
Execs::with_stdout_contains
.
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.
Prefer Execs::with_stdout_data
where possible.
expected
cannot be snapshotted- The absence of
expected
can either mean success or that the string being looked for changed.
To mitigate this, consider either matching this up with
Execs::with_stdout_contains
or replace it
with Execs::with_stderr_line_without
.
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
.
Prefer Execs::with_stdout_data
where possible.
with
cannot be snapshotted- The absence of
without
can either mean success or that the string being looked for changed.
§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
.
Source§impl Execs
impl Execs
§Configure the process
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 args<T: AsRef<OsStr>>(&mut self, args: &[T]) -> &mut Self
pub fn cwd<T: AsRef<OsStr>>(&mut self, path: T) -> &mut Self
pub fn env<T: AsRef<OsStr>>(&mut self, key: &str, val: T) -> &mut Self
pub fn env_remove(&mut self, key: &str) -> &mut Self
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 overlay_registry(&mut self, url: &Url, path: &str) -> &mut Self
pub fn enable_split_debuginfo_packed(&mut self) -> &mut Self
pub fn enable_mac_dsym(&mut self) -> &mut Self
Source§impl Execs
impl Execs
§Run and verify the process
pub fn exec_with_output(&mut self) -> Result<Output>
pub fn build_command(&mut self) -> Command
pub fn run(&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 Freeze for Execs
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
§impl<T> Pointable for T
impl<T> Pointable for T
§impl<T> WithSubscriber for T
impl<T> WithSubscriber for T
§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>,
§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: 704 bytes