macro_rules! assert_command_stdout_contains_as_result {
    ($a_command:expr, $b_containee:expr $(,)?) => { ... };
}
Expand description

Assert a command stdout string contains a given containee.

  • If true, return Result Ok(()).

  • Otherwise, return Result Err with 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");
command.args(["%s", "hello"]);
let containee = "ell";
let x = assert_command_stdout_contains_as_result!(command, containee);
//-> Ok(())
let actual = x.unwrap();
let expect = ();
assert_eq!(actual, expect);

let mut command = Command::new("printf");
command.args(["%s", "hello"]);
let containee = "xyz";
let x = assert_command_stdout_contains_as_result!(command, containee);
//-> Err(…)
let actual = x.unwrap_err();
let expect = concat!(
    "assertion failed: `assert_command_stdout_contains!(left_command, right_containee)`\n",
    "    left_command label: `command`,\n",
    "    left_command debug: `\"printf\" \"%s\" \"hello\"`,\n",
    " right_containee label: `containee`,\n",
    " right_containee debug: `\"xyz\"`,\n",
    "                  left: `\"hello\"`,\n",
    "                 right: `\"xyz\"`"
);
assert_eq!(actual, expect);