use thiserror::Error;
use impass::{fatal, fatal_fn};
#[derive(Error, Debug)]
pub enum MyError {
#[error("This operation failed")]
OperationFailed
}
fn might_fail(should_fail: bool) -> Result<i32, MyError> {
if should_fail {
Err(MyError::OperationFailed)
} else {
Ok(42)
}
}
#[test]
fn test_fatal_success() {
let result: i32 = fatal! {
let value: i32 = might_fail(false)?;
Ok(value)
};
assert_eq!(result, 42);
}
#[test]
#[should_panic]
#[fatal_fn]
fn test_fatal_panic() {
let _: i32 = might_fail(true)?;
Ok(())
}
#[test]
#[should_panic]
#[fatal_fn(reason = "Failed with a specific error")]
fn test_fatal_reason() {
let _: i32 = might_fail(true)?;
Ok(())
}