Macro lib::assert_command_stdout_contains
source · macro_rules! assert_command_stdout_contains { ($command:expr, $b:expr $(,)?) => { ... }; ($command:expr, $b:expr, $($message:tt)+) => { ... }; }
Expand description
Assert a command 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
use std::process::Command;
// Return Ok
let mut command = Command::new("bin/printf-stdout");
command.args(["%s", "hello"]);
let containee = "ell";
assert_command_stdout_contains!(command, containee);
//-> ()
// Panic with error message
let result = panic::catch_unwind(|| {
let mut command = Command::new("bin/printf-stdout");
command.args(["%s", "hello"]);
let containee = "zzz";
assert_command_stdout_contains!(command, containee);
//-> panic!
});
assert!(result.is_err());
let actual = result.unwrap_err().downcast::<String>().unwrap().to_string();
let expect = concat!(
"assertion failed: `assert_command_stdout_contains!(command, containee)`\n",
" command label: `command`,\n",
" command debug: `\"bin/printf-stdout\" \"%s\" \"hello\"`,\n",
" containee label: `containee`,\n",
" containee debug: `\"zzz\"`,\n",
" command value: `\"hello\"`,\n",
" containee value: `\"zzz\"`"
);
assert_eq!(actual, expect);
// Panic with custom message
let result = panic::catch_unwind(|| {
let mut command = Command::new("bin/printf-stdout");
command.args(["%s", "hello"]);
let containee = "zzz";
assert_command_stdout_contains!(command, containee, "message");
//-> panic!
});
assert!(result.is_err());
let actual = result.unwrap_err().downcast::<String>().unwrap().to_string();
let expect = "message";
assert_eq!(actual, expect);