Is there macro like `should_panic` but for `Result` value

such as

    #[test]
    #[should_err]
    fn test() -> Result<(), i32> {
        Err(-1)
    }

Perhaps it would be more logical to do the following:

#[test]
#[should_panic]
fn test(){
    let mut val: Result<(), i32> = Err(-1);
    //Run test and set `val`
    val.unwrap();
}

I'm not a big fan of should_panic, since it's really easy to have the test succeed because of the wrong panic.

Why no just do assert!(foo().is_err()) or assert_matches!(foo(), Err(-1));? (The latter using matches::assert_matches - Rust)

7 Likes