« Minimal Reproducible »

Home Tags About GitHub

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

Published at 2024-04-28
Last update over 365 days ago Licensed under CC BY-NC-SA 4.0 langsrusttest

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);
}

« Minimal Reproducible »

Powered by Astro