macro_rules! assert_program_args_stderr_matches {
($a_program:expr, $a_args:expr, $b_matcher:expr $(,)?) => { ... };
($a_program:expr, $a_args:expr, $b_matcher:expr, $($arg:tt)+) => { ... };
}Expand description
Assert a command (built with program and args) stderr string is a match to a given regex.
-
If true, return
(). -
Otherwise, call
panic!with a message and the values of the expressions with their debug representations.
Examples
use regex::Regex;
let program = "printf";
let args: [&str; 0] = [];
let matcher = Regex::new(r"usage").unwrap();
assert_program_args_stderr_matches!(&program, &args, matcher);
//-> ()
let result = panic::catch_unwind(|| {
let program = "printf";
let args: [&str; 0] = [];
let matcher = Regex::new(r"xyz").unwrap();
assert_program_args_stderr_matches!(&program, &args, matcher);
//-> panic!
});
let actual = result.unwrap_err().downcast::<String>().unwrap().to_string();
let expect = concat!(
"assertion failed: `assert_program_args_stderr_matches!(left_program, right_matcher)`\n",
" left_program label: `&program`,\n",
" left_program debug: `\"printf\"`,\n",
" left_args label: `&args`,\n",
" left_args debug: `[]`,\n",
" right_matcher label: `matcher`,\n",
" right_matcher debug: `xyz`,\n",
" left: `\"usage: printf format [arguments ...]\\n\"`,\n",
" right: `xyz`"
);
assert_eq!(actual, expect);