Macro match_err::assert_error
source · macro_rules! assert_error { ($var:expr, $ty:ty, $variant:ident $( ( $inner:expr ) )? $(, $($arg:tt)+)? ) => { ... }; }
Expand description
Asserts the error 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 = anyhow!(Error::Custom(String::from("internal")));
assert_error!(err, Error, Custom(String::from("internal")));