macro_rules! assert_command_stderr_matches_as_result {
($a_command:expr, $b_matcher:expr $(,)?) => { ... };
}Expand description
Assert a command stderr string is a match to a given regex.
-
If true, return Result
Ok(()). -
Otherwise, return Result
Errwith a diagnostic message.
Examples
use std::process::Command;
use regex::Regex;
let mut command = Command::new("printf");
let matcher = Regex::new(r"usage").unwrap();
let x = assert_command_stderr_matches_as_result!(command, matcher);
//-> Ok(())
let actual = x.unwrap();
let expect = ();
assert_eq!(actual, expect);
let mut command = Command::new("printf");
let matcher = Regex::new(r"xyz").unwrap();
let x = assert_command_stderr_matches_as_result!(command, matcher);
//-> Err(…)
let actual = x.unwrap_err();
let expect = concat!(
"assertion failed: `assert_command_stderr_matches!(left_command, right_matcher)`\n",
" left_command label: `command`,\n",
" left_command debug: `\"printf\"`,\n",
" right_matcher label: `matcher`,\n",
" right_matcher debug: `xyz`,\n",
" left: `\"usage: printf format [arguments ...]\\n\"`,\n",
" right: `xyz`"
);
assert_eq!(actual, expect);