20
20
#![ deny( rust_2018_idioms) ]
21
21
#![ crate_name = "test" ]
22
22
#![ unstable( feature = "test" , issue = "27812" ) ]
23
- #![ doc( html_logo_url = "https://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png" ,
24
- html_favicon_url = "https://doc.rust-lang.org/favicon.ico" ,
25
- html_root_url = "https://doc.rust-lang.org/nightly/" , test( attr( deny( warnings) ) ) ) ]
23
+ #![ doc(
24
+ html_logo_url = "https://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png" ,
25
+ html_favicon_url = "https://doc.rust-lang.org/favicon.ico" ,
26
+ html_root_url = "https://doc.rust-lang.org/nightly/" ,
27
+ test( attr( deny( warnings) ) )
28
+ ) ]
26
29
#![ feature( asm) ]
27
30
#![ feature( fnbox) ]
28
31
#![ cfg_attr( any( unix, target_os = "cloudabi" ) , feature( libc, rustc_private) ) ]
@@ -47,52 +50,57 @@ use term;
47
50
#[ cfg( not( all( windows, target_arch = "aarch64" ) ) ) ]
48
51
extern crate panic_unwind;
49
52
50
- pub use self :: TestFn :: * ;
51
53
pub use self :: ColorConfig :: * ;
52
- pub use self :: TestResult :: * ;
53
- pub use self :: TestName :: * ;
54
- use self :: TestEvent :: * ;
55
54
use self :: NamePadding :: * ;
56
55
use self :: OutputLocation :: * ;
56
+ use self :: TestEvent :: * ;
57
+ pub use self :: TestFn :: * ;
58
+ pub use self :: TestName :: * ;
59
+ pub use self :: TestResult :: * ;
57
60
58
- use std:: panic:: { catch_unwind, AssertUnwindSafe } ;
59
61
use std:: any:: Any ;
62
+ use std:: borrow:: Cow ;
60
63
use std:: boxed:: FnBox ;
61
64
use std:: cmp;
62
65
use std:: collections:: BTreeMap ;
63
66
use std:: env;
64
67
use std:: fmt;
65
68
use std:: fs:: File ;
66
- use std:: io:: prelude:: * ;
67
69
use std:: io;
70
+ use std:: io:: prelude:: * ;
71
+ use std:: panic:: { catch_unwind, AssertUnwindSafe } ;
68
72
use std:: path:: PathBuf ;
73
+ use std:: process;
69
74
use std:: process:: Termination ;
70
75
use std:: sync:: mpsc:: { channel, Sender } ;
71
76
use std:: sync:: { Arc , Mutex } ;
72
77
use std:: thread;
73
78
use std:: time:: { Duration , Instant } ;
74
- use std:: borrow:: Cow ;
75
- use std:: process;
76
79
77
80
const TEST_WARN_TIMEOUT_S : u64 = 60 ;
78
81
const QUIET_MODE_MAX_COLUMN : usize = 100 ; // insert a '\n' after 100 tests in quiet mode
79
82
80
83
// to be used by rustc to compile tests in libtest
81
84
pub mod test {
82
- pub use crate :: { assert_test_result, filter_tests, parse_opts, run_test, test_main, test_main_static,
83
- Bencher , DynTestFn , DynTestName , Metric , MetricMap , Options , RunIgnored , ShouldPanic ,
84
- StaticBenchFn , StaticTestFn , StaticTestName , TestDesc , TestDescAndFn , TestName ,
85
- TestOpts , TestResult , TrFailed , TrFailedMsg , TrIgnored , TrOk } ;
85
+ pub use crate :: {
86
+ assert_test_result, filter_tests, parse_opts, run_test, test_main, test_main_static,
87
+ Bencher , DynTestFn , DynTestName , Metric , MetricMap , Options , RunIgnored , ShouldPanic ,
88
+ StaticBenchFn , StaticTestFn , StaticTestName , TestDesc , TestDescAndFn , TestName , TestOpts ,
89
+ TestResult , TrFailed , TrFailedMsg , TrIgnored , TrOk ,
90
+ } ;
86
91
}
87
92
88
- pub mod stats;
89
93
mod formatters;
94
+ pub mod stats;
90
95
91
96
use crate :: formatters:: { JsonFormatter , OutputFormatter , PrettyFormatter , TerseFormatter } ;
92
97
93
98
/// Whether to execute tests concurrently or not
94
99
#[ derive( Copy , Clone , Debug , PartialEq , Eq ) ]
95
- pub enum Concurrent { Yes , No }
100
+ pub enum Concurrent {
101
+ Yes ,
102
+ No ,
103
+ }
96
104
97
105
// The name of a test. By convention this follows the rules for rust
98
106
// paths; i.e., it should be a series of identifiers separated by double
@@ -330,8 +338,7 @@ pub fn test_main_static(tests: &[&TestDescAndFn]) {
330
338
pub fn assert_test_result < T : Termination > ( result : T ) {
331
339
let code = result. report ( ) ;
332
340
assert_eq ! (
333
- code,
334
- 0 ,
341
+ code, 0 ,
335
342
"the test returned a termination value with a non-zero status code ({}) \
336
343
which indicates a failure",
337
344
code
@@ -559,14 +566,16 @@ pub fn parse_opts(args: &[String]) -> Option<OptRes> {
559
566
let include_ignored = matches. opt_present ( "include-ignored" ) ;
560
567
if !allow_unstable && include_ignored {
561
568
return Some ( Err (
562
- "The \" include-ignored\" flag is only accepted on the nightly compiler" . into ( )
569
+ "The \" include-ignored\" flag is only accepted on the nightly compiler" . into ( ) ,
563
570
) ) ;
564
571
}
565
572
566
573
let run_ignored = match ( include_ignored, matches. opt_present ( "ignored" ) ) {
567
- ( true , true ) => return Some ( Err (
568
- "the options --include-ignored and --ignored are mutually exclusive" . into ( )
569
- ) ) ,
574
+ ( true , true ) => {
575
+ return Some ( Err (
576
+ "the options --include-ignored and --ignored are mutually exclusive" . into ( ) ,
577
+ ) ) ;
578
+ }
570
579
( true , false ) => RunIgnored :: Yes ,
571
580
( false , true ) => RunIgnored :: Only ,
572
581
( false , false ) => RunIgnored :: No ,
@@ -598,7 +607,7 @@ pub fn parse_opts(args: &[String]) -> Option<OptRes> {
598
607
"argument for --test-threads must be a number > 0 \
599
608
(error: {})",
600
609
e
601
- ) ) )
610
+ ) ) ) ;
602
611
}
603
612
} ,
604
613
None => None ,
@@ -614,7 +623,7 @@ pub fn parse_opts(args: &[String]) -> Option<OptRes> {
614
623
"argument for --color must be auto, always, or never (was \
615
624
{})",
616
625
v
617
- ) ) )
626
+ ) ) ) ;
618
627
}
619
628
} ;
620
629
@@ -636,7 +645,7 @@ pub fn parse_opts(args: &[String]) -> Option<OptRes> {
636
645
"argument for --format must be pretty, terse, or json (was \
637
646
{})",
638
647
v
639
- ) ) )
648
+ ) ) ) ;
640
649
}
641
650
} ;
642
651
@@ -1013,10 +1022,12 @@ fn use_color(opts: &TestOpts) -> bool {
1013
1022
}
1014
1023
}
1015
1024
1016
- #[ cfg( any( target_os = "cloudabi" ,
1017
- target_os = "redox" ,
1018
- all( target_arch = "wasm32" , not( target_os = "emscripten" ) ) ,
1019
- all( target_vendor = "fortanix" , target_env = "sgx" ) ) ) ]
1025
+ #[ cfg( any(
1026
+ target_os = "cloudabi" ,
1027
+ target_os = "redox" ,
1028
+ all( target_arch = "wasm32" , not( target_os = "emscripten" ) ) ,
1029
+ all( target_vendor = "fortanix" , target_env = "sgx" )
1030
+ ) ) ]
1020
1031
fn stdout_isatty ( ) -> bool {
1021
1032
// FIXME: Implement isatty on Redox and SGX
1022
1033
false
@@ -1247,21 +1258,34 @@ fn get_concurrency() -> usize {
1247
1258
1
1248
1259
}
1249
1260
1250
- #[ cfg( any( all( target_arch = "wasm32" , not( target_os = "emscripten" ) ) ,
1251
- all( target_vendor = "fortanix" , target_env = "sgx" ) ) ) ]
1261
+ #[ cfg( any(
1262
+ all( target_arch = "wasm32" , not( target_os = "emscripten" ) ) ,
1263
+ all( target_vendor = "fortanix" , target_env = "sgx" )
1264
+ ) ) ]
1252
1265
fn num_cpus ( ) -> usize {
1253
1266
1
1254
1267
}
1255
1268
1256
- #[ cfg( any( target_os = "android" , target_os = "cloudabi" , target_os = "emscripten" ,
1257
- target_os = "fuchsia" , target_os = "ios" , target_os = "linux" ,
1258
- target_os = "macos" , target_os = "solaris" ) ) ]
1269
+ #[ cfg( any(
1270
+ target_os = "android" ,
1271
+ target_os = "cloudabi" ,
1272
+ target_os = "emscripten" ,
1273
+ target_os = "fuchsia" ,
1274
+ target_os = "ios" ,
1275
+ target_os = "linux" ,
1276
+ target_os = "macos" ,
1277
+ target_os = "solaris"
1278
+ ) ) ]
1259
1279
fn num_cpus ( ) -> usize {
1260
1280
unsafe { libc:: sysconf ( libc:: _SC_NPROCESSORS_ONLN) as usize }
1261
1281
}
1262
1282
1263
- #[ cfg( any( target_os = "freebsd" , target_os = "dragonfly" , target_os = "bitrig" ,
1264
- target_os = "netbsd" ) ) ]
1283
+ #[ cfg( any(
1284
+ target_os = "freebsd" ,
1285
+ target_os = "dragonfly" ,
1286
+ target_os = "bitrig" ,
1287
+ target_os = "netbsd"
1288
+ ) ) ]
1265
1289
fn num_cpus ( ) -> usize {
1266
1290
use std:: ptr;
1267
1291
@@ -1344,18 +1368,20 @@ pub fn filter_tests(opts: &TestOpts, tests: Vec<TestDescAndFn>) -> Vec<TestDescA
1344
1368
}
1345
1369
1346
1370
// Skip tests that match any of the skip filters
1347
- filtered. retain ( |test| {
1348
- !opts. skip . iter ( ) . any ( |sf| matches_filter ( test, sf) )
1349
- } ) ;
1371
+ filtered. retain ( |test| !opts. skip . iter ( ) . any ( |sf| matches_filter ( test, sf) ) ) ;
1350
1372
1351
1373
// maybe unignore tests
1352
1374
match opts. run_ignored {
1353
1375
RunIgnored :: Yes => {
1354
- filtered. iter_mut ( ) . for_each ( |test| test. desc . ignore = false ) ;
1355
- } ,
1376
+ filtered
1377
+ . iter_mut ( )
1378
+ . for_each ( |test| test. desc . ignore = false ) ;
1379
+ }
1356
1380
RunIgnored :: Only => {
1357
1381
filtered. retain ( |test| test. desc . ignore ) ;
1358
- filtered. iter_mut ( ) . for_each ( |test| test. desc . ignore = false ) ;
1382
+ filtered
1383
+ . iter_mut ( )
1384
+ . for_each ( |test| test. desc . ignore = false ) ;
1359
1385
}
1360
1386
RunIgnored :: No => { }
1361
1387
}
@@ -1397,7 +1423,8 @@ pub fn run_test(
1397
1423
) {
1398
1424
let TestDescAndFn { desc, testfn } = test;
1399
1425
1400
- let ignore_because_panic_abort = cfg ! ( target_arch = "wasm32" ) && !cfg ! ( target_os = "emscripten" )
1426
+ let ignore_because_panic_abort = cfg ! ( target_arch = "wasm32" )
1427
+ && !cfg ! ( target_os = "emscripten" )
1401
1428
&& desc. should_panic != ShouldPanic :: No ;
1402
1429
1403
1430
if force_ignore || desc. ignore || ignore_because_panic_abort {
@@ -1488,7 +1515,8 @@ fn calc_result(desc: &TestDesc, task_result: Result<(), Box<dyn Any + Send>>) ->
1488
1515
match ( & desc. should_panic , task_result) {
1489
1516
( & ShouldPanic :: No , Ok ( ( ) ) ) | ( & ShouldPanic :: Yes , Err ( _) ) => TrOk ,
1490
1517
( & ShouldPanic :: YesWithMessage ( msg) , Err ( ref err) ) => {
1491
- if err. downcast_ref :: < String > ( )
1518
+ if err
1519
+ . downcast_ref :: < String > ( )
1492
1520
. map ( |e| & * * e)
1493
1521
. or_else ( || err. downcast_ref :: < & ' static str > ( ) . map ( |e| * e) )
1494
1522
. map ( |e| e. contains ( msg) )
@@ -1535,7 +1563,8 @@ impl MetricMap {
1535
1563
}
1536
1564
1537
1565
pub fn fmt_metrics ( & self ) -> String {
1538
- let v = self . 0
1566
+ let v = self
1567
+ . 0
1539
1568
. iter ( )
1540
1569
. map ( |( k, v) | format ! ( "{}: {} (+/- {})" , * k, v. value, v. noise) )
1541
1570
. collect :: < Vec < _ > > ( ) ;
@@ -1644,7 +1673,8 @@ where
1644
1673
1645
1674
// If we've run for 100ms and seem to have converged to a
1646
1675
// stable median.
1647
- if loop_run > Duration :: from_millis ( 100 ) && summ. median_abs_dev_pct < 1.0
1676
+ if loop_run > Duration :: from_millis ( 100 )
1677
+ && summ. median_abs_dev_pct < 1.0
1648
1678
&& summ. median - summ5. median < summ5. median_abs_dev
1649
1679
{
1650
1680
return summ5;
@@ -1670,12 +1700,12 @@ where
1670
1700
}
1671
1701
1672
1702
pub mod bench {
1673
- use std:: panic:: { catch_unwind, AssertUnwindSafe } ;
1703
+ use super :: { BenchMode , BenchSamples , Bencher , MonitorMsg , Sender , Sink , TestDesc , TestResult } ;
1704
+ use crate :: stats;
1674
1705
use std:: cmp;
1675
1706
use std:: io;
1707
+ use std:: panic:: { catch_unwind, AssertUnwindSafe } ;
1676
1708
use std:: sync:: { Arc , Mutex } ;
1677
- use crate :: stats;
1678
- use super :: { BenchMode , BenchSamples , Bencher , MonitorMsg , Sender , Sink , TestDesc , TestResult } ;
1679
1709
1680
1710
pub fn benchmark < F > ( desc : TestDesc , monitor_ch : Sender < MonitorMsg > , nocapture : bool , f : F )
1681
1711
where
@@ -1750,14 +1780,15 @@ pub mod bench {
1750
1780
1751
1781
#[ cfg( test) ]
1752
1782
mod tests {
1753
- use crate :: test:: { filter_tests, parse_opts, run_test, DynTestFn , DynTestName , MetricMap , RunIgnored ,
1754
- ShouldPanic , StaticTestName , TestDesc , TestDescAndFn , TestOpts , TrFailed ,
1755
- TrFailedMsg , TrIgnored , TrOk } ;
1756
- use std:: sync:: mpsc:: channel;
1757
1783
use crate :: bench;
1784
+ use crate :: test:: {
1785
+ filter_tests, parse_opts, run_test, DynTestFn , DynTestName , MetricMap , RunIgnored ,
1786
+ ShouldPanic , StaticTestName , TestDesc , TestDescAndFn , TestOpts , TrFailed , TrFailedMsg ,
1787
+ TrIgnored , TrOk ,
1788
+ } ;
1758
1789
use crate :: Bencher ;
1759
1790
use crate :: Concurrent ;
1760
-
1791
+ use std :: sync :: mpsc :: channel ;
1761
1792
1762
1793
fn one_ignored_one_unignored_test ( ) -> Vec < TestDescAndFn > {
1763
1794
vec ! [
0 commit comments