Skip to content

Test CLI Applications in Rust.

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT
Notifications You must be signed in to change notification settings

vincentdephily/assert_cli

 
 

Repository files navigation

Assert CLI

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

Build Status Documentation License crates.io

Install

For your tests, add it to your Cargo.toml:

[dev-dependencies]
assert_cli = "0.5"

Example

Here's a trivial example:

extern crate assert_cli;

fn main() {
    assert_cli::Assert::main_binary().unwrap();
}

And here is one that will fail (and demonstrates running arbitrary commands):

extern crate assert_cli;

fn main() {
    assert_cli::Assert::command(&["ls", "foo-bar-foo"])
        .fails()
        .and()
        .stderr().contains("foo-bar-foo")
        .unwrap();
}

If you want to match the program's output exactly, you can use stdout().is (and shows the macro form of command):

#[macro_use] extern crate assert_cli;

fn main() {
    assert_cmd!(wc "README.md")
        .stdout().is("1337 README.md")
        .unwrap();
}

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

-1337
+92

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. :-)

Relevant crates

Other crates that might be useful in testing command line programs.

  • dir-diff for testing file side-effects.
  • tempfile for scratchpad directories.
  • duct for orchestrating multiple processes.

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.

About

Test CLI Applications in Rust.

Resources

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Rust 100.0%