assertables

Macro assert_command_stdout_is_match

source
macro_rules! assert_command_stdout_is_match {
    ($command:expr, $matcher:expr $(,)?) => { ... };
    ($command:expr, $matcher:expr, $($message:tt)+) => { ... };
}
๐Ÿ‘ŽDeprecated: Please rename from assert_command_stdout_is_match to assert_command_stdout_string_is_match because this macro does the comparison via a Rust UTF-8 String.
Expand description

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

Pseudocode:
(command โ‡’ stdout โ‡’ string) is match (expr into string)

  • If true, return ().

  • Otherwise, call panic! with a message and the values of the expressions with their debug representations.

ยงExamples

use assertables::*;
use std::process::Command;
use regex::Regex;

let mut command = Command::new("bin/printf-stdout");
command.args(["%s", "alfa"]);
let matcher = Regex::new(r"lf").unwrap();
assert_command_stdout_is_match!(command, &matcher);

// This will panic
let mut command = Command::new("bin/printf-stdout");
command.args(["%s", "alfa"]);
let matcher = Regex::new(r"zz").unwrap();
assert_command_stdout_is_match!(command, &matcher);
// assertion failed: `assert_command_stdout_is_match!(command, matcher)`
// https://docs.rs/assertables/8.18.0/assertables/macro.assert_command_stdout_is_match.html
//  command label: `command`,
//  command debug: `\"bin/printf-stdout\" \"%s\" \"alfa\"`,
//  matcher label: `&matcher`,
//  matcher debug: `Regex(\"zz\")`,
//  command value: `\"alfa\"`,
//  matcher value: `Regex(\"zz\")`

ยงModule macros