assert_cli 0.3.0

Test CLI Applications.
Documentation

Assert CLI

Test CLI Applications.

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

Build Status Coverage Status

Documentation

Install

Just add it to your Cargo.toml:

[dependencies]
assert_cli = "0.3"

Example

Here's a trivial example:

extern crate assert_cli;
fn main() {
  assert_cli::assert_cli_output("echo", &["42"], "42").unwrap();
}

Or if you'd rather use the macro:

#[macro_use] extern crate assert_cli;
fn main() {
  assert_cli!("echo", &["42"] => Success, "42").unwrap();
  assert_cli!("black-box", &["--special"] => Error 42, "error no 42\n").unwrap()
}

And here is one that will fail:

extern crate assert_cli;
fn main() {
  assert_cli::assert_cli_output("echo", &["42"], "1337").unwrap();
}

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

-1337
+42

If you'd prefer to not check the output:

#[macro_use] extern crate assert_cli;
fn main() {
  assert_cli::assert_cli("echo", &["42"]).unwrap();
  assert_cli!("echo", &["42"] => Success).unwrap();
}

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

#[macro_use] extern crate assert_cli;
fn main() {
  let output = assert_cli!("echo", &["Number 42"] => Success).unwrap();
  let stdout = std::str::from_utf8(&output.stdout).unwrap();
  assert!(stdout.contains("42"));
}

License

Licensed under either of

at your option.

Contribution

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.