Skip to content

Commit

Permalink
util: test expect_err failures
Browse files Browse the repository at this point in the history
  • Loading branch information
daviddrysdale committed Apr 5, 2024
1 parent 78b49d7 commit f531ada
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions src/util/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,35 @@ fn test_cbor_type_error() {
expect_err(e, want);
}
}

#[test]
#[should_panic]
fn test_expect_err_but_ok() {
let result: Result<i32, crate::CoseError> = Ok(42);
expect_err(result, "absent text");
}

#[test]
#[should_panic]
fn test_expect_err_wrong_msg() {
let err = cbor_type_error::<()>(&Value::Bool(true), "a");
expect_err(err, "incorrect text");
}

#[test]
#[should_panic]
fn test_expect_err_wrong_display_msg() {
// Error type where `Debug` shows the message but `Display` doesn't
#[allow(dead_code)]
#[derive(Debug)]
struct Error(&'static str);
impl core::fmt::Display for Error {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
write!(f, "other")
}
}

let err: Result<i32, Error> = Err(Error("text"));
// The expected text appears in the `Debug` output but not the `Display` output.
expect_err(err, "text");
}

0 comments on commit f531ada

Please sign in to comment.