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

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]

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]

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]

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]

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

impl Debug for Assert[src]

fn fmt(&self, f: &mut Formatter<'_>) -> Result[src]

Formats the value using the given formatter. Read more

impl Display for Assert[src]

fn fmt(&self, f: &mut Formatter<'_>) -> Result[src]

Formats the value using the given formatter. Read more

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]

pub fn type_id(&self) -> TypeId[src]

Gets the TypeId of self. Read more

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

pub fn borrow(&self) -> &T[src]

Immutably borrows from an owned value. Read more

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

pub fn borrow_mut(&mut self) -> &mut T[src]

Mutably borrows from an owned value. Read more

impl<T> From<T> for T[src]

pub fn from(t: T) -> T[src]

Performs the conversion.

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

pub fn into(self) -> U[src]

Performs the conversion.

impl<T> ToString for T where
    T: Display + ?Sized
[src]

pub default fn to_string(&self) -> String[src]

Converts the given value to a String. Read more

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>[src]

Performs the conversion.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

pub fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>[src]

Performs the conversion.