macro_rules! assert_read_to_string_eq_expr { ($a_reader:expr, $b_expr:expr $(,)?) => { ... }; ($a_reader:expr, $b_expr:expr, $($message:tt)+) => { ... }; }
Expand description
Assert a std::io::Read read_to_string() value is equal to an expression.
-
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 = "alpha".as_bytes();
let value = String::from("alpha");
assert_read_to_string_eq_expr!(reader, &value);
//-> ()
// Panic with error message
let result = panic::catch_unwind(|| {
let mut reader = "alpha".as_bytes();
let value = String::from("bravo");
assert_read_to_string_eq_expr!(reader, &value);
//-> panic!
});
assert!(result.is_err());
let actual = result.unwrap_err().downcast::<String>().unwrap().to_string();
let expect = concat!(
"assertion failed: `assert_read_to_string_eq_expr!(left_reader, right_expr)`\n",
" left_reader label: `reader`,\n",
" left_reader debug: `[]`,\n",
" right_expr label: `&value`,\n",
" right_expr debug: `\"bravo\"`,\n",
" left: `\"alpha\"`,\n",
" right: `\"bravo\"`"
);
assert_eq!(actual, expect);