assert_cli 0.5.4

Test CLI Applications.

Assert CLI

Test CLI Applications - This crate checks the output of a child process is as expected.

Build Status Documentation


Just add it to your Cargo.toml:

assert_cli = "0.5"


Here's a trivial example:

extern crate assert_cli;

fn main() {
    assert_cli::Assert::command(&["echo", "42"]).stdout().contains("42").unwrap();

Or if you'd rather use the macro, to save you some writing:

#[macro_use] extern crate assert_cli;

fn main() {
    assert_cmd!(echo "42").stdout().contains("42").unwrap();

And here is one that will fail (which also shows execute which returns a Result and can be used instead of unwrap):

#[macro_use] extern crate assert_cli;

fn main() {
    let test = assert_cmd!(ls "foo-bar-foo")

If you want to match the program's output exactly, you can use stdout().is:

#[macro_use] extern crate assert_cli;

fn main() {
    assert_cmd!(wc "")

... which has the benefit to show a nice, colorful diff in your terminal, like this:


Tip: Enclose arguments in the assert_cmd! macro in quotes ", if there are special characters, which the macro doesn't accept, e.g. assert_cmd!(cat "foo.txt").

Assert Cli use Environment underneath to deal with environment variables.

More detailed information is available in the documentation. :-)


Licensed under either of

at your option.


Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.