macro_rules! assert_program_args_stdout_contains {
($a_program:expr, $a_args:expr, $b_containee:expr $(,)?) => { ... };
($a_program:expr, $a_args:expr, $b_containee:expr, $($arg:tt)+) => { ... };
}Expand description
Assert a command (built with program and args) stdout string contains a given containee.
-
If true, return
(). -
Otherwise, call
panic!with a message and the values of the expressions with their debug representations.
This uses [std::String] method contains.
- The containee can be a &str, char, a slice of chars, or a function or closure that determines if a character contains.
Examples
let program = "printf";
let args = ["%s", "hello"];
let containee = "ell";
assert_program_args_stdout_contains!(&program, &args, containee);
//-> ()
let result = panic::catch_unwind(|| {
let program = "printf";
let args = ["%s", "hello"];
let containee = "xyz";
assert_program_args_stdout_contains!(&program, &args, containee);
//-> panic!
});
let actual = result.unwrap_err().downcast::<String>().unwrap().to_string();
let expect = concat!(
"assertion failed: `assert_program_args_stdout_contains!(left_program, left_args, right_containee)`\n",
" left_program label: `&program`,\n",
" left_program debug: `\"printf\"`,\n",
" left_args label: `&args`,\n",
" left_args debug: `[\"%s\", \"hello\"]`,\n",
" right_containee label: `containee`,\n",
" right_containee debug: `\"xyz\"`,\n",
" left: `\"hello\"`,\n",
" right: `\"xyz\"`"
);
assert_eq!(actual, expect);