Struct assert_cmd::assert::Assert

source ·
pub struct Assert { /* private fields */ }
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::main_binary()
    .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::main_binary()
    .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::main_binary()
    .unwrap()
    .assert()
    .success();

Ensure the command failed.

Examples
use assert_cmd::prelude::*;

use std::process::Command;

Command::main_binary()
    .unwrap()
    .env("exit", "1")
    .assert()
    .failure();

Ensure the command aborted before returning a code.

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:

extern crate assert_cmd;
extern crate predicates;

use assert_cmd::prelude::*;

use std::process::Command;
use predicates::prelude::*;

Command::main_binary()
    .unwrap()
    .env("exit", "42")
    .assert()
    .code(predicate::eq(42));

Accepting an exit code:

use assert_cmd::prelude::*;

use std::process::Command;

Command::main_binary()
    .unwrap()
    .env("exit", "42")
    .assert()
    .code(42);

Accepting multiple exit codes:

use assert_cmd::prelude::*;

use std::process::Command;

Command::main_binary()
    .unwrap()
    .env("exit", "42")
    .assert()
    .code(&[2, 42] as &[i32]);

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:

extern crate assert_cmd;
extern crate predicates;

use assert_cmd::prelude::*;

use std::process::Command;
use predicates::prelude::*;

Command::main_binary()
    .unwrap()
    .env("stdout", "hello")
    .env("stderr", "world")
    .assert()
    .stdout(predicate::eq(b"hello\n" as &[u8]));

Accepting a str predicate:

extern crate assert_cmd;
extern crate predicates;

use assert_cmd::prelude::*;

use std::process::Command;
use predicates::prelude::*;

Command::main_binary()
    .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::main_binary()
    .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::main_binary()
    .unwrap()
    .env("stdout", "hello")
    .env("stderr", "world")
    .assert()
    .stdout("hello\n");

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:

extern crate assert_cmd;
extern crate predicates;

use assert_cmd::prelude::*;

use std::process::Command;
use predicates::prelude::*;

Command::main_binary()
    .unwrap()
    .env("stdout", "hello")
    .env("stderr", "world")
    .assert()
    .stderr(predicate::eq(b"world\n" as &[u8]));

Accepting a str predicate:

extern crate assert_cmd;
extern crate predicates;

use assert_cmd::prelude::*;

use std::process::Command;
use predicates::prelude::*;

Command::main_binary()
    .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::main_binary()
    .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::main_binary()
    .unwrap()
    .env("stdout", "hello")
    .env("stderr", "world")
    .assert()
    .stderr("world\n");

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

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

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.