I'm looking for a way to assert that a piece of code panics, and that the panic message contains a particular string. I came up with the following which appears to work:
let actual = std::panic::catch_unwind(|| decode(notation.to_string()));
assert!(actual.is_err());
let err = *(actual.unwrap_err().downcast::<String>().unwrap());
assert!(err.contains("Invalid"));
I know that I can use #[should_panic] and that it lets me specify a message to check for, but I only want to partially match the exact error message.