macro_rules! assert_command_stdout_matches {
($command:expr, $b:expr $(,)?) => { ... };
($command:expr, $b:expr, $($arg:tt)+) => { ... };
}Expand description
Assert a command stdout 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 std::process::Command;
use regex::Regex;
let mut command = Command::new("printf");
command.args(["%s", "hello"]);
let matcher = Regex::new(r"el").unwrap();
assert_command_stdout_matches!(command, matcher);
//-> ()
let result = panic::catch_unwind(|| {
let mut command = Command::new("printf");
command.args(["%s", "hello"]);
let matcher = Regex::new(r"xyz").unwrap();
assert_command_stdout_matches!(command, matcher);
//-> panic!
});
let actual = result.unwrap_err().downcast::<String>().unwrap().to_string();
let expect = concat!(
"assertion failed: `assert_command_stdout_matches!(left_command, right_matcher)`\n",
" left_command label: `command`,\n",
" left_command debug: `\"printf\" \"%s\" \"hello\"`,\n",
" right_matcher label: `matcher`,\n",
" right_matcher debug: `xyz`,\n",
" left: `\"hello\"`,\n",
" right: `xyz`"
);
assert_eq!(actual, expect);