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

Assert a command stdout string is equal to another.

  • If true, return ().

  • If true, return Result Err with a message and the values of the expressions with their debug representations.

Examples

use std::process::Command;

let mut a = Command::new("printf");
a.args(["%s", "hello"]);
let mut b = Command::new("printf");
b.args(["%s%s%s%s%s", "h", "e", "l", "l", "o"]);
let x = assert_command_stdout_eq_other_as_result!(a, b);
//-> Ok(())
let actual = x.unwrap();
let expect = ();
assert_eq!(actual, expect);

let mut a = Command::new("printf");
a.args(["%s", "hello"]);
let mut b = Command::new("printf");
b.args(["%s%s%s%s%s", "w", "o", "r", "l", "d"]);
let x = assert_command_stdout_eq_other_as_result!(a, b);
//-> Err(…)
let actual = x.unwrap_err();
let expect = concat!(
    "assertion failed: `assert_command_stdout_eq_other!(left_command, right_command)`\n",
    "  left_command label: `a`,\n",
    "  left_command debug: `\"printf\" \"%s\" \"hello\"`,\n",
    " right_command label: `b`,\n",
    " right_command debug: `\"printf\" \"%s%s%s%s%s\" \"w\" \"o\" \"r\" \"l\" \"d\"`,\n",
    "                left: `\"hello\"`,\n",
    "               right: `\"world\"`"
);
assert_eq!(actual, expect);

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