[−][src]Crate assert_cmd
Assert Command - Easy command initialization and assertions.
assert_cmd includes support for:
- Setting up your program-under-test (see
CommandCargoExt,CommandStdInExt). - Verifying your program-under-test (see
OutputOkExt,OutputAssertExt).
[dependencies]
assert_cmd = "0.11"
Overview
Create a Command:
Command::new(path), seeCommandCommand::cargo_bin(name), seeCommandCargoExt
Configure a Command:
arg/args, seeCommandcurrent_dir, seeCommandenv/envs/env_remove/env_clear, seeCommandwith_stdin, seeCommandStdInExt
Validate either a Command or Output:
ok/unwrap/unwrap_err, seeOutputOkExtassert(OutputAssertExt)
Examples
Here's a trivial example:
extern crate assert_cmd; use std::process::Command; use assert_cmd::prelude::*; fn main() { let mut cmd = Command::cargo_bin("bin_fixture").unwrap(); cmd.assert().success(); }
And a little of everything:
extern crate assert_cmd; use std::process::Command; use assert_cmd::prelude::*; fn main() { let mut cmd = Command::cargo_bin("bin_fixture").unwrap(); cmd .arg("-A") .env("stdout", "hello") .env("exit", "42") .with_stdin() .buffer("42"); let assert = cmd.assert(); assert .failure() .code(42) .stdout("hello\n"); }
Relevant crates
Other crates that might be useful in testing command line programs.
- duct for orchestrating multiple processes.
- commandspec for easier writing of commands
- assert_fs for filesystem fixtures and assertions.
- dir-diff for testing file side-effects.
- tempfile for scratchpad directories.
Migrating from assert_cli v0.6
assert_cmd is the successor to the original assert_cli:
- More flexible, reusable assertions (also used by assert_fs).
- Can integrate with other process-management crates, like
duct. - Addresses several architectural problems.
Key points in migrating from assert_cli:
Modules
| assert |
|
| cargo | Simplify running |
| cmd | Simplify one-off runs of programs. |
| prelude | Extension traits that are useful to have available. |
| stdin | Write to |
Macros
| crate_name | Allows you to pull the name from your Cargo.toml at compile time. |