Macro match_err::assert_if_error
source · macro_rules! assert_if_error { ($var:expr, $ty:ty, $variant:ident $( ( $inner:expr ) )? $(, $($arg:tt)+)? ) => { ... }; }
Expand description
Asserts the variable is an error and then asserts it against an enum-like error type by hiding the usage of downcast_ref method The error is required to implement PartialEq
§Examples
use match_err::*;
use anyhow::anyhow;
#[derive(thiserror::Error, Debug, PartialEq)]
enum Error {
#[error("not found")]
NotFound,
#[error("custom: {0}")]
Custom(String),
}
let err: Result<(), _> = Err(anyhow!(Error::Custom(String::from("internal"))));
assert_if_error!(err, Error, Custom(String::from("internal")), "invalid");