Skip to content

How do I write a Rust unit test that ensures that a panic has occurred?

ref: https://stackoverflow.com/questions/26469715/how-do-i-write-a-rust-unit-test-that-ensures-that-a-panic-has-occurred

#[test]
#[should_panic(expected = "invalid var name: \"1x\"")]
fn test_invalid_name() {
    let s = "(let (1x 2) 3)";
    let _ = parse(s);
}