5
5
#![ warn( rust_2018_idioms, unused_lifetimes) ]
6
6
#![ allow( unused_extern_crates) ]
7
7
8
- use compiletest:: { status_emitter, CommandBuilder , OutputConflictHandling } ;
8
+ use compiletest:: { status_emitter, Args , CommandBuilder , OutputConflictHandling } ;
9
9
use ui_test as compiletest;
10
10
use ui_test:: Mode as TestMode ;
11
11
@@ -110,28 +110,33 @@ mod test_utils;
110
110
// whether to run internal tests or not
111
111
const RUN_INTERNAL_TESTS : bool = cfg ! ( feature = "internal" ) ;
112
112
113
- fn base_config ( test_dir : & str ) -> compiletest:: Config {
113
+ fn canonicalize ( path : impl AsRef < Path > ) -> PathBuf {
114
+ let path = path. as_ref ( ) ;
115
+ fs:: create_dir_all ( path) . unwrap ( ) ;
116
+ fs:: canonicalize ( path) . unwrap_or_else ( |err| panic ! ( "{} cannot be canonicalized: {err}" , path. display( ) ) )
117
+ }
118
+
119
+ fn base_config ( test_dir : & str ) -> ( compiletest:: Config , Args ) {
120
+ let args = Args :: test ( ) . unwrap ( ) ;
114
121
let mut config = compiletest:: Config {
115
- mode : TestMode :: Yolo ,
122
+ mode : TestMode :: Yolo { rustfix : true } ,
116
123
stderr_filters : vec ! [ ] ,
117
124
stdout_filters : vec ! [ ] ,
118
- output_conflict_handling : if var_os ( "RUSTC_BLESS " ) . is_some_and ( |v| v != "0" )
119
- || env :: args ( ) . any ( |arg| arg == "--bless" )
125
+ output_conflict_handling : if var_os ( "GITHUB_ACTION " ) . is_none ( )
126
+ && ( var_os ( "RUSTC_BLESS" ) . is_some_and ( |v| v != "0" ) || !args . check )
120
127
{
121
128
OutputConflictHandling :: Bless
122
129
} else {
123
130
OutputConflictHandling :: Error ( "cargo uibless" . into ( ) )
124
131
} ,
125
132
target : None ,
126
- out_dir : PathBuf :: from ( std:: env:: var_os ( "CARGO_TARGET_DIR" ) . unwrap_or ( "target" . into ( ) ) ) . join ( "ui_test" ) ,
133
+ out_dir : canonicalize (
134
+ std:: env:: var_os ( "CARGO_TARGET_DIR" )
135
+ . map_or_else ( || std:: env:: current_dir ( ) . unwrap ( ) . join ( "target" ) , PathBuf :: from) ,
136
+ )
137
+ . join ( "ui_test" ) ,
127
138
..compiletest:: Config :: rustc ( Path :: new ( "tests" ) . join ( test_dir) )
128
139
} ;
129
-
130
- if let Some ( _path) = option_env ! ( "RUSTC_LIB_PATH" ) {
131
- //let path = PathBuf::from(path);
132
- //config.run_lib_path = path.clone();
133
- //config.compile_lib_path = path;
134
- }
135
140
let current_exe_path = env:: current_exe ( ) . unwrap ( ) ;
136
141
let deps_path = current_exe_path. parent ( ) . unwrap ( ) ;
137
142
let profile_path = deps_path. parent ( ) . unwrap ( ) ;
@@ -164,7 +169,7 @@ fn base_config(test_dir: &str) -> compiletest::Config {
164
169
} else {
165
170
"clippy-driver"
166
171
} ) ;
167
- config
172
+ ( config, args )
168
173
}
169
174
170
175
fn test_filter ( ) -> Box < dyn Sync + Fn ( & Path ) -> bool > {
@@ -177,10 +182,10 @@ fn test_filter() -> Box<dyn Sync + Fn(&Path) -> bool> {
177
182
}
178
183
179
184
fn run_ui ( ) {
180
- let config = base_config ( "ui" ) ;
185
+ let ( config, args ) = base_config ( "ui" ) ;
181
186
//config.rustfix_coverage = true;
182
187
// use tests/clippy.toml
183
- let _g = VarGuard :: set ( "CARGO_MANIFEST_DIR" , fs :: canonicalize ( "tests" ) . unwrap ( ) ) ;
188
+ let _g = VarGuard :: set ( "CARGO_MANIFEST_DIR" , canonicalize ( "tests" ) ) ;
184
189
let _threads = VarGuard :: set (
185
190
"RUST_TEST_THREADS" ,
186
191
// if RUST_TEST_THREADS is set, adhere to it, otherwise override it
@@ -193,43 +198,54 @@ fn run_ui() {
193
198
194
199
let test_filter = test_filter ( ) ;
195
200
201
+ let quiet = args. quiet ;
202
+
196
203
compiletest:: run_tests_generic (
197
- config,
198
- move |path| compiletest:: default_file_filter ( path) && test_filter ( path) ,
204
+ vec ! [ config] ,
205
+ args,
206
+ move |path, args, config| compiletest:: default_file_filter ( path, args, config) && test_filter ( path) ,
199
207
compiletest:: default_per_file_config,
200
- status_emitter:: Text ,
208
+ if quiet {
209
+ status_emitter:: Text :: quiet ( )
210
+ } else {
211
+ status_emitter:: Text :: verbose ( )
212
+ } ,
201
213
)
202
214
. unwrap ( ) ;
203
- check_rustfix_coverage ( ) ;
204
215
}
205
216
206
217
fn run_internal_tests ( ) {
207
218
// only run internal tests with the internal-tests feature
208
219
if !RUN_INTERNAL_TESTS {
209
220
return ;
210
221
}
211
- let mut config = base_config ( "ui-internal" ) ;
222
+ let ( mut config, args ) = base_config ( "ui-internal" ) ;
212
223
if let OutputConflictHandling :: Error ( err) = & mut config. output_conflict_handling {
213
- * err = "cargo uitest --features internal -- -- --bless " . into ( ) ;
224
+ * err = "cargo uitest --features internal" . into ( ) ;
214
225
}
215
226
let test_filter = test_filter ( ) ;
227
+ let quiet = args. quiet ;
216
228
217
229
compiletest:: run_tests_generic (
218
- config,
219
- move |path| compiletest:: default_file_filter ( path) && test_filter ( path) ,
230
+ vec ! [ config] ,
231
+ args,
232
+ move |path, args, config| compiletest:: default_file_filter ( path, args, config) && test_filter ( path) ,
220
233
compiletest:: default_per_file_config,
221
- status_emitter:: Text ,
234
+ if quiet {
235
+ status_emitter:: Text :: quiet ( )
236
+ } else {
237
+ status_emitter:: Text :: verbose ( )
238
+ } ,
222
239
)
223
240
. unwrap ( ) ;
224
241
}
225
242
226
243
fn run_ui_toml ( ) {
227
- let mut config = base_config ( "ui-toml" ) ;
244
+ let ( mut config, args ) = base_config ( "ui-toml" ) ;
228
245
229
246
config. stderr_filter (
230
247
& regex:: escape (
231
- & fs:: canonicalize ( "tests" )
232
- . unwrap ( )
248
+ & canonicalize ( "tests" )
233
249
. parent ( )
234
250
. unwrap ( )
235
251
. display ( )
@@ -240,19 +256,23 @@ fn run_ui_toml() {
240
256
) ;
241
257
242
258
let test_filter = test_filter ( ) ;
259
+ let quiet = args. quiet ;
243
260
244
261
ui_test:: run_tests_generic (
245
- config,
246
- |path| compiletest :: default_file_filter ( path ) && test_filter ( path ) ,
247
- |config , path| {
248
- let mut config = config . clone ( ) ;
262
+ vec ! [ config] ,
263
+ args ,
264
+ |path , args , config| compiletest :: default_file_filter ( path , args , config ) && test_filter ( path ) ,
265
+ | config, path , _file_contents| {
249
266
config
250
267
. program
251
268
. envs
252
269
. push ( ( "CLIPPY_CONF_DIR" . into ( ) , Some ( path. parent ( ) . unwrap ( ) . into ( ) ) ) ) ;
253
- Some ( config)
254
270
} ,
255
- status_emitter:: Text ,
271
+ if quiet {
272
+ status_emitter:: Text :: quiet ( )
273
+ } else {
274
+ status_emitter:: Text :: verbose ( )
275
+ } ,
256
276
)
257
277
. unwrap ( ) ;
258
278
}
@@ -262,7 +282,7 @@ fn run_ui_cargo() {
262
282
return ;
263
283
}
264
284
265
- let mut config = base_config ( "ui-cargo" ) ;
285
+ let ( mut config, args ) = base_config ( "ui-cargo" ) ;
266
286
config. program . input_file_flag = CommandBuilder :: cargo ( ) . input_file_flag ;
267
287
config. program . out_dir_flag = CommandBuilder :: cargo ( ) . out_dir_flag ;
268
288
config. program . args = vec ! [ "clippy" . into( ) , "--color" . into( ) , "never" . into( ) , "--quiet" . into( ) ] ;
@@ -282,8 +302,7 @@ fn run_ui_cargo() {
282
302
283
303
config. stderr_filter (
284
304
& regex:: escape (
285
- & fs:: canonicalize ( "tests" )
286
- . unwrap ( )
305
+ & canonicalize ( "tests" )
287
306
. parent ( )
288
307
. unwrap ( )
289
308
. display ( )
@@ -294,16 +313,26 @@ fn run_ui_cargo() {
294
313
) ;
295
314
296
315
let test_filter = test_filter ( ) ;
316
+ let quiet = args. quiet ;
297
317
298
318
ui_test:: run_tests_generic (
299
- config,
300
- |path| test_filter ( path) && path. ends_with ( "Cargo.toml" ) ,
301
- |config, path| {
302
- let mut config = config. clone ( ) ;
303
- config. out_dir = PathBuf :: from ( "target/ui_test_cargo/" ) . join ( path. parent ( ) . unwrap ( ) ) ;
304
- Some ( config)
319
+ vec ! [ config] ,
320
+ args,
321
+ |path, _args, _config| test_filter ( path) && path. ends_with ( "Cargo.toml" ) ,
322
+ |config, path, _file_contents| {
323
+ config. out_dir = canonicalize (
324
+ std:: env:: current_dir ( )
325
+ . unwrap ( )
326
+ . join ( "target" )
327
+ . join ( "ui_test_cargo/" )
328
+ . join ( path. parent ( ) . unwrap ( ) ) ,
329
+ ) ;
330
+ } ,
331
+ if quiet {
332
+ status_emitter:: Text :: quiet ( )
333
+ } else {
334
+ status_emitter:: Text :: verbose ( )
305
335
} ,
306
- status_emitter:: Text ,
307
336
)
308
337
. unwrap ( ) ;
309
338
}
@@ -328,7 +357,6 @@ fn main() {
328
357
"cargo" => run_ui_cargo as fn ( ) ,
329
358
"toml" => run_ui_toml as fn ( ) ,
330
359
"internal" => run_internal_tests as fn ( ) ,
331
- "rustfix-coverage-known-exceptions-accuracy" => rustfix_coverage_known_exceptions_accuracy as fn ( ) ,
332
360
"ui-cargo-toml-metadata" => ui_cargo_toml_metadata as fn ( ) ,
333
361
334
362
_ => panic ! ( "unknown speedtest: {speedtest} || accepted speedtests are: [ui, cargo, toml, internal]" ) ,
@@ -355,89 +383,10 @@ fn main() {
355
383
run_ui_toml ( ) ;
356
384
run_ui_cargo ( ) ;
357
385
run_internal_tests ( ) ;
358
- rustfix_coverage_known_exceptions_accuracy ( ) ;
359
386
ui_cargo_toml_metadata ( ) ;
360
387
}
361
388
}
362
389
363
- const RUSTFIX_COVERAGE_KNOWN_EXCEPTIONS : & [ & str ] = & [
364
- "assign_ops2.rs" ,
365
- "borrow_deref_ref_unfixable.rs" ,
366
- "cast_size_32bit.rs" ,
367
- "char_lit_as_u8.rs" ,
368
- "cmp_owned/without_suggestion.rs" ,
369
- "dbg_macro.rs" ,
370
- "deref_addrof_double_trigger.rs" ,
371
- "doc/unbalanced_ticks.rs" ,
372
- "eprint_with_newline.rs" ,
373
- "explicit_counter_loop.rs" ,
374
- "iter_skip_next_unfixable.rs" ,
375
- "let_and_return.rs" ,
376
- "literals.rs" ,
377
- "map_flatten.rs" ,
378
- "map_unwrap_or.rs" ,
379
- "match_bool.rs" ,
380
- "mem_replace_macro.rs" ,
381
- "needless_arbitrary_self_type_unfixable.rs" ,
382
- "needless_borrow_pat.rs" ,
383
- "needless_for_each_unfixable.rs" ,
384
- "nonminimal_bool.rs" ,
385
- "print_literal.rs" ,
386
- "redundant_static_lifetimes_multiple.rs" ,
387
- "ref_binding_to_reference.rs" ,
388
- "repl_uninit.rs" ,
389
- "result_map_unit_fn_unfixable.rs" ,
390
- "search_is_some.rs" ,
391
- "single_component_path_imports_nested_first.rs" ,
392
- "string_add.rs" ,
393
- "suspicious_to_owned.rs" ,
394
- "toplevel_ref_arg_non_rustfix.rs" ,
395
- "unit_arg.rs" ,
396
- "unnecessary_clone.rs" ,
397
- "unnecessary_lazy_eval_unfixable.rs" ,
398
- "write_literal.rs" ,
399
- "write_literal_2.rs" ,
400
- ] ;
401
-
402
- fn check_rustfix_coverage ( ) {
403
- let missing_coverage_path = Path :: new ( "debug/test/ui/rustfix_missing_coverage.txt" ) ;
404
- let missing_coverage_path = if let Ok ( target_dir) = std:: env:: var ( "CARGO_TARGET_DIR" ) {
405
- PathBuf :: from ( target_dir) . join ( missing_coverage_path)
406
- } else {
407
- missing_coverage_path. to_path_buf ( )
408
- } ;
409
-
410
- if let Ok ( missing_coverage_contents) = std:: fs:: read_to_string ( missing_coverage_path) {
411
- assert ! ( RUSTFIX_COVERAGE_KNOWN_EXCEPTIONS . iter( ) . is_sorted_by_key( Path :: new) ) ;
412
-
413
- for rs_file in missing_coverage_contents. lines ( ) {
414
- let rs_path = Path :: new ( rs_file) ;
415
- if rs_path. starts_with ( "tests/ui/crashes" ) {
416
- continue ;
417
- }
418
- assert ! ( rs_path. starts_with( "tests/ui/" ) , "{rs_file:?}" ) ;
419
- let filename = rs_path. strip_prefix ( "tests/ui/" ) . unwrap ( ) ;
420
- assert ! (
421
- RUSTFIX_COVERAGE_KNOWN_EXCEPTIONS
422
- . binary_search_by_key( & filename, Path :: new)
423
- . is_ok( ) ,
424
- "`{rs_file}` runs `MachineApplicable` diagnostics but is missing a `run-rustfix` annotation. \
425
- Please either add `//@run-rustfix` at the top of the file or add the file to \
426
- `RUSTFIX_COVERAGE_KNOWN_EXCEPTIONS` in `tests/compile-test.rs`.",
427
- ) ;
428
- }
429
- }
430
- }
431
-
432
- fn rustfix_coverage_known_exceptions_accuracy ( ) {
433
- for filename in RUSTFIX_COVERAGE_KNOWN_EXCEPTIONS {
434
- let rs_path = Path :: new ( "tests/ui" ) . join ( filename) ;
435
- assert ! ( rs_path. exists( ) , "`{}` does not exist" , rs_path. display( ) ) ;
436
- let fixed_path = rs_path. with_extension ( "fixed" ) ;
437
- assert ! ( !fixed_path. exists( ) , "`{}` exists" , fixed_path. display( ) ) ;
438
- }
439
- }
440
-
441
390
fn ui_cargo_toml_metadata ( ) {
442
391
let ui_cargo_path = Path :: new ( "tests/ui-cargo" ) ;
443
392
let cargo_common_metadata_path = ui_cargo_path. join ( "cargo_common_metadata" ) ;
0 commit comments