macro_rules! assert_program_args_stderr_is_match {
    ($a_program:expr, $a_args:expr, $b_matcher:expr $(,)?) => { ... };
    ($a_program:expr, $a_args:expr, $b_matcher:expr, $($message:tt)+) => { ... };
}
Expand description

Assert a command (built with program and args) stderr string is a match to a regex.

  • If true, return ().

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

Examples

use regex::Regex;

// Return Ok
let program = "bin/printf-stderr";
let args = ["%s", "hello"];
let matcher = Regex::new(r"ell").unwrap();
assert_program_args_stderr_is_match!(&program, &args, matcher);
//-> ()

// Panic with error message
let result = panic::catch_unwind(|| {
let program = "bin/printf-stderr";
let args = ["%s", "hello"];
let matcher = Regex::new(r"zzz").unwrap();
assert_program_args_stderr_is_match!(&program, &args, matcher);
//-> panic!
});
assert!(result.is_err());
let actual = result.unwrap_err().downcast::<String>().unwrap().to_string();
let expect = concat!(
    "assertion failed: `assert_program_args_stderr_is_match!(left_program, right_matcher)`\n",
    "  left_program label: `&program`,\n",
    "  left_program debug: `\"bin/printf-stderr\"`,\n",
    "     left_args label: `&args`,\n",
    "     left_args debug: `[\"%s\", \"hello\"]`,\n",
    " right_matcher label: `matcher`,\n",
    " right_matcher debug: `zzz`,\n",
    "                left: `\"hello\"`,\n",
    "               right: `zzz`"
);
assert_eq!(actual, expect);