]> git.lizzy.rs Git - rust.git/commit
Allow message specification for should_fail
authorSteven Fackler <sfackler@gmail.com>
Fri, 5 Dec 2014 07:02:36 +0000 (23:02 -0800)
committerSteven Fackler <sfackler@gmail.com>
Sat, 6 Dec 2014 23:13:48 +0000 (15:13 -0800)
commit616af6eb83630b76bb3a9bde57a00f5ebe5dbd6c
tree494380149d05abc6c6954b1b6bcbee856563d163
parentde83d7dd191bf5564855057a29f9b5d9dcfcb201
Allow message specification for should_fail

The test harness will make sure that the panic message contains the
specified string. This is useful to help make `#[should_fail]` tests a
bit less brittle by decreasing the chance that the test isn't
"accidentally" passing due to a panic occurring earlier than expected.
The behavior is in some ways similar to JUnit's `expected` feature:
`@Test(expected=NullPointerException.class)`.

Without the message assertion, this test would pass even though it's not
actually reaching the intended part of the code:
```rust
 #[test]
 #[should_fail(message = "out of bounds")]
fn test_oob_array_access() {
    let idx: uint = from_str("13o").unwrap(); // oops, this will panic
    [1i32, 2, 3][idx];
}
```
src/compiletest/compiletest.rs
src/librustdoc/test.rs
src/libsyntax/test.rs
src/libtest/lib.rs
src/test/run-fail/test-should-fail-bad-message.rs [new file with mode: 0644]
src/test/run-pass/test-should-fail-good-message.rs [new file with mode: 0644]