@@ -12,6 +12,7 @@ pub mod common;
12
12
pub mod compute_diff;
13
13
mod debuggers;
14
14
pub mod errors;
15
+ mod executor;
15
16
pub mod header;
16
17
mod json;
17
18
mod raise_fd_limit;
@@ -32,7 +33,6 @@ use std::{env, fs, vec};
32
33
33
34
use build_helper:: git:: { get_git_modified_files, get_git_untracked_files} ;
34
35
use getopts:: Options ;
35
- use test:: ColorConfig ;
36
36
use tracing:: * ;
37
37
use walkdir:: WalkDir ;
38
38
@@ -41,6 +41,7 @@ use crate::common::{
41
41
CompareMode , Config , Debugger , Mode , PassMode , TestPaths , UI_EXTENSIONS , expected_output_path,
42
42
output_base_dir, output_relative_path,
43
43
} ;
44
+ use crate :: executor:: { CollectedTest , ColorConfig , OutputFormat } ;
44
45
use crate :: header:: HeadersCache ;
45
46
use crate :: util:: logv;
46
47
@@ -50,6 +51,12 @@ use crate::util::logv;
50
51
/// some code here that inspects environment variables or even runs executables
51
52
/// (e.g. when discovering debugger versions).
52
53
pub fn parse_config ( args : Vec < String > ) -> Config {
54
+ if env:: var ( "RUST_TEST_NOCAPTURE" ) . is_ok ( ) {
55
+ eprintln ! (
56
+ "WARNING: RUST_TEST_NOCAPTURE is not supported. Use the `--no-capture` flag instead."
57
+ ) ;
58
+ }
59
+
53
60
let mut opts = Options :: new ( ) ;
54
61
opts. reqopt ( "" , "compile-lib-path" , "path to host shared libraries" , "PATH" )
55
62
. reqopt ( "" , "run-lib-path" , "path to target shared libraries" , "PATH" )
@@ -128,6 +135,7 @@ pub fn parse_config(args: Vec<String>) -> Config {
128
135
"bless" ,
129
136
"overwrite stderr/stdout files instead of complaining about a mismatch" ,
130
137
)
138
+ . optflag ( "" , "fail-fast" , "stop as soon as possible after any test fails" )
131
139
. optflag ( "" , "quiet" , "print one character per test instead of one line" )
132
140
. optopt ( "" , "color" , "coloring: auto, always, never" , "WHEN" )
133
141
. optflag ( "" , "json" , "emit json output instead of plaintext output" )
@@ -319,6 +327,9 @@ pub fn parse_config(args: Vec<String>) -> Config {
319
327
320
328
Config {
321
329
bless : matches. opt_present ( "bless" ) ,
330
+ fail_fast : matches. opt_present ( "fail-fast" )
331
+ || env:: var_os ( "RUSTC_TEST_FAIL_FAST" ) . is_some ( ) ,
332
+
322
333
compile_lib_path : make_absolute ( opt_path ( matches, "compile-lib-path" ) ) ,
323
334
run_lib_path : make_absolute ( opt_path ( matches, "run-lib-path" ) ) ,
324
335
rustc_path : opt_path ( matches, "rustc-path" ) ,
@@ -392,9 +403,9 @@ pub fn parse_config(args: Vec<String>) -> Config {
392
403
verbose : matches. opt_present ( "verbose" ) ,
393
404
format : match ( matches. opt_present ( "quiet" ) , matches. opt_present ( "json" ) ) {
394
405
( true , true ) => panic ! ( "--quiet and --json are incompatible" ) ,
395
- ( true , false ) => test :: OutputFormat :: Terse ,
396
- ( false , true ) => test :: OutputFormat :: Json ,
397
- ( false , false ) => test :: OutputFormat :: Pretty ,
406
+ ( true , false ) => OutputFormat :: Terse ,
407
+ ( false , true ) => OutputFormat :: Json ,
408
+ ( false , false ) => OutputFormat :: Pretty ,
398
409
} ,
399
410
only_modified : matches. opt_present ( "only-modified" ) ,
400
411
color,
@@ -525,8 +536,6 @@ pub fn run_tests(config: Arc<Config>) {
525
536
// Let tests know which target they're running as
526
537
env:: set_var ( "TARGET" , & config. target ) ;
527
538
528
- let opts = test_opts ( & config) ;
529
-
530
539
let mut configs = Vec :: new ( ) ;
531
540
if let Mode :: DebugInfo = config. mode {
532
541
// Debugging emscripten code doesn't make sense today
@@ -553,12 +562,12 @@ pub fn run_tests(config: Arc<Config>) {
553
562
tests. extend ( collect_and_make_tests ( c) ) ;
554
563
}
555
564
556
- tests. sort_by ( |a, b| a. desc . name . as_slice ( ) . cmp ( & b. desc . name . as_slice ( ) ) ) ;
565
+ tests. sort_by ( |a, b| Ord :: cmp ( & a. desc . name , & b. desc . name ) ) ;
557
566
558
567
// Delegate to libtest to filter and run the big list of structures created
559
- // during test discovery. When libtest decides to run a test, it will invoke
560
- // the corresponding closure created by `make_test_closure` .
561
- let res = test :: run_tests_console ( & opts , tests) ;
568
+ // during test discovery. When libtest decides to run a test, it will
569
+ // return control to compiletest by invoking a closure .
570
+ let res = crate :: executor :: execute_tests ( & config , tests) ;
562
571
563
572
// Check the outcome reported by libtest.
564
573
match res {
@@ -602,37 +611,6 @@ pub fn run_tests(config: Arc<Config>) {
602
611
}
603
612
}
604
613
605
- pub fn test_opts ( config : & Config ) -> test:: TestOpts {
606
- if env:: var ( "RUST_TEST_NOCAPTURE" ) . is_ok ( ) {
607
- eprintln ! (
608
- "WARNING: RUST_TEST_NOCAPTURE is no longer used. \
609
- Use the `--nocapture` flag instead."
610
- ) ;
611
- }
612
-
613
- test:: TestOpts {
614
- exclude_should_panic : false ,
615
- filters : config. filters . clone ( ) ,
616
- filter_exact : config. filter_exact ,
617
- run_ignored : if config. run_ignored { test:: RunIgnored :: Yes } else { test:: RunIgnored :: No } ,
618
- format : config. format ,
619
- logfile : config. logfile . clone ( ) ,
620
- run_tests : true ,
621
- bench_benchmarks : true ,
622
- nocapture : config. nocapture ,
623
- color : config. color ,
624
- shuffle : false ,
625
- shuffle_seed : None ,
626
- test_threads : None ,
627
- skip : config. skip . clone ( ) ,
628
- list : false ,
629
- options : test:: Options :: new ( ) ,
630
- time_options : None ,
631
- force_run_in_process : false ,
632
- fail_fast : std:: env:: var_os ( "RUSTC_TEST_FAIL_FAST" ) . is_some ( ) ,
633
- }
634
- }
635
-
636
614
/// Read-only context data used during test collection.
637
615
struct TestCollectorCx {
638
616
config : Arc < Config > ,
@@ -643,17 +621,17 @@ struct TestCollectorCx {
643
621
644
622
/// Mutable state used during test collection.
645
623
struct TestCollector {
646
- tests : Vec < test :: TestDescAndFn > ,
624
+ tests : Vec < CollectedTest > ,
647
625
found_path_stems : HashSet < PathBuf > ,
648
626
poisoned : bool ,
649
627
}
650
628
651
- /// Creates libtest structures for every test/revision in the test suite directory.
629
+ /// Creates test structures for every test/revision in the test suite directory.
652
630
///
653
631
/// This always inspects _all_ test files in the suite (e.g. all 17k+ ui tests),
654
632
/// regardless of whether any filters/tests were specified on the command-line,
655
633
/// because filtering is handled later by libtest.
656
- pub fn collect_and_make_tests ( config : Arc < Config > ) -> Vec < test :: TestDescAndFn > {
634
+ pub ( crate ) fn collect_and_make_tests ( config : Arc < Config > ) -> Vec < CollectedTest > {
657
635
debug ! ( "making tests from {}" , config. src_test_suite_root. display( ) ) ;
658
636
let common_inputs_stamp = common_inputs_stamp ( & config) ;
659
637
let modified_tests =
@@ -882,7 +860,7 @@ fn make_test(cx: &TestCollectorCx, collector: &mut TestCollector, testpaths: &Te
882
860
} ;
883
861
884
862
// For each revision (or the sole dummy revision), create and append a
885
- // `test::TestDescAndFn ` that can be handed over to libtest .
863
+ // `CollectedTest ` that can be handed over to the test executor .
886
864
collector. tests . extend ( revisions. into_iter ( ) . map ( |revision| {
887
865
// Create a test name and description to hand over to libtest.
888
866
let src_file = fs:: File :: open ( & test_path) . expect ( "open test file to parse ignores" ) ;
@@ -905,13 +883,14 @@ fn make_test(cx: &TestCollectorCx, collector: &mut TestCollector, testpaths: &Te
905
883
if !cx. config . force_rerun && is_up_to_date ( cx, testpaths, & early_props, revision) {
906
884
desc. ignore = true ;
907
885
// Keep this in sync with the "up-to-date" message detected by bootstrap.
908
- desc. ignore_message = Some ( "up-to-date" ) ;
886
+ desc. ignore_message = Some ( "up-to-date" . into ( ) ) ;
909
887
}
910
888
911
- // Create the callback that will run this test/revision when libtest calls it.
912
- let testfn = make_test_closure ( Arc :: clone ( & cx. config ) , testpaths, revision) ;
889
+ let config = Arc :: clone ( & cx. config ) ;
890
+ let testpaths = testpaths. clone ( ) ;
891
+ let revision = revision. map ( str:: to_owned) ;
913
892
914
- test :: TestDescAndFn { desc, testfn }
893
+ CollectedTest { desc, config , testpaths , revision }
915
894
} ) ) ;
916
895
}
917
896
@@ -1043,11 +1022,7 @@ impl Stamp {
1043
1022
}
1044
1023
1045
1024
/// Creates a name for this test/revision that can be handed over to libtest.
1046
- fn make_test_name (
1047
- config : & Config ,
1048
- testpaths : & TestPaths ,
1049
- revision : Option < & str > ,
1050
- ) -> test:: TestName {
1025
+ fn make_test_name ( config : & Config , testpaths : & TestPaths , revision : Option < & str > ) -> String {
1051
1026
// Print the name of the file, relative to the sources root.
1052
1027
let path = testpaths. file . strip_prefix ( & config. src_root ) . unwrap ( ) ;
1053
1028
let debugger = match config. debugger {
@@ -1059,32 +1034,14 @@ fn make_test_name(
1059
1034
None => String :: new ( ) ,
1060
1035
} ;
1061
1036
1062
- test :: DynTestName ( format ! (
1037
+ format ! (
1063
1038
"[{}{}{}] {}{}" ,
1064
1039
config. mode,
1065
1040
debugger,
1066
1041
mode_suffix,
1067
1042
path. display( ) ,
1068
1043
revision. map_or( "" . to_string( ) , |rev| format!( "#{}" , rev) )
1069
- ) )
1070
- }
1071
-
1072
- /// Creates a callback for this test/revision that libtest will call when it
1073
- /// decides to actually run the underlying test.
1074
- fn make_test_closure (
1075
- config : Arc < Config > ,
1076
- testpaths : & TestPaths ,
1077
- revision : Option < & str > ,
1078
- ) -> test:: TestFn {
1079
- let testpaths = testpaths. clone ( ) ;
1080
- let revision = revision. map ( str:: to_owned) ;
1081
-
1082
- // This callback is the link between compiletest's test discovery code,
1083
- // and the parts of compiletest that know how to run an individual test.
1084
- test:: DynTestFn ( Box :: new ( move || {
1085
- runtest:: run ( config, & testpaths, revision. as_deref ( ) ) ;
1086
- Ok ( ( ) )
1087
- } ) )
1044
+ )
1088
1045
}
1089
1046
1090
1047
/// Checks that test discovery didn't find any tests whose name stem is a prefix
0 commit comments