Struct assert_cmd::assert::Assert [−][src]
pub struct Assert { /* fields omitted */ }
Expand description
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();
Implementations
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();
Access the contained Output
.
Ensure the command succeeded.
Examples
use assert_cmd::prelude::*; use std::process::Command; Command::cargo_bin("bin_fixture") .unwrap() .assert() .success();
try_
variant of Assert::success
.
Ensure the command failed.
Examples
use assert_cmd::prelude::*; use std::process::Command; Command::cargo_bin("bin_fixture") .unwrap() .env("exit", "1") .assert() .failure();
Variant of Assert::failure
that returns an AssertResult
.
Ensure the command aborted before returning a code.
Variant of Assert::interrupted
that returns an AssertResult
.
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 try_code<I, P>(self, pred: I) -> AssertResult where
I: IntoCodePredicate<P>,
P: Predicate<i32>,
pub fn try_code<I, P>(self, pred: I) -> AssertResult where
I: IntoCodePredicate<P>,
P: Predicate<i32>,
Variant of Assert::code
that returns an AssertResult
.
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::diff("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 try_stdout<I, P>(self, pred: I) -> AssertResult where
I: IntoOutputPredicate<P>,
P: Predicate<[u8]>,
pub fn try_stdout<I, P>(self, pred: I) -> AssertResult where
I: IntoOutputPredicate<P>,
P: Predicate<[u8]>,
Variant of Assert::stdout
that returns an AssertResult
.
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::diff("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");
pub fn try_stderr<I, P>(self, pred: I) -> AssertResult where
I: IntoOutputPredicate<P>,
P: Predicate<[u8]>,
pub fn try_stderr<I, P>(self, pred: I) -> AssertResult where
I: IntoOutputPredicate<P>,
P: Predicate<[u8]>,
Variant of Assert::stderr
that returns an AssertResult
.