11use colored:: * ;
22use regex:: bytes:: Regex ;
33use std:: ffi:: OsString ;
4+ use std:: num:: NonZeroUsize ;
45use std:: path:: { Path , PathBuf } ;
56use std:: { env, process:: Command } ;
67use ui_test:: { color_eyre:: Result , Config , Match , Mode , OutputConflictHandling } ;
7- use ui_test:: { status_emitter, CommandBuilder } ;
8+ use ui_test:: { status_emitter, CommandBuilder , Format , RustfixMode } ;
89
910fn miri_path ( ) -> PathBuf {
1011 PathBuf :: from ( option_env ! ( "MIRI" ) . unwrap_or ( env ! ( "CARGO_BIN_EXE_miri" ) ) )
@@ -78,26 +79,18 @@ fn test_config(target: &str, path: &str, mode: Mode, with_dependencies: bool) ->
7879 program. args . push ( flag) ;
7980 }
8081
81- let bless = env:: var_os ( "RUSTC_BLESS" ) . is_some_and ( |v| v != "0" ) ;
82- let skip_ui_checks = env:: var_os ( "MIRI_SKIP_UI_CHECKS" ) . is_some ( ) ;
83-
84- let output_conflict_handling = match ( bless, skip_ui_checks) {
85- ( false , false ) => OutputConflictHandling :: Error ( "./miri test --bless" . into ( ) ) ,
86- ( true , false ) => OutputConflictHandling :: Bless ,
87- ( false , true ) => OutputConflictHandling :: Ignore ,
88- ( true , true ) => panic ! ( "cannot use RUSTC_BLESS and MIRI_SKIP_UI_CHECKS at the same time" ) ,
89- } ;
90-
9182 let mut config = Config {
9283 target : Some ( target. to_owned ( ) ) ,
9384 stderr_filters : STDERR . clone ( ) ,
9485 stdout_filters : STDOUT . clone ( ) ,
9586 mode,
9687 program,
97- output_conflict_handling,
9888 out_dir : PathBuf :: from ( std:: env:: var_os ( "CARGO_TARGET_DIR" ) . unwrap ( ) ) . join ( "ui" ) ,
9989 edition : Some ( "2021" . into ( ) ) ,
100- ..Config :: rustc ( path. into ( ) )
90+ threads : std:: env:: var ( "MIRI_TEST_THREADS" )
91+ . ok ( )
92+ . map ( |threads| NonZeroUsize :: new ( threads. parse ( ) . unwrap ( ) ) . unwrap ( ) ) ,
93+ ..Config :: rustc ( path)
10194 } ;
10295
10396 let use_std = env:: var_os ( "MIRI_NO_STD" ) . is_none ( ) ;
@@ -120,51 +113,32 @@ fn test_config(target: &str, path: &str, mode: Mode, with_dependencies: bool) ->
120113}
121114
122115fn run_tests ( mode : Mode , path : & str , target : & str , with_dependencies : bool ) -> Result < ( ) > {
123- let config = test_config ( target, path, mode, with_dependencies) ;
116+ let mut config = test_config ( target, path, mode, with_dependencies) ;
124117
125118 // Handle command-line arguments.
126- let mut after_dashdash = false ;
127- let mut quiet = false ;
128- let filters = std:: env:: args ( )
129- . skip ( 1 )
130- . filter ( |arg| {
131- if after_dashdash {
132- // Just propagate everything.
133- return true ;
134- }
135- match & * * arg {
136- "--quiet" => {
137- quiet = true ;
138- false
139- }
140- "--" => {
141- after_dashdash = true ;
142- false
143- }
144- s if s. starts_with ( '-' ) => {
145- panic ! ( "unknown compiletest flag `{s}`" ) ;
146- }
147- _ => true ,
148- }
149- } )
150- . collect :: < Vec < _ > > ( ) ;
119+ let args = ui_test:: Args :: test ( ) ?;
120+ let default_bless = env:: var_os ( "RUSTC_BLESS" ) . is_some_and ( |v| v != "0" ) ;
121+ config. with_args ( & args, default_bless) ;
122+ if let OutputConflictHandling :: Error ( msg) = & mut config. output_conflict_handling {
123+ * msg = "./miri test --bless" . into ( ) ;
124+ }
125+ if env:: var_os ( "MIRI_SKIP_UI_CHECKS" ) . is_some ( ) {
126+ assert ! ( !default_bless, "cannot use RUSTC_BLESS and MIRI_SKIP_UI_CHECKS at the same time" ) ;
127+ config. output_conflict_handling = OutputConflictHandling :: Ignore ;
128+ }
151129 eprintln ! ( " Compiler: {}" , config. program. display( ) ) ;
152130 ui_test:: run_tests_generic (
153- config,
131+ // Only run one test suite. In the future we can add all test suites to one `Vec` and run
132+ // them all at once, making best use of systems with high parallelism.
133+ vec ! [ config] ,
154134 // The files we're actually interested in (all `.rs` files).
155- |path| {
156- path. extension ( ) . is_some_and ( |ext| ext == "rs" )
157- && ( filters. is_empty ( )
158- || filters. iter ( ) . any ( |f| path. display ( ) . to_string ( ) . contains ( f) ) )
159- } ,
135+ ui_test:: default_file_filter,
160136 // This could be used to overwrite the `Config` on a per-test basis.
161- |_, _| None ,
137+ |_, _, _| { } ,
162138 (
163- if quiet {
164- Box :: < status_emitter:: Quiet > :: default ( )
165- as Box < dyn status_emitter:: StatusEmitter + Send >
166- } else {
167- Box :: new ( status_emitter:: Text )
139+ match args. format {
140+ Format :: Terse => status_emitter:: Text :: quiet ( ) ,
141+ Format :: Pretty => status_emitter:: Text :: verbose ( ) ,
168142 } ,
169143 status_emitter:: Gha :: < /* GHA Actions groups*/ false > {
170144 name : format ! ( "{mode:?} {path} ({target})" ) ,
@@ -269,11 +243,22 @@ fn main() -> Result<()> {
269243 ui ( Mode :: Pass , "tests/pass" , & target, WithoutDependencies ) ?;
270244 ui ( Mode :: Pass , "tests/pass-dep" , & target, WithDependencies ) ?;
271245 ui ( Mode :: Panic , "tests/panic" , & target, WithDependencies ) ?;
272- ui ( Mode :: Fail { require_patterns : true } , "tests/fail" , & target, WithDependencies ) ?;
246+ ui (
247+ Mode :: Fail { require_patterns : true , rustfix : RustfixMode :: Disabled } ,
248+ "tests/fail" ,
249+ & target,
250+ WithoutDependencies ,
251+ ) ?;
252+ ui (
253+ Mode :: Fail { require_patterns : true , rustfix : RustfixMode :: Disabled } ,
254+ "tests/fail-dep" ,
255+ & target,
256+ WithDependencies ,
257+ ) ?;
273258 if cfg ! ( target_os = "linux" ) {
274259 ui ( Mode :: Pass , "tests/extern-so/pass" , & target, WithoutDependencies ) ?;
275260 ui (
276- Mode :: Fail { require_patterns : true } ,
261+ Mode :: Fail { require_patterns : true , rustfix : RustfixMode :: Disabled } ,
277262 "tests/extern-so/fail" ,
278263 & target,
279264 WithoutDependencies ,
@@ -285,11 +270,17 @@ fn main() -> Result<()> {
285270
286271fn run_dep_mode ( target : String , mut args : impl Iterator < Item = OsString > ) -> Result < ( ) > {
287272 let path = args. next ( ) . expect ( "./miri run-dep must be followed by a file name" ) ;
288- let mut config = test_config ( & target, "" , Mode :: Yolo , /* with dependencies */ true ) ;
273+ let mut config = test_config (
274+ & target,
275+ "" ,
276+ Mode :: Yolo { rustfix : RustfixMode :: Disabled } ,
277+ /* with dependencies */ true ,
278+ ) ;
289279 config. program . args . clear ( ) ; // We want to give the user full control over flags
290- config. build_dependencies_and_link_them ( ) ?;
280+ let dep_args = config. build_dependencies ( ) ?;
291281
292282 let mut cmd = config. program . build ( & config. out_dir ) ;
283+ cmd. args ( dep_args) ;
293284
294285 cmd. arg ( path) ;
295286
0 commit comments