Macro assertables::assert_command_stdout_eq
source · [−]macro_rules! assert_command_stdout_eq {
($a_command:expr, $b_expr:expr $(,)?) => { ... };
($a_command:expr, $b_expr:expr, $($arg:tt)+) => { ... };
}Expand description
Assert a command stdout string is equal to an expression.
-
If true, return
(). -
Otherwise, call
panic!with a message and the values of the expressions with their debug representations.
Examples
use std::process::Command;
let mut command = Command::new("printf");
command.args(["%s", "hello"]);
let s = "hello";
assert_command_stdout_eq!(command, s);
//-> ()
let result = panic::catch_unwind(|| {
let mut command = Command::new("printf");
command.args(["%s", "hello"]);
let s = "world";
assert_command_stdout_eq!(command, s);
//-> panic!
});
let actual = result.unwrap_err().downcast::<String>().unwrap().to_string();
let expect = concat!(
"assertion failed: `assert_command_stdout_eq!(left_command, right_expr)`\n",
" left_command label: `command`,\n",
" left_command debug: `\"printf\" \"%s\" \"hello\"`,\n",
" right_expr label: `s`,\n",
" right_expr debug: `\"world\"`,\n",
" left: `\"hello\"`,\n",
" right: `\"world\"`"
);
assert_eq!(actual, expect);