Crate assert_cli [] [src]

Test CLI Applications

This crate's goal is to provide you some very easy tools to test your CLI applications. It can currently execute child processes and validate their exit status as well as stdout output against your assertions.


Here's a trivial example:

assert_cli::Assert::command(&["echo", "42"])

And here is one that will fail:

assert_cli::Assert::command(&["echo", "42"])

this will show a nice, colorful diff in your terminal, like this:


If you are testing a Rust binary crate, you can start with Assert::main_binary() to use cargo run as command. Or, if you want to run a specific binary (if you have more than one), use Assert::cargo_binary.

Alternatively, you can use the assert_cmd! macro to construct the command:

#[macro_use] extern crate assert_cli;

assert_cmd!(echo 42).succeeds().prints("42").unwrap();

(Make sure to include the crate as #[macro_use] extern crate assert_cli;!)

If you don't want it to panic when the assertions are not met, simply call .execute instead of .unwrap to get a Result:

#[macro_use] extern crate assert_cli;

let x = assert_cmd!(echo 1337).prints_exactly("42").execute();



Easily construct an Assert with a custom command



Assertions for a specific command