assert_cli 0.3.0

Test CLI Applications.

Crate assert_cli [] [src]

Test CLI Applications

Currently, this crate only includes basic functionality to check the output of a child process is as expected.

Example

Here's a trivial example:


assert_cli::assert_cli_output("echo", &["42"], "42").unwrap();

And here is one that will fail:

assert_cli::assert_cli_output("echo", &["42"], "1337").unwrap();

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

-1337
+42

Alternatively, you can use the assert_cli! macro:

assert_cli!("echo", &["42"] => Success, "42").unwrap();

All exported functions and the macro return a Result containing the Output of the process, allowing you to do further custom assertions:

let output = assert_cli!("echo", &["Number 42"] => Success).unwrap();
let stdout = std::str::from_utf8(&output.stdout).unwrap();
assert!(stdout.contains("42"));

Make sure to include the crate as #[macro_use] extern crate assert_cli;.

Macros

assert_cli!

The assert_cli! macro combines the functionality of the other functions in this crate in one short macro.

Functions

assert_cli

Assert a CLI call

assert_cli_error

Assert a CLI call that fails with a given error code.

assert_cli_output

Assert a CLI call returns the expected output.

assert_cli_output_error

Assert a CLI call that fails the expected stderr output and error code.