pub struct OutputAssert { /* private fields */ }Expand description
Assert the state of a Command’s Output.
Create an OutputAssert through the Command::assert.
Implementations§
Source§impl OutputAssert
impl OutputAssert
Sourcepub fn with_assert(self, config: Assert) -> Self
pub fn with_assert(self, config: Assert) -> Self
Customize the assertion behavior
Sourcepub fn get_output(&self) -> &Output
pub fn get_output(&self) -> &Output
Access the contained Output.
Sourcepub fn success(self) -> Self
pub fn success(self) -> Self
Ensure the command succeeded.
use snapbox::cmd::Command;
use snapbox::cmd::cargo_bin;
let assert = Command::new(cargo_bin("snap-fixture"))
.assert()
.success();Sourcepub fn failure(self) -> Self
pub fn failure(self) -> Self
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();Sourcepub fn interrupted(self) -> Self
pub fn interrupted(self) -> Self
Ensure the command aborted before returning a code.
Sourcepub fn code(self, expected: i32) -> Self
pub fn code(self, expected: i32) -> Self
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);Sourcepub fn stdout_eq(self, expected: impl IntoData) -> Self
pub fn stdout_eq(self, expected: impl IntoData) -> Self
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) -> Self
Replaced with OutputAssert::stdout_eq
Sourcepub fn stderr_eq(self, expected: impl IntoData) -> Self
pub fn stderr_eq(self, expected: impl IntoData) -> Self
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) -> Self
Replaced with OutputAssert::stderr_eq