macro_rules! assert_command_stdout_matches_as_result {
($command:expr, $b:expr $(,)?) => { ... };
}Expand description
Assert a command stdout 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");
command.args(["%s", "hello"]);
let matcher = Regex::new(r"el").unwrap();
let x = assert_command_stdout_matches_as_result!(command, matcher);
//-> Ok(())
let actual = x.unwrap();
let expect = ();
assert_eq!(actual, expect);
let mut command = Command::new("printf");
command.args(["%s", "hello"]);
let matcher = Regex::new(r"xyz").unwrap();
let x = assert_command_stdout_matches_as_result!(command, matcher);
//-> Err(…)
let actual = x.unwrap_err();
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);