1
1
use colored:: * ;
2
2
use regex:: bytes:: Regex ;
3
3
use std:: ffi:: OsString ;
4
+ use std:: num:: NonZeroUsize ;
4
5
use std:: path:: { Path , PathBuf } ;
5
6
use std:: { env, process:: Command } ;
6
7
use 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 } ;
8
9
9
10
fn miri_path ( ) -> PathBuf {
10
11
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) ->
78
79
program. args . push ( flag) ;
79
80
}
80
81
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
-
91
82
let mut config = Config {
92
83
target : Some ( target. to_owned ( ) ) ,
93
84
stderr_filters : STDERR . clone ( ) ,
94
85
stdout_filters : STDOUT . clone ( ) ,
95
86
mode,
96
87
program,
97
- output_conflict_handling,
98
88
out_dir : PathBuf :: from ( std:: env:: var_os ( "CARGO_TARGET_DIR" ) . unwrap ( ) ) . join ( "ui" ) ,
99
89
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)
101
94
} ;
102
95
103
96
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) ->
120
113
}
121
114
122
115
fn 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) ;
124
117
125
118
// 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
+ }
151
129
eprintln ! ( " Compiler: {}" , config. program. display( ) ) ;
152
130
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] ,
154
134
// 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,
160
136
// This could be used to overwrite the `Config` on a per-test basis.
161
- |_, _| None ,
137
+ |_, _, _| { } ,
162
138
(
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 ( ) ,
168
142
} ,
169
143
status_emitter:: Gha :: < /* GHA Actions groups*/ false > {
170
144
name : format ! ( "{mode:?} {path} ({target})" ) ,
@@ -269,11 +243,22 @@ fn main() -> Result<()> {
269
243
ui ( Mode :: Pass , "tests/pass" , & target, WithoutDependencies ) ?;
270
244
ui ( Mode :: Pass , "tests/pass-dep" , & target, WithDependencies ) ?;
271
245
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
+ ) ?;
273
258
if cfg ! ( target_os = "linux" ) {
274
259
ui ( Mode :: Pass , "tests/extern-so/pass" , & target, WithoutDependencies ) ?;
275
260
ui (
276
- Mode :: Fail { require_patterns : true } ,
261
+ Mode :: Fail { require_patterns : true , rustfix : RustfixMode :: Disabled } ,
277
262
"tests/extern-so/fail" ,
278
263
& target,
279
264
WithoutDependencies ,
@@ -285,11 +270,17 @@ fn main() -> Result<()> {
285
270
286
271
fn run_dep_mode ( target : String , mut args : impl Iterator < Item = OsString > ) -> Result < ( ) > {
287
272
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
+ ) ;
289
279
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 ( ) ?;
291
281
292
282
let mut cmd = config. program . build ( & config. out_dir ) ;
283
+ cmd. args ( dep_args) ;
293
284
294
285
cmd. arg ( path) ;
295
286
0 commit comments