macro_rules! assert_command_stdout_regex {
    ($ command:expr, $regex:expr $(,)?) => { ... };
    ($ command:expr, $regex:expr, $($arg:tt)+) => { ... };
}
Expand description

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

  • When 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 a = Command::new("printf");
a.args(["%s", "hello"]);
let regex = Regex::new(r"el").unwrap();
assert_command_stdout_regex!(a, regex);
//-> ()

let mut a = Command::new("printf");
a.args(["%s", "hello"]);
let regex = Regex::new(r"xyz").unwrap();
assert_command_stdout_regex!(a, regex);
//-> panic!("…")
// assertion failed: `assert_command_stdout_regex!(command, regex)`
//  command program: `\"printf\"`,
//  regex: `xyz`,
//  stdout: `\"hello\"`,

This macro has a second form where a custom message can be provided.