macro_rules! assert_command_stdout_matches_as_result {
    ($a_command:expr, $b_expr:expr $(,)?) => { ... };
}
Expand description

Assert a command stdout string is a match to a given regex.

  • When true, return ().

  • When true, return Result Err with 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_expr)`\n",
    "  left command name: `command`,\n",
    "    right expr name: `matcher`,\n",
    "       left command: `\"printf\"`,\n",
    "         right expr: `xyz`,\n",
    "               left: `\"hello\"`,\n",
    "              right: `xyz`"
);
assert_eq!(actual, expect);