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

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

  • When true, return ().

  • Otherwise, return Err 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");
let regex = Regex::new(r"usage").unwrap();
let x = assertable_command_stderr_regex!(a, regex);
//-> Ok(())
assert_eq!(x.unwrap(), ());

let mut a = Command::new("printf");
let regex = Regex::new(r"xyz").unwrap();
let x = assertable_command_stderr_regex!(a, regex);
//-> Err("…")
// assertable failed: `assertable_command_stderr_regex!(command, regex)`
//   command program: `\"printf\"`,
//  right command program: `\"printf\"`,
//  regex: `xyz`,
//  stderr: `\"usage: printf format [arguments ...]\\n\"`,
assert_eq!(x.unwrap_err(), "assertable failed: `assertable_command_stderr_regex!(command, regex)`\n command program: `\"printf\"`,\n regex: `xyz`,\n stderr: `\"usage: printf format [arguments ...]\\n\"`");

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