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

Create an Assert for a given Output.

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]);

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");

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");

Variant of Assert::stderr that returns an AssertResult.

Trait Implementations

Formats the value using the given formatter. Read more

Formats the value using the given formatter. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

Converts the given value to a String. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.