macro_rules! assert_program_args_stdout_contains { ($a_program:expr, $a_args:expr, $containee:expr $(,)?) => { ... }; ($a_program:expr, $a_args:expr, $containee:expr, $($message: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
// Return Ok
let program = "bin/printf-stdout";
let args = ["%s", "hello"];
let containee = "ell";
assert_program_args_stdout_contains!(&program, &args, containee);
//-> ()
// Panic with error message
let result = panic::catch_unwind(|| {
let program = "bin/printf-stdout";
let args = ["%s", "hello"];
let containee = "zzz";
assert_program_args_stdout_contains!(&program, &args, containee);
//-> panic!
});
assert!(result.is_err());
let actual = result.unwrap_err().downcast::<String>().unwrap().to_string();
let expect = concat!(
"assertion failed: `assert_program_args_stdout_contains!(a_program, a_args, containee)`\n",
" a_program label: `&program`,\n",
" a_program debug: `\"bin/printf-stdout\"`,\n",
" a_args label: `&args`,\n",
" a_args debug: `[\"%s\", \"hello\"]`,\n",
" containee label: `containee`,\n",
" containee debug: `\"zzz\"`,\n",
" a: `\"hello\"`,\n",
" b: `\"zzz\"`"
);
assert_eq!(actual, expect);