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

Assert a command stderr 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;

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

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

// Panic with custom message
let result = panic::catch_unwind(|| {
let mut command = Command::new("bin/printf-stderr");
command.args(["%s", "hello"]);
let containee = "zzz";
assert_command_stderr_contains!(command, containee, "message");
//-> panic!
});
assert!(result.is_err());
let actual = result.unwrap_err().downcast::<String>().unwrap().to_string();
let expect = "message";
assert_eq!(actual, expect);