Struct snapbox::cmd::OutputAssert
source · 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.exe
on Windows\
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"]);
sourcepub fn stdout_eq(self, expected: impl Into<Data>) -> Self
👎Deprecated since 0.5.11: Replaced with OutputAssert::stdout_eq_(expected.raw())
pub fn stdout_eq(self, expected: impl Into<Data>) -> Self
OutputAssert::stdout_eq_(expected.raw())
Ensure the command wrote the expected data to stdout
.
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("hello");
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"]);
sourcepub fn stdout_matches(self, expected: impl Into<Data>) -> Self
👎Deprecated since 0.5.11: Replaced with OutputAssert::stdout_eq_(expected)
pub fn stdout_matches(self, expected: impl Into<Data>) -> Self
OutputAssert::stdout_eq_(expected)
Ensure the command wrote the expected data to stdout
.
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_matches("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_matches(file!["stdout.log"]);
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.exe
on Windows\
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"]);
sourcepub fn stderr_eq(self, expected: impl Into<Data>) -> Self
👎Deprecated since 0.5.11: Replaced with OutputAssert::stderr_eq_(expected.raw())
pub fn stderr_eq(self, expected: impl Into<Data>) -> Self
OutputAssert::stderr_eq_(expected.raw())
Ensure the command wrote the expected data to stderr
.
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("world");
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"]);
sourcepub fn stderr_matches(self, expected: impl Into<Data>) -> Self
👎Deprecated since 0.5.11: Replaced with OutputAssert::stderr_eq_(expected)
pub fn stderr_matches(self, expected: impl Into<Data>) -> Self
OutputAssert::stderr_eq_(expected)
Ensure the command wrote the expected data to stderr
.
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_matches("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_matches(file!["stderr.log"]);