cargo_test_support

Struct Execs

Source
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

Run and verify a ProcessBuilder

Construct with

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

Source§

impl Execs

§Configure assertions

Source

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());
Source

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());
Source

pub fn with_stdin<S: ToString>(&mut self, expected: S) -> &mut Self

Writes the given lines to stdin.

Source

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.

Source

pub fn without_status(&mut self) -> &mut Self

Removes exit code check for the process.

By default, the expected exit code is 0.

Source

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 snapshotted
  • expected can end up being ambiguous, causing the assertion to succeed when it should fail
Source

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 snapshotted
  • expected can end up being ambiguous, causing the assertion to succeed when it should fail
Source

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.

Source

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.

Source

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

§Configure the process

Source

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!

Source

pub fn arg<T: AsRef<OsStr>>(&mut self, arg: T) -> &mut Self

Source

pub fn args<T: AsRef<OsStr>>(&mut self, args: &[T]) -> &mut Self

Source

pub fn cwd<T: AsRef<OsStr>>(&mut self, path: T) -> &mut Self

Source

pub fn env<T: AsRef<OsStr>>(&mut self, key: &str, val: T) -> &mut Self

Source

pub fn env_remove(&mut self, key: &str) -> &mut Self

Source

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"]

Source

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.

Source

pub fn overlay_registry(&mut self, url: &Url, path: &str) -> &mut Self

Source

pub fn enable_split_debuginfo_packed(&mut self) -> &mut Self

Source

pub fn enable_mac_dsym(&mut self) -> &mut Self

Source§

impl Execs

§Run and verify the process

Source

pub fn exec_with_output(&mut self) -> Result<Output>

Source

pub fn build_command(&mut self) -> Command

Source

pub fn run(&mut self)

Source

pub fn run_json(&mut self) -> Value

Runs the process, checks the expected output, and returns the first JSON object on stdout.

Source

pub fn run_output(&mut self, output: &Output)

Source

pub(crate) fn verify_checks_output(&self, stdout: &[u8], stderr: &[u8])

Source

pub(crate) fn match_process( &self, process: &ProcessBuilder, ) -> Result<RawOutput>

Source

pub(crate) fn match_output( &self, code: Option<i32>, stdout: &[u8], stderr: &[u8], ) -> Result<()>

Trait Implementations§

Source§

impl Clone for Execs

Source§

fn clone(&self) -> Execs

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Drop for Execs

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

§

impl<T> Pointable for T

§

const ALIGN: usize = _

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more

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