macro_rules! assert_command_stderr_contains_as_result {
($a_command:expr, $b_containee:expr $(,)?) => { ... };
}Expand description
Assert a command stderr string contains a given containee.
-
If true, return Result
Ok(()). -
Otherwise, return Result
Errwith a diagnostic message.
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;
let mut command = Command::new("printf");
let containee = "usage";
let x = assert_command_stderr_contains_as_result!(command, containee);
//-> Ok(())
let actual = x.unwrap();
let expect = ();
assert_eq!(actual, expect);
let mut command = Command::new("printf");
let containee = "xyz";
let x = assert_command_stderr_contains_as_result!(command, containee);
//-> Err(…)
let actual = x.unwrap_err();
let expect = concat!(
"assertion failed: `assert_command_stderr_contains!(left_command, right_containee)`\n",
" left_command label: `command`,\n",
" left_command debug: `\"printf\"`,\n",
" right_containee label: `containee`,\n",
" right_containee debug: `\"xyz\"`,\n",
" left: `\"usage: printf format [arguments ...]\\n\"`,\n",
" right: `\"xyz\"`"
);
assert_eq!(actual, expect);