macro_rules! assert_io_read_to_string_contains { ($reader:expr, $containee:expr $(,)?) => { ... }; ($a:expr, $b:expr, $($message:tt)+) => { ... }; }
Expand description
Assert a std::io::Read read_to_string() contains a pattern.
-
If true, return
(). -
Otherwise, call
panic!with a message and the values of the expressions with their debug representations.
§Examples
use std::io::Read;
// Return Ok
let mut reader = "hello".as_bytes();
let containee = "ell";
assert_io_read_to_string_contains!(reader, containee);
//-> ()
// Panic with error message
let result = panic::catch_unwind(|| {
let mut reader = "hello".as_bytes();
let containee = "zzz";
assert_io_read_to_string_contains!(reader, containee);
//-> panic!
});
assert!(result.is_err());
let actual = result.unwrap_err().downcast::<String>().unwrap().to_string();
let expect = concat!(
"assertion failed: `assert_io_read_to_string_contains!(reader, containee)`\n",
" reader label: `reader`,\n",
" reader debug: `[]`,\n",
" containee label: `containee`,\n",
" containee debug: `\"zzz\"`,\n",
" reader value: `\"hello\"`,\n",
" containee value: `\"zzz\"`"
);
assert_eq!(actual, expect);