2020#![ deny( rust_2018_idioms) ]
2121#![ crate_name = "test" ]
2222#![ 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+ ) ]
2629#![ feature( asm) ]
2730#![ feature( fnbox) ]
2831#![ cfg_attr( any( unix, target_os = "cloudabi" ) , feature( libc, rustc_private) ) ]
@@ -47,52 +50,57 @@ use term;
4750#[ cfg( not( all( windows, target_arch = "aarch64" ) ) ) ]
4851extern crate panic_unwind;
4952
50- pub use self :: TestFn :: * ;
5153pub use self :: ColorConfig :: * ;
52- pub use self :: TestResult :: * ;
53- pub use self :: TestName :: * ;
54- use self :: TestEvent :: * ;
5554use self :: NamePadding :: * ;
5655use self :: OutputLocation :: * ;
56+ use self :: TestEvent :: * ;
57+ pub use self :: TestFn :: * ;
58+ pub use self :: TestName :: * ;
59+ pub use self :: TestResult :: * ;
5760
58- use std:: panic:: { catch_unwind, AssertUnwindSafe } ;
5961use std:: any:: Any ;
62+ use std:: borrow:: Cow ;
6063use std:: boxed:: FnBox ;
6164use std:: cmp;
6265use std:: collections:: BTreeMap ;
6366use std:: env;
6467use std:: fmt;
6568use std:: fs:: File ;
66- use std:: io:: prelude:: * ;
6769use std:: io;
70+ use std:: io:: prelude:: * ;
71+ use std:: panic:: { catch_unwind, AssertUnwindSafe } ;
6872use std:: path:: PathBuf ;
73+ use std:: process;
6974use std:: process:: Termination ;
7075use std:: sync:: mpsc:: { channel, Sender } ;
7176use std:: sync:: { Arc , Mutex } ;
7277use std:: thread;
7378use std:: time:: { Duration , Instant } ;
74- use std:: borrow:: Cow ;
75- use std:: process;
7679
7780const TEST_WARN_TIMEOUT_S : u64 = 60 ;
7881const QUIET_MODE_MAX_COLUMN : usize = 100 ; // insert a '\n' after 100 tests in quiet mode
7982
8083// to be used by rustc to compile tests in libtest
8184pub 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+ } ;
8691}
8792
88- pub mod stats;
8993mod formatters;
94+ pub mod stats;
9095
9196use crate :: formatters:: { JsonFormatter , OutputFormatter , PrettyFormatter , TerseFormatter } ;
9297
9398/// Whether to execute tests concurrently or not
9499#[ derive( Copy , Clone , Debug , PartialEq , Eq ) ]
95- pub enum Concurrent { Yes , No }
100+ pub enum Concurrent {
101+ Yes ,
102+ No ,
103+ }
96104
97105// The name of a test. By convention this follows the rules for rust
98106// paths; i.e., it should be a series of identifiers separated by double
@@ -330,8 +338,7 @@ pub fn test_main_static(tests: &[&TestDescAndFn]) {
330338pub fn assert_test_result < T : Termination > ( result : T ) {
331339 let code = result. report ( ) ;
332340 assert_eq ! (
333- code,
334- 0 ,
341+ code, 0 ,
335342 "the test returned a termination value with a non-zero status code ({}) \
336343 which indicates a failure",
337344 code
@@ -559,14 +566,16 @@ pub fn parse_opts(args: &[String]) -> Option<OptRes> {
559566 let include_ignored = matches. opt_present ( "include-ignored" ) ;
560567 if !allow_unstable && include_ignored {
561568 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 ( ) ,
563570 ) ) ;
564571 }
565572
566573 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+ }
570579 ( true , false ) => RunIgnored :: Yes ,
571580 ( false , true ) => RunIgnored :: Only ,
572581 ( false , false ) => RunIgnored :: No ,
@@ -598,7 +607,7 @@ pub fn parse_opts(args: &[String]) -> Option<OptRes> {
598607 "argument for --test-threads must be a number > 0 \
599608 (error: {})",
600609 e
601- ) ) )
610+ ) ) ) ;
602611 }
603612 } ,
604613 None => None ,
@@ -614,7 +623,7 @@ pub fn parse_opts(args: &[String]) -> Option<OptRes> {
614623 "argument for --color must be auto, always, or never (was \
615624 {})",
616625 v
617- ) ) )
626+ ) ) ) ;
618627 }
619628 } ;
620629
@@ -636,7 +645,7 @@ pub fn parse_opts(args: &[String]) -> Option<OptRes> {
636645 "argument for --format must be pretty, terse, or json (was \
637646 {})",
638647 v
639- ) ) )
648+ ) ) ) ;
640649 }
641650 } ;
642651
@@ -1013,10 +1022,12 @@ fn use_color(opts: &TestOpts) -> bool {
10131022 }
10141023}
10151024
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+ ) ) ]
10201031fn stdout_isatty ( ) -> bool {
10211032 // FIXME: Implement isatty on Redox and SGX
10221033 false
@@ -1247,21 +1258,34 @@ fn get_concurrency() -> usize {
12471258 1
12481259 }
12491260
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+ ) ) ]
12521265 fn num_cpus ( ) -> usize {
12531266 1
12541267 }
12551268
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+ ) ) ]
12591279 fn num_cpus ( ) -> usize {
12601280 unsafe { libc:: sysconf ( libc:: _SC_NPROCESSORS_ONLN) as usize }
12611281 }
12621282
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+ ) ) ]
12651289 fn num_cpus ( ) -> usize {
12661290 use std:: ptr;
12671291
@@ -1344,18 +1368,20 @@ pub fn filter_tests(opts: &TestOpts, tests: Vec<TestDescAndFn>) -> Vec<TestDescA
13441368 }
13451369
13461370 // 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) ) ) ;
13501372
13511373 // maybe unignore tests
13521374 match opts. run_ignored {
13531375 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+ }
13561380 RunIgnored :: Only => {
13571381 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 ) ;
13591385 }
13601386 RunIgnored :: No => { }
13611387 }
@@ -1397,7 +1423,8 @@ pub fn run_test(
13971423) {
13981424 let TestDescAndFn { desc, testfn } = test;
13991425
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" )
14011428 && desc. should_panic != ShouldPanic :: No ;
14021429
14031430 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>>) ->
14881515 match ( & desc. should_panic , task_result) {
14891516 ( & ShouldPanic :: No , Ok ( ( ) ) ) | ( & ShouldPanic :: Yes , Err ( _) ) => TrOk ,
14901517 ( & ShouldPanic :: YesWithMessage ( msg) , Err ( ref err) ) => {
1491- if err. downcast_ref :: < String > ( )
1518+ if err
1519+ . downcast_ref :: < String > ( )
14921520 . map ( |e| & * * e)
14931521 . or_else ( || err. downcast_ref :: < & ' static str > ( ) . map ( |e| * e) )
14941522 . map ( |e| e. contains ( msg) )
@@ -1535,7 +1563,8 @@ impl MetricMap {
15351563 }
15361564
15371565 pub fn fmt_metrics ( & self ) -> String {
1538- let v = self . 0
1566+ let v = self
1567+ . 0
15391568 . iter ( )
15401569 . map ( |( k, v) | format ! ( "{}: {} (+/- {})" , * k, v. value, v. noise) )
15411570 . collect :: < Vec < _ > > ( ) ;
@@ -1644,7 +1673,8 @@ where
16441673
16451674 // If we've run for 100ms and seem to have converged to a
16461675 // 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
16481678 && summ. median - summ5. median < summ5. median_abs_dev
16491679 {
16501680 return summ5;
@@ -1670,12 +1700,12 @@ where
16701700}
16711701
16721702pub mod bench {
1673- use std:: panic:: { catch_unwind, AssertUnwindSafe } ;
1703+ use super :: { BenchMode , BenchSamples , Bencher , MonitorMsg , Sender , Sink , TestDesc , TestResult } ;
1704+ use crate :: stats;
16741705 use std:: cmp;
16751706 use std:: io;
1707+ use std:: panic:: { catch_unwind, AssertUnwindSafe } ;
16761708 use std:: sync:: { Arc , Mutex } ;
1677- use crate :: stats;
1678- use super :: { BenchMode , BenchSamples , Bencher , MonitorMsg , Sender , Sink , TestDesc , TestResult } ;
16791709
16801710 pub fn benchmark < F > ( desc : TestDesc , monitor_ch : Sender < MonitorMsg > , nocapture : bool , f : F )
16811711 where
@@ -1750,14 +1780,15 @@ pub mod bench {
17501780
17511781#[ cfg( test) ]
17521782mod 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;
17571783 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+ } ;
17581789 use crate :: Bencher ;
17591790 use crate :: Concurrent ;
1760-
1791+ use std :: sync :: mpsc :: channel ;
17611792
17621793 fn one_ignored_one_unignored_test ( ) -> Vec < TestDescAndFn > {
17631794 vec ! [
0 commit comments