-
Notifications
You must be signed in to change notification settings - Fork 12.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of #37749 - keeperofdakeys:should-panic, r=alexcrichton
Improvements to the #[should_panic] feature Add more error checking for the `#[should_panic]` attribute, and print the expected panic string when it does not match. Fixes #29000 Eg: ```running 3 tests test test2 ... ok test test1 ... FAILED : Panic did not include expected string 'foo' test test3 ... FAILED failures: ---- test1 stdout ---- thread 'test1' panicked at 'bar', test.rs:7 note: Run with `RUST_BACKTRACE=1` for a backtrace. ---- test3 stdout ---- thread 'test3' panicked at 'bar', test.rs:18 ```
- Loading branch information
Showing
5 changed files
with
151 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT | ||
// file at the top-level directory of this distribution and at | ||
// http://rust-lang.org/COPYRIGHT. | ||
// | ||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or | ||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license | ||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your | ||
// option. This file may not be copied, modified, or distributed | ||
// except according to those terms. | ||
|
||
// compile-flags: --test | ||
|
||
// error-pattern:panicked at 'bar' | ||
// check-stdout | ||
#[test] | ||
#[should_panic(expected = "foo")] | ||
pub fn test_bar() { | ||
panic!("bar") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT | ||
// file at the top-level directory of this distribution and at | ||
// http://rust-lang.org/COPYRIGHT. | ||
// | ||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or | ||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license | ||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your | ||
// option. This file may not be copied, modified, or distributed | ||
// except according to those terms. | ||
|
||
// compile-flags: --test | ||
|
||
// error-pattern:panicked at 'explicit panic' | ||
// check-stdout | ||
#[test] | ||
#[should_panic(expected = "foo")] | ||
pub fn test_explicit() { | ||
panic!() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT | ||
// file at the top-level directory of this distribution and at | ||
// http://rust-lang.org/COPYRIGHT. | ||
// | ||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or | ||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license | ||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your | ||
// option. This file may not be copied, modified, or distributed | ||
// except according to those terms. | ||
|
||
// compile-flags: --test | ||
|
||
#[test] | ||
#[should_panic = "foo"] | ||
//~^ WARN: attribute must be of the form: | ||
fn test1() { | ||
panic!(); | ||
} | ||
|
||
#[test] | ||
#[should_panic(expected)] | ||
//~^ WARN: argument must be of the form: | ||
fn test2() { | ||
panic!(); | ||
} | ||
|
||
#[test] | ||
#[should_panic(expect)] | ||
//~^ WARN: argument must be of the form: | ||
fn test3() { | ||
panic!(); | ||
} | ||
|
||
#[test] | ||
#[should_panic(expected(foo, bar))] | ||
//~^ WARN: argument must be of the form: | ||
fn test4() { | ||
panic!(); | ||
} | ||
|
||
#[test] | ||
#[should_panic(expected = "foo", bar)] | ||
//~^ WARN: argument must be of the form: | ||
fn test5() { | ||
panic!(); | ||
} |