@@ -80,7 +80,7 @@ const QUIET_MODE_MAX_COLUMN: usize = 100; // insert a '\n' after 100 tests in qu
80
80
// to be used by rustc to compile tests in libtest
81
81
pub mod test {
82
82
pub use { assert_test_result, filter_tests, parse_opts, run_test, test_main, test_main_static,
83
- Bencher , DynTestFn , DynTestName , Metric , MetricMap , Options , ShouldPanic ,
83
+ Bencher , DynTestFn , DynTestName , Metric , MetricMap , Options , RunIgnored , ShouldPanic ,
84
84
StaticBenchFn , StaticTestFn , StaticTestName , TestDesc , TestDescAndFn , TestName ,
85
85
TestOpts , TestResult , TrFailed , TrFailedMsg , TrIgnored , TrOk } ;
86
86
}
@@ -348,12 +348,19 @@ pub enum OutputFormat {
348
348
Json ,
349
349
}
350
350
351
+ #[ derive( Copy , Clone , Debug , PartialEq , Eq ) ]
352
+ pub enum RunIgnored {
353
+ Yes ,
354
+ No ,
355
+ Only ,
356
+ }
357
+
351
358
#[ derive( Debug ) ]
352
359
pub struct TestOpts {
353
360
pub list : bool ,
354
361
pub filter : Option < String > ,
355
362
pub filter_exact : bool ,
356
- pub run_ignored : bool ,
363
+ pub run_ignored : RunIgnored ,
357
364
pub run_tests : bool ,
358
365
pub bench_benchmarks : bool ,
359
366
pub logfile : Option < PathBuf > ,
@@ -372,7 +379,7 @@ impl TestOpts {
372
379
list : false ,
373
380
filter : None ,
374
381
filter_exact : false ,
375
- run_ignored : false ,
382
+ run_ignored : RunIgnored :: No ,
376
383
run_tests : false ,
377
384
bench_benchmarks : false ,
378
385
logfile : None ,
@@ -391,7 +398,8 @@ pub type OptRes = Result<TestOpts, String>;
391
398
392
399
fn optgroups ( ) -> getopts:: Options {
393
400
let mut opts = getopts:: Options :: new ( ) ;
394
- opts. optflag ( "" , "ignored" , "Run ignored tests" )
401
+ opts. optflag ( "" , "all" , "Run ignored and not ignored tests" )
402
+ . optflag ( "" , "ignored" , "Run only ignored tests" )
395
403
. optflag ( "" , "test" , "Run tests and not benchmarks" )
396
404
. optflag ( "" , "bench" , "Run benchmarks instead of tests" )
397
405
. optflag ( "" , "list" , "List all tests and benchmarks" )
@@ -490,8 +498,8 @@ Test Attributes:
490
498
contain: #[should_panic(expected = "foo")].
491
499
#[ignore] - When applied to a function which is already attributed as a
492
500
test, then the test runner will ignore these tests during
493
- normal test runs. Running with --ignored will run these
494
- tests."# ,
501
+ normal test runs. Running with --ignored or --all will run
502
+ these tests."# ,
495
503
usage = options. usage( & message)
496
504
) ;
497
505
}
@@ -544,7 +552,14 @@ pub fn parse_opts(args: &[String]) -> Option<OptRes> {
544
552
None
545
553
} ;
546
554
547
- let run_ignored = matches. opt_present ( "ignored" ) ;
555
+ let run_ignored = match ( matches. opt_present ( "all" ) , matches. opt_present ( "ignored" ) ) {
556
+ ( true , true ) => return Some ( Err (
557
+ "the options --all and --ignored are mutually exclusive" . into ( )
558
+ ) ) ,
559
+ ( true , false ) => RunIgnored :: Yes ,
560
+ ( false , true ) => RunIgnored :: Only ,
561
+ ( false , false ) => RunIgnored :: No ,
562
+ } ;
548
563
let quiet = matches. opt_present ( "quiet" ) ;
549
564
let exact = matches. opt_present ( "exact" ) ;
550
565
let list = matches. opt_present ( "list" ) ;
@@ -1315,16 +1330,17 @@ pub fn filter_tests(opts: &TestOpts, tests: Vec<TestDescAndFn>) -> Vec<TestDescA
1315
1330
!opts. skip . iter ( ) . any ( |sf| matches_filter ( test, sf) )
1316
1331
} ) ;
1317
1332
1318
- // Maybe pull out the ignored test and unignore them
1319
- if opts. run_ignored {
1320
- filtered = filtered. into_iter ( )
1321
- . filter ( |test| test. desc . ignore )
1322
- . map ( |mut test| {
1323
- test. desc . ignore = false ;
1324
- test
1325
- } )
1326
- . collect ( ) ;
1327
- } ;
1333
+ // maybe unignore tests
1334
+ match opts. run_ignored {
1335
+ RunIgnored :: Yes => {
1336
+ filtered. iter_mut ( ) . for_each ( |test| test. desc . ignore = false ) ;
1337
+ } ,
1338
+ RunIgnored :: Only => {
1339
+ filtered. retain ( |test| test. desc . ignore ) ;
1340
+ filtered. iter_mut ( ) . for_each ( |test| test. desc . ignore = false ) ;
1341
+ }
1342
+ RunIgnored :: No => { }
1343
+ }
1328
1344
1329
1345
// Sort the tests alphabetically
1330
1346
filtered. sort_by ( |t1, t2| t1. desc . name . as_slice ( ) . cmp ( t2. desc . name . as_slice ( ) ) ) ;
@@ -1713,13 +1729,37 @@ pub mod bench {
1713
1729
1714
1730
#[ cfg( test) ]
1715
1731
mod tests {
1716
- use test:: { filter_tests, parse_opts, run_test, DynTestFn , DynTestName , MetricMap , ShouldPanic ,
1717
- StaticTestName , TestDesc , TestDescAndFn , TestOpts , TrFailed , TrFailedMsg ,
1718
- TrIgnored , TrOk } ;
1732
+ use test:: { filter_tests, parse_opts, run_test, DynTestFn , DynTestName , MetricMap , RunIgnored ,
1733
+ ShouldPanic , StaticTestName , TestDesc , TestDescAndFn , TestOpts , TrFailed ,
1734
+ TrFailedMsg , TrIgnored , TrOk } ;
1719
1735
use std:: sync:: mpsc:: channel;
1720
1736
use bench;
1721
1737
use Bencher ;
1722
1738
1739
+
1740
+ fn one_ignored_one_unignored_test ( ) -> Vec < TestDescAndFn > {
1741
+ vec ! [
1742
+ TestDescAndFn {
1743
+ desc: TestDesc {
1744
+ name: StaticTestName ( "1" ) ,
1745
+ ignore: true ,
1746
+ should_panic: ShouldPanic :: No ,
1747
+ allow_fail: false ,
1748
+ } ,
1749
+ testfn: DynTestFn ( Box :: new( move || { } ) ) ,
1750
+ } ,
1751
+ TestDescAndFn {
1752
+ desc: TestDesc {
1753
+ name: StaticTestName ( "2" ) ,
1754
+ ignore: false ,
1755
+ should_panic: ShouldPanic :: No ,
1756
+ allow_fail: false ,
1757
+ } ,
1758
+ testfn: DynTestFn ( Box :: new( move || { } ) ) ,
1759
+ } ,
1760
+ ]
1761
+ }
1762
+
1723
1763
#[ test]
1724
1764
pub fn do_not_run_ignored_tests ( ) {
1725
1765
fn f ( ) {
@@ -1845,11 +1885,19 @@ mod tests {
1845
1885
"filter" . to_string( ) ,
1846
1886
"--ignored" . to_string( ) ,
1847
1887
] ;
1848
- let opts = match parse_opts ( & args) {
1849
- Some ( Ok ( o) ) => o,
1850
- _ => panic ! ( "Malformed arg in parse_ignored_flag" ) ,
1851
- } ;
1852
- assert ! ( ( opts. run_ignored) ) ;
1888
+ let opts = parse_opts ( & args) . unwrap ( ) . unwrap ( ) ;
1889
+ assert_eq ! ( opts. run_ignored, RunIgnored :: Only ) ;
1890
+ }
1891
+
1892
+ #[ test]
1893
+ fn parse_all_flag ( ) {
1894
+ let args = vec ! [
1895
+ "progname" . to_string( ) ,
1896
+ "filter" . to_string( ) ,
1897
+ "--all" . to_string( ) ,
1898
+ ] ;
1899
+ let opts = parse_opts ( & args) . unwrap ( ) . unwrap ( ) ;
1900
+ assert_eq ! ( opts. run_ignored, RunIgnored :: Yes ) ;
1853
1901
}
1854
1902
1855
1903
#[ test]
@@ -1859,35 +1907,33 @@ mod tests {
1859
1907
1860
1908
let mut opts = TestOpts :: new ( ) ;
1861
1909
opts. run_tests = true ;
1862
- opts. run_ignored = true ;
1910
+ opts. run_ignored = RunIgnored :: Only ;
1863
1911
1864
- let tests = vec ! [
1865
- TestDescAndFn {
1866
- desc: TestDesc {
1867
- name: StaticTestName ( "1" ) ,
1868
- ignore: true ,
1869
- should_panic: ShouldPanic :: No ,
1870
- allow_fail: false ,
1871
- } ,
1872
- testfn: DynTestFn ( Box :: new( move || { } ) ) ,
1873
- } ,
1874
- TestDescAndFn {
1875
- desc: TestDesc {
1876
- name: StaticTestName ( "2" ) ,
1877
- ignore: false ,
1878
- should_panic: ShouldPanic :: No ,
1879
- allow_fail: false ,
1880
- } ,
1881
- testfn: DynTestFn ( Box :: new( move || { } ) ) ,
1882
- } ,
1883
- ] ;
1912
+ let tests = one_ignored_one_unignored_test ( ) ;
1884
1913
let filtered = filter_tests ( & opts, tests) ;
1885
1914
1886
1915
assert_eq ! ( filtered. len( ) , 1 ) ;
1887
1916
assert_eq ! ( filtered[ 0 ] . desc. name. to_string( ) , "1" ) ;
1888
1917
assert ! ( !filtered[ 0 ] . desc. ignore) ;
1889
1918
}
1890
1919
1920
+ #[ test]
1921
+ pub fn run_all_option ( ) {
1922
+ // When we run "--all" tests, the ignore flag should be set to false on
1923
+ // all tests and no test filtered out
1924
+
1925
+ let mut opts = TestOpts :: new ( ) ;
1926
+ opts. run_tests = true ;
1927
+ opts. run_ignored = RunIgnored :: Yes ;
1928
+
1929
+ let tests = one_ignored_one_unignored_test ( ) ;
1930
+ let filtered = filter_tests ( & opts, tests) ;
1931
+
1932
+ assert_eq ! ( filtered. len( ) , 2 ) ;
1933
+ assert ! ( !filtered[ 0 ] . desc. ignore) ;
1934
+ assert ! ( !filtered[ 1 ] . desc. ignore) ;
1935
+ }
1936
+
1891
1937
#[ test]
1892
1938
pub fn exact_filter_match ( ) {
1893
1939
fn tests ( ) -> Vec < TestDescAndFn > {
@@ -1995,7 +2041,9 @@ mod tests {
1995
2041
"test::ignored_tests_result_in_ignored" . to_string( ) ,
1996
2042
"test::first_free_arg_should_be_a_filter" . to_string( ) ,
1997
2043
"test::parse_ignored_flag" . to_string( ) ,
2044
+ "test::parse_all_flag" . to_string( ) ,
1998
2045
"test::filter_for_ignored_option" . to_string( ) ,
2046
+ "test::run_all_option" . to_string( ) ,
1999
2047
"test::sort_tests" . to_string( ) ,
2000
2048
] ;
2001
2049
let tests = {
@@ -2025,7 +2073,9 @@ mod tests {
2025
2073
"test::filter_for_ignored_option" . to_string( ) ,
2026
2074
"test::first_free_arg_should_be_a_filter" . to_string( ) ,
2027
2075
"test::ignored_tests_result_in_ignored" . to_string( ) ,
2076
+ "test::parse_all_flag" . to_string( ) ,
2028
2077
"test::parse_ignored_flag" . to_string( ) ,
2078
+ "test::run_all_option" . to_string( ) ,
2029
2079
"test::sort_tests" . to_string( ) ,
2030
2080
] ;
2031
2081
0 commit comments