@@ -89,7 +89,7 @@ const QUIET_MODE_MAX_COLUMN: usize = 100; // insert a '\n' after 100 tests in qu
89
89
// to be used by rustc to compile tests in libtest
90
90
pub mod test {
91
91
pub use { assert_test_result, filter_tests, parse_opts, run_test, test_main, test_main_static,
92
- Bencher , DynTestFn , DynTestName , Metric , MetricMap , Options , ShouldPanic ,
92
+ Bencher , DynTestFn , DynTestName , Metric , MetricMap , Options , RunIgnored , ShouldPanic ,
93
93
StaticBenchFn , StaticTestFn , StaticTestName , TestDesc , TestDescAndFn , TestName ,
94
94
TestOpts , TestResult , TrFailed , TrFailedMsg , TrIgnored , TrOk } ;
95
95
}
@@ -357,12 +357,19 @@ pub enum OutputFormat {
357
357
Json ,
358
358
}
359
359
360
+ #[ derive( Copy , Clone , Debug , PartialEq , Eq ) ]
361
+ pub enum RunIgnored {
362
+ Yes ,
363
+ No ,
364
+ Only ,
365
+ }
366
+
360
367
#[ derive( Debug ) ]
361
368
pub struct TestOpts {
362
369
pub list : bool ,
363
370
pub filter : Option < String > ,
364
371
pub filter_exact : bool ,
365
- pub run_ignored : bool ,
372
+ pub run_ignored : RunIgnored ,
366
373
pub run_tests : bool ,
367
374
pub bench_benchmarks : bool ,
368
375
pub logfile : Option < PathBuf > ,
@@ -381,7 +388,7 @@ impl TestOpts {
381
388
list : false ,
382
389
filter : None ,
383
390
filter_exact : false ,
384
- run_ignored : false ,
391
+ run_ignored : RunIgnored :: No ,
385
392
run_tests : false ,
386
393
bench_benchmarks : false ,
387
394
logfile : None ,
@@ -400,7 +407,8 @@ pub type OptRes = Result<TestOpts, String>;
400
407
401
408
fn optgroups ( ) -> getopts:: Options {
402
409
let mut opts = getopts:: Options :: new ( ) ;
403
- opts. optflag ( "" , "ignored" , "Run ignored tests" )
410
+ opts. optflag ( "" , "include-ignored" , "Run ignored and not ignored tests" )
411
+ . optflag ( "" , "ignored" , "Run only ignored tests" )
404
412
. optflag ( "" , "test" , "Run tests and not benchmarks" )
405
413
. optflag ( "" , "bench" , "Run benchmarks instead of tests" )
406
414
. optflag ( "" , "list" , "List all tests and benchmarks" )
@@ -499,8 +507,8 @@ Test Attributes:
499
507
contain: #[should_panic(expected = "foo")].
500
508
#[ignore] - When applied to a function which is already attributed as a
501
509
test, then the test runner will ignore these tests during
502
- normal test runs. Running with --ignored will run these
503
- tests."# ,
510
+ normal test runs. Running with --ignored or --include-ignored will run
511
+ these tests."# ,
504
512
usage = options. usage( & message)
505
513
) ;
506
514
}
@@ -553,7 +561,21 @@ pub fn parse_opts(args: &[String]) -> Option<OptRes> {
553
561
None
554
562
} ;
555
563
556
- let run_ignored = matches. opt_present ( "ignored" ) ;
564
+ let include_ignored = matches. opt_present ( "include-ignored" ) ;
565
+ if !allow_unstable && include_ignored {
566
+ return Some ( Err (
567
+ "The \" include-ignored\" flag is only accepted on the nightly compiler" . into ( )
568
+ ) ) ;
569
+ }
570
+
571
+ let run_ignored = match ( include_ignored, matches. opt_present ( "ignored" ) ) {
572
+ ( true , true ) => return Some ( Err (
573
+ "the options --include-ignored and --ignored are mutually exclusive" . into ( )
574
+ ) ) ,
575
+ ( true , false ) => RunIgnored :: Yes ,
576
+ ( false , true ) => RunIgnored :: Only ,
577
+ ( false , false ) => RunIgnored :: No ,
578
+ } ;
557
579
let quiet = matches. opt_present ( "quiet" ) ;
558
580
let exact = matches. opt_present ( "exact" ) ;
559
581
let list = matches. opt_present ( "list" ) ;
@@ -1324,16 +1346,17 @@ pub fn filter_tests(opts: &TestOpts, tests: Vec<TestDescAndFn>) -> Vec<TestDescA
1324
1346
!opts. skip . iter ( ) . any ( |sf| matches_filter ( test, sf) )
1325
1347
} ) ;
1326
1348
1327
- // Maybe pull out the ignored test and unignore them
1328
- if opts. run_ignored {
1329
- filtered = filtered. into_iter ( )
1330
- . filter ( |test| test. desc . ignore )
1331
- . map ( |mut test| {
1332
- test. desc . ignore = false ;
1333
- test
1334
- } )
1335
- . collect ( ) ;
1336
- } ;
1349
+ // maybe unignore tests
1350
+ match opts. run_ignored {
1351
+ RunIgnored :: Yes => {
1352
+ filtered. iter_mut ( ) . for_each ( |test| test. desc . ignore = false ) ;
1353
+ } ,
1354
+ RunIgnored :: Only => {
1355
+ filtered. retain ( |test| test. desc . ignore ) ;
1356
+ filtered. iter_mut ( ) . for_each ( |test| test. desc . ignore = false ) ;
1357
+ }
1358
+ RunIgnored :: No => { }
1359
+ }
1337
1360
1338
1361
// Sort the tests alphabetically
1339
1362
filtered. sort_by ( |t1, t2| t1. desc . name . as_slice ( ) . cmp ( t2. desc . name . as_slice ( ) ) ) ;
@@ -1722,13 +1745,37 @@ pub mod bench {
1722
1745
1723
1746
#[ cfg( test) ]
1724
1747
mod tests {
1725
- use test:: { filter_tests, parse_opts, run_test, DynTestFn , DynTestName , MetricMap , ShouldPanic ,
1726
- StaticTestName , TestDesc , TestDescAndFn , TestOpts , TrFailed , TrFailedMsg ,
1727
- TrIgnored , TrOk } ;
1748
+ use test:: { filter_tests, parse_opts, run_test, DynTestFn , DynTestName , MetricMap , RunIgnored ,
1749
+ ShouldPanic , StaticTestName , TestDesc , TestDescAndFn , TestOpts , TrFailed ,
1750
+ TrFailedMsg , TrIgnored , TrOk } ;
1728
1751
use std:: sync:: mpsc:: channel;
1729
1752
use bench;
1730
1753
use Bencher ;
1731
1754
1755
+
1756
+ fn one_ignored_one_unignored_test ( ) -> Vec < TestDescAndFn > {
1757
+ vec ! [
1758
+ TestDescAndFn {
1759
+ desc: TestDesc {
1760
+ name: StaticTestName ( "1" ) ,
1761
+ ignore: true ,
1762
+ should_panic: ShouldPanic :: No ,
1763
+ allow_fail: false ,
1764
+ } ,
1765
+ testfn: DynTestFn ( Box :: new( move || { } ) ) ,
1766
+ } ,
1767
+ TestDescAndFn {
1768
+ desc: TestDesc {
1769
+ name: StaticTestName ( "2" ) ,
1770
+ ignore: false ,
1771
+ should_panic: ShouldPanic :: No ,
1772
+ allow_fail: false ,
1773
+ } ,
1774
+ testfn: DynTestFn ( Box :: new( move || { } ) ) ,
1775
+ } ,
1776
+ ]
1777
+ }
1778
+
1732
1779
#[ test]
1733
1780
pub fn do_not_run_ignored_tests ( ) {
1734
1781
fn f ( ) {
@@ -1854,11 +1901,20 @@ mod tests {
1854
1901
"filter" . to_string( ) ,
1855
1902
"--ignored" . to_string( ) ,
1856
1903
] ;
1857
- let opts = match parse_opts ( & args) {
1858
- Some ( Ok ( o) ) => o,
1859
- _ => panic ! ( "Malformed arg in parse_ignored_flag" ) ,
1860
- } ;
1861
- assert ! ( ( opts. run_ignored) ) ;
1904
+ let opts = parse_opts ( & args) . unwrap ( ) . unwrap ( ) ;
1905
+ assert_eq ! ( opts. run_ignored, RunIgnored :: Only ) ;
1906
+ }
1907
+
1908
+ #[ test]
1909
+ fn parse_include_ignored_flag ( ) {
1910
+ let args = vec ! [
1911
+ "progname" . to_string( ) ,
1912
+ "filter" . to_string( ) ,
1913
+ "-Zunstable-options" . to_string( ) ,
1914
+ "--include-ignored" . to_string( ) ,
1915
+ ] ;
1916
+ let opts = parse_opts ( & args) . unwrap ( ) . unwrap ( ) ;
1917
+ assert_eq ! ( opts. run_ignored, RunIgnored :: Yes ) ;
1862
1918
}
1863
1919
1864
1920
#[ test]
@@ -1868,35 +1924,33 @@ mod tests {
1868
1924
1869
1925
let mut opts = TestOpts :: new ( ) ;
1870
1926
opts. run_tests = true ;
1871
- opts. run_ignored = true ;
1927
+ opts. run_ignored = RunIgnored :: Only ;
1872
1928
1873
- let tests = vec ! [
1874
- TestDescAndFn {
1875
- desc: TestDesc {
1876
- name: StaticTestName ( "1" ) ,
1877
- ignore: true ,
1878
- should_panic: ShouldPanic :: No ,
1879
- allow_fail: false ,
1880
- } ,
1881
- testfn: DynTestFn ( Box :: new( move || { } ) ) ,
1882
- } ,
1883
- TestDescAndFn {
1884
- desc: TestDesc {
1885
- name: StaticTestName ( "2" ) ,
1886
- ignore: false ,
1887
- should_panic: ShouldPanic :: No ,
1888
- allow_fail: false ,
1889
- } ,
1890
- testfn: DynTestFn ( Box :: new( move || { } ) ) ,
1891
- } ,
1892
- ] ;
1929
+ let tests = one_ignored_one_unignored_test ( ) ;
1893
1930
let filtered = filter_tests ( & opts, tests) ;
1894
1931
1895
1932
assert_eq ! ( filtered. len( ) , 1 ) ;
1896
1933
assert_eq ! ( filtered[ 0 ] . desc. name. to_string( ) , "1" ) ;
1897
1934
assert ! ( !filtered[ 0 ] . desc. ignore) ;
1898
1935
}
1899
1936
1937
+ #[ test]
1938
+ pub fn run_include_ignored_option ( ) {
1939
+ // When we "--include-ignored" tests, the ignore flag should be set to false on
1940
+ // all tests and no test filtered out
1941
+
1942
+ let mut opts = TestOpts :: new ( ) ;
1943
+ opts. run_tests = true ;
1944
+ opts. run_ignored = RunIgnored :: Yes ;
1945
+
1946
+ let tests = one_ignored_one_unignored_test ( ) ;
1947
+ let filtered = filter_tests ( & opts, tests) ;
1948
+
1949
+ assert_eq ! ( filtered. len( ) , 2 ) ;
1950
+ assert ! ( !filtered[ 0 ] . desc. ignore) ;
1951
+ assert ! ( !filtered[ 1 ] . desc. ignore) ;
1952
+ }
1953
+
1900
1954
#[ test]
1901
1955
pub fn exact_filter_match ( ) {
1902
1956
fn tests ( ) -> Vec < TestDescAndFn > {
@@ -2004,7 +2058,9 @@ mod tests {
2004
2058
"test::ignored_tests_result_in_ignored" . to_string( ) ,
2005
2059
"test::first_free_arg_should_be_a_filter" . to_string( ) ,
2006
2060
"test::parse_ignored_flag" . to_string( ) ,
2061
+ "test::parse_include_ignored_flag" . to_string( ) ,
2007
2062
"test::filter_for_ignored_option" . to_string( ) ,
2063
+ "test::run_include_ignored_option" . to_string( ) ,
2008
2064
"test::sort_tests" . to_string( ) ,
2009
2065
] ;
2010
2066
let tests = {
@@ -2035,6 +2091,8 @@ mod tests {
2035
2091
"test::first_free_arg_should_be_a_filter" . to_string( ) ,
2036
2092
"test::ignored_tests_result_in_ignored" . to_string( ) ,
2037
2093
"test::parse_ignored_flag" . to_string( ) ,
2094
+ "test::parse_include_ignored_flag" . to_string( ) ,
2095
+ "test::run_include_ignored_option" . to_string( ) ,
2038
2096
"test::sort_tests" . to_string( ) ,
2039
2097
] ;
2040
2098
0 commit comments