macro_rules! assert_program_args_stdout_eq {
($a_program:expr, $a_args:expr, $b_expr:expr $(,)?) => { ... };
($a_program:expr, $a_args:expr, $b_expr:expr, $($message:tt)+) => { ... };
}Expand description
Assert a command (built with program and args) 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
// Return Ok
let program = "printf";
let args = ["%s", "hello"];
let s = "hello";
assert_program_args_stdout_eq!(&program, &args, s);
//-> ()
// Panic with error message
let result = panic::catch_unwind(|| {
let program = "printf";
let args = ["%s", "hello"];
let s = "world";
assert_program_args_stdout_eq!(&program, &args, s);
//-> panic!
});
assert!(result.is_err());
let actual = result.unwrap_err().downcast::<String>().unwrap().to_string();
let expect = concat!(
"assertion failed: `assert_program_args_stdout_eq!(left_program, left_args, right_expr)`\n",
" left_program label: `&program`,\n",
" left_program debug: `\"printf\"`,\n",
" left_args label: `&args`,\n",
" left_args debug: `[\"%s\", \"hello\"]`,\n",
" right_expr label: `s`,\n",
" right_expr debug: `\"world\"`,\n",
" left: `\"hello\"`,\n",
" right: `\"world\"`"
);
assert_eq!(actual, expect);