Struct OutputAssert
pub struct OutputAssert {
output: Output,
config: Assert,
}Expand description
Assert the state of a Command’s Output.
Create an OutputAssert through the Command::assert.
Fields§
§output: Output§config: AssertImplementations§
§impl OutputAssert
impl OutputAssert
pub fn new(output: Output) -> OutputAssert
pub fn new(output: Output) -> OutputAssert
Create an Assert for a given Output.
pub fn with_assert(self, config: Assert) -> OutputAssert
pub fn with_assert(self, config: Assert) -> OutputAssert
Customize the assertion behavior
pub fn get_output(&self) -> &Output
pub fn get_output(&self) -> &Output
Access the contained Output.
pub fn success(self) -> OutputAssert
pub fn success(self) -> OutputAssert
Ensure the command succeeded.
use snapbox::cmd::Command;
use snapbox::cmd::cargo_bin;
let assert = Command::new(cargo_bin("snap-fixture"))
.assert()
.success();pub fn failure(self) -> OutputAssert
pub fn failure(self) -> OutputAssert
Ensure the command failed.
use snapbox::cmd::Command;
use snapbox::cmd::cargo_bin;
let assert = Command::new(cargo_bin("snap-fixture"))
.env("exit", "1")
.assert()
.failure();pub fn interrupted(self) -> OutputAssert
pub fn interrupted(self) -> OutputAssert
Ensure the command aborted before returning a code.
pub fn code(self, expected: i32) -> OutputAssert
pub fn code(self, expected: i32) -> OutputAssert
Ensure the command returned the expected code.
use snapbox::cmd::Command;
use snapbox::cmd::cargo_bin;
let assert = Command::new(cargo_bin("snap-fixture"))
.env("exit", "42")
.assert()
.code(42);pub fn stdout_eq(self, expected: impl IntoData) -> OutputAssert
pub fn stdout_eq(self, expected: impl IntoData) -> OutputAssert
Ensure the command wrote the expected data to stdout.
By default filters are applied, including:
...is a line-wildcard when on a line by itself[..]is a character-wildcard when inside a line[EXE]matches.exeon Windows"{...}"is a JSON value wildcard"...": "{...}"is a JSON key-value wildcard\to/- Newlines
To limit this to newline normalization for text, call Data::raw on expected.
§Examples
use snapbox::cmd::Command;
use snapbox::cmd::cargo_bin;
let assert = Command::new(cargo_bin("snap-fixture"))
.env("stdout", "hello")
.env("stderr", "world")
.assert()
.stdout_eq("he[..]o");Can combine this with file!
use snapbox::cmd::Command;
use snapbox::cmd::cargo_bin;
use snapbox::file;
let assert = Command::new(cargo_bin("snap-fixture"))
.env("stdout", "hello")
.env("stderr", "world")
.assert()
.stdout_eq(file!["stdout.log"]);pub fn stdout_eq_(self, expected: impl IntoData) -> OutputAssert
Replaced with OutputAssert::stdout_eq
pub fn stderr_eq(self, expected: impl IntoData) -> OutputAssert
pub fn stderr_eq(self, expected: impl IntoData) -> OutputAssert
Ensure the command wrote the expected data to stderr.
By default filters are applied, including:
...is a line-wildcard when on a line by itself[..]is a character-wildcard when inside a line[EXE]matches.exeon Windows"{...}"is a JSON value wildcard"...": "{...}"is a JSON key-value wildcard\to/- Newlines
To limit this to newline normalization for text, call Data::raw on expected.
§Examples
use snapbox::cmd::Command;
use snapbox::cmd::cargo_bin;
let assert = Command::new(cargo_bin("snap-fixture"))
.env("stdout", "hello")
.env("stderr", "world")
.assert()
.stderr_eq("wo[..]d");Can combine this with file!
use snapbox::cmd::Command;
use snapbox::cmd::cargo_bin;
use snapbox::file;
let assert = Command::new(cargo_bin("snap-fixture"))
.env("stdout", "hello")
.env("stderr", "world")
.assert()
.stderr_eq(file!["stderr.log"]);pub fn stderr_eq_(self, expected: impl IntoData) -> OutputAssert
Replaced with OutputAssert::stderr_eq
Auto Trait Implementations§
impl Freeze for OutputAssert
impl RefUnwindSafe for OutputAssert
impl Send for OutputAssert
impl Sync for OutputAssert
impl Unpin for OutputAssert
impl UnsafeUnpin for OutputAssert
impl UnwindSafe for OutputAssert
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
§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>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more§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: 232 bytes