macro_rules! assert_command_stdout_contains {
    ($a_command:expr, $b:expr $(,)?) => { ... };
    ($a_command:expr, $b:expr, $($arg:tt)+) => { ... };
}
Expand description

Assert a command stdout string contains a given containee.

  • If true, return ().

  • Otherwise, call panic! with a message and the values of the expressions with their debug representations.

This uses [std::String] method contains.

  • The containee can be a &str, char, a slice of chars, or a function or closure that determines if a character contains.

Examples

use std::process::Command;

let mut command = Command::new("printf");
command.args(["%s", "hello"]);
let containee = "ell";
assert_command_stdout_contains!(command, containee);
//-> ()

let result = panic::catch_unwind(|| {
let mut command = Command::new("printf");
command.args(["%s", "hello"]);
let containee = "xyz";
assert_command_stdout_contains!(command, containee);
//-> panic!
});
let actual = result.unwrap_err().downcast::<String>().unwrap().to_string();
let expect = concat!(
    "assertion failed: `assert_command_stdout_contains!(left_command, right_containee)`\n",
    "    left_command label: `command`,\n",
    "    left_command debug: `\"printf\" \"%s\" \"hello\"`,\n",
    " right_containee label: `containee`,\n",
    " right_containee debug: `\"xyz\"`,\n",
    "                  left: `\"hello\"`,\n",
    "                 right: `\"xyz\"`"
);
assert_eq!(actual, expect);