macro_rules! assert_fs_read_to_string_matches { ($a_path:expr, $b_matcher:expr $(,)?) => { ... }; ($a_path:expr, $b_matcher:expr, $($message:tt)+) => { ... }; }
Expand description
Assert a std::fs::read_to_string() is a match to a regex.
-
If true, return
(). -
Otherwise, call
panic!with a message and the values of the expressions with their debug representations.
§Examples
use std::io::Read;
use regex::Regex;
// Return Ok
let path = "alfa.txt";
let matcher = Regex::new(r"alfa").unwrap();
assert_fs_read_to_string_matches!(&path, matcher);
//-> ()
// Panic with error message
let result = panic::catch_unwind(|| {
let path = "alfa.txt";
let matcher = Regex::new(r"zzz").unwrap();
assert_fs_read_to_string_matches!(&path, matcher);
//-> panic!
});
assert!(result.is_err());
let actual = result.unwrap_err().downcast::<String>().unwrap().to_string();
let expect = concat!(
"assertion failed: `assert_fs_read_to_string_matches!(left_path, right_matcher)`\n",
" left_path label: `&path`,\n",
" left_path debug: `\"alfa.txt\"`,\n",
" right_matcher label: `matcher`,\n",
" right_matcher debug: `Regex(\"zzz\")`,\n",
" left: `\"alfa\\n\"`,\n",
" right: `Regex(\"zzz\")`"
);
assert_eq!(actual, expect);