feat: Stringify and print error pattern on assert_error failure

pull/24376/head
Carol (Nichols || Goulding) 2021-11-08 11:10:31 -05:00
parent 3dda694520
commit 9c40bd87fb
No known key found for this signature in database
GPG Key ID: E907EE5A736F87D4
1 changed files with 6 additions and 1 deletions

View File

@ -153,6 +153,11 @@ macro_rules! assert_not_contains {
macro_rules! assert_error {
($OPERATION: expr, $(|)? $( $ERROR_PATTERN:pat_param )|+ $( if $GUARD: expr )? $(,)?) => {
let err = $OPERATION.unwrap_err();
assert!(matches!(err, $( $ERROR_PATTERN )|+ $( if $GUARD )?), "got: {:?}", err);
assert!(
matches!(err, $( $ERROR_PATTERN )|+ $( if $GUARD )?),
"Expected {}, but got {:?}",
stringify!($( $ERROR_PATTERN )|+ $( if $GUARD )?),
err
);
};
}