]> git.lizzy.rs Git - rust.git/commit
auto merge of #19560 : sfackler/rust/should-fail-reason, r=alexcrichton
authorbors <bors@rust-lang.org>
Mon, 8 Dec 2014 12:12:23 +0000 (12:12 +0000)
committerbors <bors@rust-lang.org>
Mon, 8 Dec 2014 12:12:23 +0000 (12:12 +0000)
commitc7a9b49d1b5d4e520f25355f26a93dfac4ffa146
tree7a2a559658447be5fe71de276b7e8296b2999770
parentcf0b4e068227dd33fa15f3ffe24f29e0535d197f
parenta20926a51add66ab67053843e244efb1a4d7ad76
auto merge of #19560 : sfackler/rust/should-fail-reason, r=alexcrichton

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/libtest/lib.rs