@@ -366,6 +366,7 @@ pub struct TestOpts {
366366 pub list : bool ,
367367 pub filter : Option < String > ,
368368 pub filter_exact : bool ,
369+ pub exclude_should_panic : bool ,
369370 pub run_ignored : RunIgnored ,
370371 pub run_tests : bool ,
371372 pub bench_benchmarks : bool ,
@@ -385,6 +386,7 @@ impl TestOpts {
385386 list : false ,
386387 filter : None ,
387388 filter_exact : false ,
389+ exclude_should_panic : false ,
388390 run_ignored : RunIgnored :: No ,
389391 run_tests : false ,
390392 bench_benchmarks : false ,
@@ -406,6 +408,7 @@ fn optgroups() -> getopts::Options {
406408 let mut opts = getopts:: Options :: new ( ) ;
407409 opts. optflag ( "" , "include-ignored" , "Run ignored and not ignored tests" )
408410 . optflag ( "" , "ignored" , "Run only ignored tests" )
411+ . optflag ( "" , "exclude-should-panic" , "Excludes tests marked as should_panic" )
409412 . optflag ( "" , "test" , "Run tests and not benchmarks" )
410413 . optflag ( "" , "bench" , "Run benchmarks instead of tests" )
411414 . optflag ( "" , "list" , "List all tests and benchmarks" )
@@ -558,6 +561,13 @@ pub fn parse_opts(args: &[String]) -> Option<OptRes> {
558561 None
559562 } ;
560563
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+
561571 let include_ignored = matches. opt_present ( "include-ignored" ) ;
562572 if !allow_unstable && include_ignored {
563573 return Some ( Err (
@@ -648,6 +658,7 @@ pub fn parse_opts(args: &[String]) -> Option<OptRes> {
648658 list,
649659 filter,
650660 filter_exact : exact,
661+ exclude_should_panic,
651662 run_ignored,
652663 run_tests,
653664 bench_benchmarks,
@@ -1365,6 +1376,11 @@ pub fn filter_tests(opts: &TestOpts, tests: Vec<TestDescAndFn>) -> Vec<TestDescA
13651376 // Skip tests that match any of the skip filters
13661377 filtered. retain ( |test| !opts. skip . iter ( ) . any ( |sf| matches_filter ( test, sf) ) ) ;
13671378
1379+ // Excludes #[should_panic] tests
1380+ if opts. exclude_should_panic {
1381+ filtered. retain ( |test| test. desc . should_panic == ShouldPanic :: No ) ;
1382+ }
1383+
13681384 // maybe unignore tests
13691385 match opts. run_ignored {
13701386 RunIgnored :: Yes => {
@@ -1983,6 +1999,29 @@ mod tests {
19831999 assert ! ( !filtered[ 1 ] . desc. ignore) ;
19842000 }
19852001
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+
19862025 #[ test]
19872026 pub fn exact_filter_match ( ) {
19882027 fn tests ( ) -> Vec < TestDescAndFn > {
0 commit comments