How to Use the assert_cmd and predicates Crates for CLI Testing

Cli
Use assert_cmd to run your binary in tests and verify exit codes or output without manual shell scripting.

Use assert_cmd::Command to spawn your binary and chain assertions to verify exit codes and output. Add assert_cmd = "2" to your [dev-dependencies] in Cargo.toml, then write a test that calls Command::cargo_bin with your binary name, passes arguments, and asserts the result.

use assert_cmd::Command;

#[test]
fn supports_html_renderer() {
    let cmd = Command::cargo_bin("mdbook-trpl-note")
        .unwrap()
        .args(["supports", "html"])
        .ok();
    assert!(cmd.is_ok());
}