@@ -81,7 +81,7 @@ const QUIET_MODE_MAX_COLUMN: usize = 100; // insert a '\n' after 100 tests in qu
81
81
// to be used by rustc to compile tests in libtest
82
82
pub mod test {
83
83
pub use { assert_test_result, filter_tests, parse_opts, run_test, test_main, test_main_static,
84
- Bencher , DynTestFn , DynTestName , Metric , MetricMap , Options , RunIgnored , ShouldPanic ,
84
+ Bencher , DynTestFn , DynTestName , Metric , MetricMap , Options , ShouldPanic ,
85
85
StaticBenchFn , StaticTestFn , StaticTestName , TestDesc , TestDescAndFn , TestName ,
86
86
TestOpts , TestResult , TrFailed , TrFailedMsg , TrIgnored , TrOk } ;
87
87
}
@@ -349,19 +349,12 @@ pub enum OutputFormat {
349
349
Json ,
350
350
}
351
351
352
- #[ derive( Copy , Clone , Debug , PartialEq , Eq ) ]
353
- pub enum RunIgnored {
354
- Yes ,
355
- No ,
356
- Only ,
357
- }
358
-
359
352
#[ derive( Debug ) ]
360
353
pub struct TestOpts {
361
354
pub list : bool ,
362
355
pub filter : Option < String > ,
363
356
pub filter_exact : bool ,
364
- pub run_ignored : RunIgnored ,
357
+ pub run_ignored : bool ,
365
358
pub run_tests : bool ,
366
359
pub bench_benchmarks : bool ,
367
360
pub logfile : Option < PathBuf > ,
@@ -380,7 +373,7 @@ impl TestOpts {
380
373
list : false ,
381
374
filter : None ,
382
375
filter_exact : false ,
383
- run_ignored : RunIgnored :: No ,
376
+ run_ignored : false ,
384
377
run_tests : false ,
385
378
bench_benchmarks : false ,
386
379
logfile : None ,
@@ -399,8 +392,7 @@ pub type OptRes = Result<TestOpts, String>;
399
392
400
393
fn optgroups ( ) -> getopts:: Options {
401
394
let mut opts = getopts:: Options :: new ( ) ;
402
- opts. optflag ( "" , "include-ignored" , "Run ignored and not ignored tests" )
403
- . optflag ( "" , "ignored" , "Run only ignored tests" )
395
+ opts. optflag ( "" , "ignored" , "Run ignored tests" )
404
396
. optflag ( "" , "test" , "Run tests and not benchmarks" )
405
397
. optflag ( "" , "bench" , "Run benchmarks instead of tests" )
406
398
. optflag ( "" , "list" , "List all tests and benchmarks" )
@@ -499,8 +491,8 @@ Test Attributes:
499
491
contain: #[should_panic(expected = "foo")].
500
492
#[ignore] - When applied to a function which is already attributed as a
501
493
test, then the test runner will ignore these tests during
502
- normal test runs. Running with --ignored or --include-ignored will run
503
- these tests."# ,
494
+ normal test runs. Running with --ignored will run these
495
+ tests."# ,
504
496
usage = options. usage( & message)
505
497
) ;
506
498
}
@@ -553,21 +545,7 @@ pub fn parse_opts(args: &[String]) -> Option<OptRes> {
553
545
None
554
546
} ;
555
547
556
- let include_ignored = matches. opt_present ( "include-ignored" ) ;
557
- if !allow_unstable && include_ignored {
558
- return Some ( Err (
559
- "The \" include-ignored\" flag is only accepted on the nightly compiler" . into ( )
560
- ) ) ;
561
- }
562
-
563
- let run_ignored = match ( include_ignored, matches. opt_present ( "ignored" ) ) {
564
- ( true , true ) => return Some ( Err (
565
- "the options --include-ignored and --ignored are mutually exclusive" . into ( )
566
- ) ) ,
567
- ( true , false ) => RunIgnored :: Yes ,
568
- ( false , true ) => RunIgnored :: Only ,
569
- ( false , false ) => RunIgnored :: No ,
570
- } ;
548
+ let run_ignored = matches. opt_present ( "ignored" ) ;
571
549
let quiet = matches. opt_present ( "quiet" ) ;
572
550
let exact = matches. opt_present ( "exact" ) ;
573
551
let list = matches. opt_present ( "list" ) ;
@@ -1319,36 +1297,55 @@ fn get_concurrency() -> usize {
1319
1297
1320
1298
pub fn filter_tests ( opts : & TestOpts , tests : Vec < TestDescAndFn > ) -> Vec < TestDescAndFn > {
1321
1299
let mut filtered = tests;
1322
- let matches_filter = |test : & TestDescAndFn , filter : & str | {
1323
- let test_name = test. desc . name . as_slice ( ) ;
1324
-
1325
- match opts. filter_exact {
1326
- true => test_name == filter,
1327
- false => test_name. contains ( filter) ,
1328
- }
1329
- } ;
1330
-
1331
1300
// Remove tests that don't match the test filter
1332
- if let Some ( ref filter) = opts. filter {
1333
- filtered. retain ( |test| matches_filter ( test, filter) ) ;
1334
- }
1301
+ filtered = match opts. filter {
1302
+ None => filtered,
1303
+ Some ( ref filter) => filtered
1304
+ . into_iter ( )
1305
+ . filter ( |test| {
1306
+ if opts. filter_exact {
1307
+ test. desc . name . as_slice ( ) == & filter[ ..]
1308
+ } else {
1309
+ test. desc . name . as_slice ( ) . contains ( & filter[ ..] )
1310
+ }
1311
+ } )
1312
+ . collect ( ) ,
1313
+ } ;
1335
1314
1336
1315
// Skip tests that match any of the skip filters
1337
- filtered. retain ( |test| {
1338
- !opts. skip . iter ( ) . any ( |sf| matches_filter ( test, sf) )
1339
- } ) ;
1340
-
1341
- // maybe unignore tests
1342
- match opts. run_ignored {
1343
- RunIgnored :: Yes => {
1344
- filtered. iter_mut ( ) . for_each ( |test| test. desc . ignore = false ) ;
1345
- } ,
1346
- RunIgnored :: Only => {
1347
- filtered. retain ( |test| test. desc . ignore ) ;
1348
- filtered. iter_mut ( ) . for_each ( |test| test. desc . ignore = false ) ;
1316
+ filtered = filtered
1317
+ . into_iter ( )
1318
+ . filter ( |t| {
1319
+ !opts. skip . iter ( ) . any ( |sf| {
1320
+ if opts. filter_exact {
1321
+ t. desc . name . as_slice ( ) == & sf[ ..]
1322
+ } else {
1323
+ t. desc . name . as_slice ( ) . contains ( & sf[ ..] )
1324
+ }
1325
+ } )
1326
+ } )
1327
+ . collect ( ) ;
1328
+
1329
+ // Maybe pull out the ignored test and unignore them
1330
+ filtered = if !opts. run_ignored {
1331
+ filtered
1332
+ } else {
1333
+ fn filter ( test : TestDescAndFn ) -> Option < TestDescAndFn > {
1334
+ if test. desc . ignore {
1335
+ let TestDescAndFn { desc, testfn } = test;
1336
+ Some ( TestDescAndFn {
1337
+ desc : TestDesc {
1338
+ ignore : false ,
1339
+ ..desc
1340
+ } ,
1341
+ testfn,
1342
+ } )
1343
+ } else {
1344
+ None
1345
+ }
1349
1346
}
1350
- RunIgnored :: No => { }
1351
- }
1347
+ filtered . into_iter ( ) . filter_map ( filter ) . collect ( )
1348
+ } ;
1352
1349
1353
1350
// Sort the tests alphabetically
1354
1351
filtered. sort_by ( |t1, t2| t1. desc . name . as_slice ( ) . cmp ( t2. desc . name . as_slice ( ) ) ) ;
@@ -1737,37 +1734,13 @@ pub mod bench {
1737
1734
1738
1735
#[ cfg( test) ]
1739
1736
mod tests {
1740
- use test:: { filter_tests, parse_opts, run_test, DynTestFn , DynTestName , MetricMap , RunIgnored ,
1741
- ShouldPanic , StaticTestName , TestDesc , TestDescAndFn , TestOpts , TrFailed ,
1742
- TrFailedMsg , TrIgnored , TrOk } ;
1737
+ use test:: { filter_tests, parse_opts, run_test, DynTestFn , DynTestName , MetricMap , ShouldPanic ,
1738
+ StaticTestName , TestDesc , TestDescAndFn , TestOpts , TrFailed , TrFailedMsg ,
1739
+ TrIgnored , TrOk } ;
1743
1740
use std:: sync:: mpsc:: channel;
1744
1741
use bench;
1745
1742
use Bencher ;
1746
1743
1747
-
1748
- fn one_ignored_one_unignored_test ( ) -> Vec < TestDescAndFn > {
1749
- vec ! [
1750
- TestDescAndFn {
1751
- desc: TestDesc {
1752
- name: StaticTestName ( "1" ) ,
1753
- ignore: true ,
1754
- should_panic: ShouldPanic :: No ,
1755
- allow_fail: false ,
1756
- } ,
1757
- testfn: DynTestFn ( Box :: new( move || { } ) ) ,
1758
- } ,
1759
- TestDescAndFn {
1760
- desc: TestDesc {
1761
- name: StaticTestName ( "2" ) ,
1762
- ignore: false ,
1763
- should_panic: ShouldPanic :: No ,
1764
- allow_fail: false ,
1765
- } ,
1766
- testfn: DynTestFn ( Box :: new( move || { } ) ) ,
1767
- } ,
1768
- ]
1769
- }
1770
-
1771
1744
#[ test]
1772
1745
pub fn do_not_run_ignored_tests ( ) {
1773
1746
fn f ( ) {
@@ -1893,20 +1866,11 @@ mod tests {
1893
1866
"filter" . to_string( ) ,
1894
1867
"--ignored" . to_string( ) ,
1895
1868
] ;
1896
- let opts = parse_opts ( & args) . unwrap ( ) . unwrap ( ) ;
1897
- assert_eq ! ( opts. run_ignored, RunIgnored :: Only ) ;
1898
- }
1899
-
1900
- #[ test]
1901
- fn parse_include_ignored_flag ( ) {
1902
- let args = vec ! [
1903
- "progname" . to_string( ) ,
1904
- "filter" . to_string( ) ,
1905
- "-Zunstable-options" . to_string( ) ,
1906
- "--include-ignored" . to_string( ) ,
1907
- ] ;
1908
- let opts = parse_opts ( & args) . unwrap ( ) . unwrap ( ) ;
1909
- assert_eq ! ( opts. run_ignored, RunIgnored :: Yes ) ;
1869
+ let opts = match parse_opts ( & args) {
1870
+ Some ( Ok ( o) ) => o,
1871
+ _ => panic ! ( "Malformed arg in parse_ignored_flag" ) ,
1872
+ } ;
1873
+ assert ! ( ( opts. run_ignored) ) ;
1910
1874
}
1911
1875
1912
1876
#[ test]
@@ -1916,33 +1880,35 @@ mod tests {
1916
1880
1917
1881
let mut opts = TestOpts :: new ( ) ;
1918
1882
opts. run_tests = true ;
1919
- opts. run_ignored = RunIgnored :: Only ;
1883
+ opts. run_ignored = true ;
1920
1884
1921
- let tests = one_ignored_one_unignored_test ( ) ;
1885
+ let tests = vec ! [
1886
+ TestDescAndFn {
1887
+ desc: TestDesc {
1888
+ name: StaticTestName ( "1" ) ,
1889
+ ignore: true ,
1890
+ should_panic: ShouldPanic :: No ,
1891
+ allow_fail: false ,
1892
+ } ,
1893
+ testfn: DynTestFn ( Box :: new( move || { } ) ) ,
1894
+ } ,
1895
+ TestDescAndFn {
1896
+ desc: TestDesc {
1897
+ name: StaticTestName ( "2" ) ,
1898
+ ignore: false ,
1899
+ should_panic: ShouldPanic :: No ,
1900
+ allow_fail: false ,
1901
+ } ,
1902
+ testfn: DynTestFn ( Box :: new( move || { } ) ) ,
1903
+ } ,
1904
+ ] ;
1922
1905
let filtered = filter_tests ( & opts, tests) ;
1923
1906
1924
1907
assert_eq ! ( filtered. len( ) , 1 ) ;
1925
1908
assert_eq ! ( filtered[ 0 ] . desc. name. to_string( ) , "1" ) ;
1926
1909
assert ! ( !filtered[ 0 ] . desc. ignore) ;
1927
1910
}
1928
1911
1929
- #[ test]
1930
- pub fn run_include_ignored_option ( ) {
1931
- // When we "--include-ignored" tests, the ignore flag should be set to false on
1932
- // all tests and no test filtered out
1933
-
1934
- let mut opts = TestOpts :: new ( ) ;
1935
- opts. run_tests = true ;
1936
- opts. run_ignored = RunIgnored :: Yes ;
1937
-
1938
- let tests = one_ignored_one_unignored_test ( ) ;
1939
- let filtered = filter_tests ( & opts, tests) ;
1940
-
1941
- assert_eq ! ( filtered. len( ) , 2 ) ;
1942
- assert ! ( !filtered[ 0 ] . desc. ignore) ;
1943
- assert ! ( !filtered[ 1 ] . desc. ignore) ;
1944
- }
1945
-
1946
1912
#[ test]
1947
1913
pub fn exact_filter_match ( ) {
1948
1914
fn tests ( ) -> Vec < TestDescAndFn > {
@@ -2050,9 +2016,7 @@ mod tests {
2050
2016
"test::ignored_tests_result_in_ignored" . to_string( ) ,
2051
2017
"test::first_free_arg_should_be_a_filter" . to_string( ) ,
2052
2018
"test::parse_ignored_flag" . to_string( ) ,
2053
- "test::parse_include_ignored_flag" . to_string( ) ,
2054
2019
"test::filter_for_ignored_option" . to_string( ) ,
2055
- "test::run_include_ignored_option" . to_string( ) ,
2056
2020
"test::sort_tests" . to_string( ) ,
2057
2021
] ;
2058
2022
let tests = {
@@ -2083,8 +2047,6 @@ mod tests {
2083
2047
"test::first_free_arg_should_be_a_filter" . to_string( ) ,
2084
2048
"test::ignored_tests_result_in_ignored" . to_string( ) ,
2085
2049
"test::parse_ignored_flag" . to_string( ) ,
2086
- "test::parse_include_ignored_flag" . to_string( ) ,
2087
- "test::run_include_ignored_option" . to_string( ) ,
2088
2050
"test::sort_tests" . to_string( ) ,
2089
2051
] ;
2090
2052
0 commit comments