Macro assertables::assert_is_match
source · macro_rules! assert_is_match { ($matcher:expr, $matchee:expr $(,)?) => { ... }; ($matcher:expr, $matchee:expr, $($message:tt)+) => { ... }; }
Expand description
Assert a matcher is a match for an expression.
-
If true, return
()
. -
Otherwise, call
panic!
with a message and the values of the expressions with their debug representations.
Examples
use std::process::Command;
use regex::Regex;
// Return Ok
let a = Regex::new(r"foo").unwrap();
let b = "foogoo";
assert_is_match!(a, b);
//-> ()
// Panic with error message
let result = panic::catch_unwind(|| {
let a = Regex::new(r"foo").unwrap();
let b = "yoohoo";
assert_is_match!(a, b);
//-> panic!
});
assert!(result.is_err());
let actual = result.unwrap_err().downcast::<String>().unwrap().to_string();
let expect = concat!(
"assertion failed: `assert_is_match!(matcher, matchee)`\n",
" matcher label: `a`,\n",
" matcher debug: `foo`,\n",
" matchee label: `b`,\n",
" matchee debug: `\"yoohoo\"`"
);
assert_eq!(actual, expect);