macro_rules! assertable_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, return
Errwith 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();
let x = assertable_command_stdout_regex!(a, regex);
//-> Ok(())
assert_eq!(x.unwrap(), ());
let mut a = Command::new("printf");
a.args(["%s", "hello"]);
let regex = Regex::new(r"xyz").unwrap();
let x = assertable_command_stdout_regex!(a, regex);
//-> Err("…")
// assertable failed: `assertable_command_stdout_regex!(command, regex)`
// command program: `\"printf\"`,
// regex: `xyz`
// stdout: `\"hello\"`,
assert_eq!(x.unwrap_err(), "assertable failed: `assertable_command_stdout_regex!(command, regex)`\n command program: `\"printf\"`,\n regex: `xyz`,\n stdout: `\"hello\"`");This macro has a second form where a custom message can be provided.