macro_rules! assert_program_args_stdout_matches_as_result {
($a_program:expr, $a_args:expr, $b_matcher:expr $(,)?) => { ... };
}Expand description
Assert a command (built with program and args) stdout string is a match to a given regex.
-
If true, return Result
Ok(()). -
Otherwise, return Result
Errwith a diagnostic message.
Examples
use regex::Regex;
let program = "printf";
let args = ["%s", "hello"];
let matcher = Regex::new(r"el").unwrap();
let x = assert_program_args_stdout_matches_as_result!(&program, &args, matcher);
//-> Ok(())
let actual = x.unwrap();
let expect = ();
assert_eq!(actual, expect);
let program = "printf";
let args = ["%s", "hello"];
let matcher = Regex::new(r"xyz").unwrap();
let x = assert_program_args_stdout_matches_as_result!(&program, &args, matcher);
//-> Err(…)
let actual = x.unwrap_err();
let expect = concat!(
"assertion failed: `assert_program_args_stdout_matches!(left_program, right_matcher)`\n",
" left_program label: `&program`,\n",
" left_program debug: `\"printf\"`,\n",
" left_args label: `&args`,\n",
" left_args debug: `[\"%s\", \"hello\"]`,\n",
" right_matcher label: `matcher`,\n",
" right_matcher debug: `xyz`,\n",
" left: `\"hello\"`,\n",
" right: `xyz`"
);
assert_eq!(actual, expect);