Struct assert_cmd::assert::Assert[][src]

pub struct Assert { /* fields omitted */ }

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>(mut self: 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]

impl Display for Assert[src]

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

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

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

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

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

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

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.

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.