assert_cmd - Rust (original) (raw)

Expand description

Assert Command - Easy command initialization and assertions.

assert_cmd aims to simplify the process for doing integration testing of CLIs, including:

§Overview

Create a Command:

Configure a Command:

Validate a Command:

Note: Command is provided as a convenience. Extension traits for std::process::Commandand Output are provided for interoperability:

§Examples

Here’s a trivial example:

use assert_cmd::Command;

let mut cmd = Command::cargo_bin("bin_fixture").unwrap();
cmd.assert().success();

And a little of everything:

use assert_cmd::Command;

let mut cmd = Command::cargo_bin("bin_fixture").unwrap();
let assert = cmd
    .arg("-A")
    .env("stdout", "hello")
    .env("exit", "42")
    .write_stdin("42")
    .assert();
assert
    .failure()
    .code(42)
    .stdout("hello\n");

§Relevant crates

Other crates that might be useful in testing command line programs.

§Migrating from assert_cli v0.6

assert_cmd is the successor to the original assert_cli:

Key points in migrating from assert_cli:

pub use crate::cmd::[Command](cmd/struct.Command.html "struct assert_cmd::cmd::Command");

assert

std::process::Output assertions.

cargo

Simplify running bins in a Cargo project.

cmd

std::process::Command customized for testing.

output

Simplify one-off runs of programs.

prelude

Extension traits that are useful to have available.

crate_name

Allows you to pull the name from your Cargo.toml at compile time.