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];
}
```
This commit is contained in:
Steven Fackler
2014-12-04 23:02:36 -08:00
parent de83d7dd19
commit 616af6eb83
6 changed files with 150 additions and 29 deletions

View File

@@ -280,7 +280,7 @@ impl Collector {
desc: testing::TestDesc {
name: testing::DynTestName(name),
ignore: should_ignore,
should_fail: false, // compiler failures are test failures
should_fail: testing::ShouldFail::No, // compiler failures are test failures
},
testfn: testing::DynTestFn(proc() {
runtest(test.as_slice(),