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

#1

such as

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

#2

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();
}
0 Likes

#3

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 https://docs.rs/matches/0.1.6/matches/macro.assert_matches.html)

7 Likes