@@ -366,6 +366,7 @@ pub struct TestOpts {
366
366
pub list : bool ,
367
367
pub filter : Option < String > ,
368
368
pub filter_exact : bool ,
369
+ pub exclude_should_panic : bool ,
369
370
pub run_ignored : RunIgnored ,
370
371
pub run_tests : bool ,
371
372
pub bench_benchmarks : bool ,
@@ -385,6 +386,7 @@ impl TestOpts {
385
386
list : false ,
386
387
filter : None ,
387
388
filter_exact : false ,
389
+ exclude_should_panic : false ,
388
390
run_ignored : RunIgnored :: No ,
389
391
run_tests : false ,
390
392
bench_benchmarks : false ,
@@ -406,6 +408,7 @@ fn optgroups() -> getopts::Options {
406
408
let mut opts = getopts:: Options :: new ( ) ;
407
409
opts. optflag ( "" , "include-ignored" , "Run ignored and not ignored tests" )
408
410
. optflag ( "" , "ignored" , "Run only ignored tests" )
411
+ . optflag ( "" , "exclude-should-panic" , "Excludes tests marked as should_panic" )
409
412
. optflag ( "" , "test" , "Run tests and not benchmarks" )
410
413
. optflag ( "" , "bench" , "Run benchmarks instead of tests" )
411
414
. optflag ( "" , "list" , "List all tests and benchmarks" )
@@ -558,6 +561,13 @@ pub fn parse_opts(args: &[String]) -> Option<OptRes> {
558
561
None
559
562
} ;
560
563
564
+ let exclude_should_panic = matches. opt_present ( "exclude-should-panic" ) ;
565
+ if !allow_unstable && exclude_should_panic {
566
+ return Some ( Err (
567
+ "The \" exclude-should-panic\" flag is only accepted on the nightly compiler" . into ( ) ,
568
+ ) ) ;
569
+ }
570
+
561
571
let include_ignored = matches. opt_present ( "include-ignored" ) ;
562
572
if !allow_unstable && include_ignored {
563
573
return Some ( Err (
@@ -648,6 +658,7 @@ pub fn parse_opts(args: &[String]) -> Option<OptRes> {
648
658
list,
649
659
filter,
650
660
filter_exact : exact,
661
+ exclude_should_panic,
651
662
run_ignored,
652
663
run_tests,
653
664
bench_benchmarks,
@@ -1365,6 +1376,11 @@ pub fn filter_tests(opts: &TestOpts, tests: Vec<TestDescAndFn>) -> Vec<TestDescA
1365
1376
// Skip tests that match any of the skip filters
1366
1377
filtered. retain ( |test| !opts. skip . iter ( ) . any ( |sf| matches_filter ( test, sf) ) ) ;
1367
1378
1379
+ // Excludes #[should_panic] tests
1380
+ if opts. exclude_should_panic {
1381
+ filtered. retain ( |test| test. desc . should_panic == ShouldPanic :: No ) ;
1382
+ }
1383
+
1368
1384
// maybe unignore tests
1369
1385
match opts. run_ignored {
1370
1386
RunIgnored :: Yes => {
@@ -1983,6 +1999,29 @@ mod tests {
1983
1999
assert ! ( !filtered[ 1 ] . desc. ignore) ;
1984
2000
}
1985
2001
2002
+ #[ test]
2003
+ pub fn exclude_should_panic_option ( ) {
2004
+ let mut opts = TestOpts :: new ( ) ;
2005
+ opts. run_tests = true ;
2006
+ opts. exclude_should_panic = true ;
2007
+
2008
+ let mut tests = one_ignored_one_unignored_test ( ) ;
2009
+ tests. push ( TestDescAndFn {
2010
+ desc : TestDesc {
2011
+ name : StaticTestName ( "3" ) ,
2012
+ ignore : false ,
2013
+ should_panic : ShouldPanic :: Yes ,
2014
+ allow_fail : false ,
2015
+ } ,
2016
+ testfn : DynTestFn ( Box :: new ( move || { } ) ) ,
2017
+ } ) ;
2018
+
2019
+ let filtered = filter_tests ( & opts, tests) ;
2020
+
2021
+ assert_eq ! ( filtered. len( ) , 2 ) ;
2022
+ assert ! ( filtered. iter( ) . all( |test| test. desc. should_panic == ShouldPanic :: No ) ) ;
2023
+ }
2024
+
1986
2025
#[ test]
1987
2026
pub fn exact_filter_match ( ) {
1988
2027
fn tests ( ) -> Vec < TestDescAndFn > {
0 commit comments