[−][src]Struct assert_cmd::assert::Assert
Assert the state of an Output
.
Create an Assert
through the OutputAssertExt
trait.
Examples
use assert_cmd::prelude::*; use std::process::Command; let mut cmd = Command::cargo_bin("bin_fixture") .unwrap(); cmd.assert() .success();
Methods
impl Assert
[src]
pub fn new(output: Output) -> Self
[src]
Create an Assert
for a given Output
.
pub fn append_context<D>(self, name: &'static str, context: D) -> Self where
D: Display + 'static,
[src]
D: Display + 'static,
Clarify failures with additional context.
Examples
use assert_cmd::prelude::*; use std::process::Command; Command::cargo_bin("bin_fixture") .unwrap() .assert() .append_context("main", "no args") .success();
pub fn get_output(&self) -> &Output
[src]
Access the contained Output
.
pub fn success(self) -> Self
[src]
Ensure the command succeeded.
Examples
use assert_cmd::prelude::*; use std::process::Command; Command::cargo_bin("bin_fixture") .unwrap() .assert() .success();
pub fn failure(self) -> Self
[src]
Ensure the command failed.
Examples
use assert_cmd::prelude::*; use std::process::Command; Command::cargo_bin("bin_fixture") .unwrap() .env("exit", "1") .assert() .failure();
pub fn interrupted(self) -> Self
[src]
Ensure the command aborted before returning a code.
pub fn code<I, P>(self, pred: I) -> Self where
I: IntoCodePredicate<P>,
P: Predicate<i32>,
[src]
I: IntoCodePredicate<P>,
P: Predicate<i32>,
Ensure the command returned the expected code.
This uses IntoCodePredicate
to provide short-hands for common cases.
See predicates
for more predicates.
Examples
Accepting a predicate:
use assert_cmd::prelude::*; use std::process::Command; use predicates::prelude::*; Command::cargo_bin("bin_fixture") .unwrap() .env("exit", "42") .assert() .code(predicate::eq(42));
Accepting an exit code:
use assert_cmd::prelude::*; use std::process::Command; Command::cargo_bin("bin_fixture") .unwrap() .env("exit", "42") .assert() .code(42);
Accepting multiple exit codes:
use assert_cmd::prelude::*; use std::process::Command; Command::cargo_bin("bin_fixture") .unwrap() .env("exit", "42") .assert() .code(&[2, 42] as &[i32]);
pub fn stdout<I, P>(self, pred: I) -> Self where
I: IntoOutputPredicate<P>,
P: Predicate<[u8]>,
[src]
I: IntoOutputPredicate<P>,
P: Predicate<[u8]>,
Ensure the command wrote the expected data to stdout
.
This uses IntoOutputPredicate
to provide short-hands for common cases.
See predicates
for more predicates.
Examples
Accepting a bytes predicate:
use assert_cmd::prelude::*; use std::process::Command; use predicates::prelude::*; Command::cargo_bin("bin_fixture") .unwrap() .env("stdout", "hello") .env("stderr", "world") .assert() .stdout(predicate::eq(b"hello\n" as &[u8]));
Accepting a str
predicate:
use assert_cmd::prelude::*; use std::process::Command; use predicates::prelude::*; Command::cargo_bin("bin_fixture") .unwrap() .env("stdout", "hello") .env("stderr", "world") .assert() .stdout(predicate::str::similar("hello\n"));
Accepting bytes:
use assert_cmd::prelude::*; use std::process::Command; Command::cargo_bin("bin_fixture") .unwrap() .env("stdout", "hello") .env("stderr", "world") .assert() .stdout(b"hello\n" as &[u8]);
Accepting a str
:
use assert_cmd::prelude::*; use std::process::Command; Command::cargo_bin("bin_fixture") .unwrap() .env("stdout", "hello") .env("stderr", "world") .assert() .stdout("hello\n");
pub fn stderr<I, P>(self, pred: I) -> Self where
I: IntoOutputPredicate<P>,
P: Predicate<[u8]>,
[src]
I: IntoOutputPredicate<P>,
P: Predicate<[u8]>,
Ensure the command wrote the expected data to stderr
.
This uses IntoOutputPredicate
to provide short-hands for common cases.
See predicates
for more predicates.
Examples
Accepting a bytes predicate:
use assert_cmd::prelude::*; use std::process::Command; use predicates::prelude::*; Command::cargo_bin("bin_fixture") .unwrap() .env("stdout", "hello") .env("stderr", "world") .assert() .stderr(predicate::eq(b"world\n" as &[u8]));
Accepting a str
predicate:
use assert_cmd::prelude::*; use std::process::Command; use predicates::prelude::*; Command::cargo_bin("bin_fixture") .unwrap() .env("stdout", "hello") .env("stderr", "world") .assert() .stderr(predicate::str::similar("world\n"));
Accepting bytes:
use assert_cmd::prelude::*; use std::process::Command; Command::cargo_bin("bin_fixture") .unwrap() .env("stdout", "hello") .env("stderr", "world") .assert() .stderr(b"world\n" as &[u8]);
Accepting a str
:
use assert_cmd::prelude::*; use std::process::Command; Command::cargo_bin("bin_fixture") .unwrap() .env("stdout", "hello") .env("stderr", "world") .assert() .stderr("world\n");
Trait Implementations
Auto Trait Implementations
impl !RefUnwindSafe for Assert
impl !Send for Assert
impl !Sync for Assert
impl Unpin for Assert
impl !UnwindSafe for Assert
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToString for T where
T: Display + ?Sized,
[src]
T: Display + ?Sized,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,