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

source

pub fn with_process_builder(self, p: ProcessBuilder) -> Execs

source

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.

source

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.

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.

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.

source

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.

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.

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.

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.

source

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.

source

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.

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. 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.

source

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.
source

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.

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 cwd<T: AsRef<OsStr>>(&mut self, path: T) -> &mut Self

source

pub(crate) fn get_cwd(&self) -> Option<&Path>

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 exec_with_output(&mut self) -> Result<Output>

source

pub fn build_command(&mut self) -> Command

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 enable_split_debuginfo_packed(&mut self) -> &mut Self

source

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

source

pub fn run(&mut self)

source

pub fn run_expect_error(&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 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 Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

source§

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

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> Instrument for T

source§

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

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

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 Twhere 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.

source§

impl<T> Same<T> for T

§

type Output = T

Should always be Self
source§

impl<T> ToOwned for Twhere T: Clone,

§

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 Twhere U: Into<T>,

§

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 Twhere U: TryFrom<T>,

§

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.
source§

impl<T> WithSubscriber for T

source§

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
source§

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: 488 bytes