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,13 +110,14 @@ 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 base_config ( test_dir : & str ) -> ( compiletest:: Config , Args ) {
114
+ let args = Args :: test ( ) ;
114
115
let mut config = compiletest:: Config {
115
116
mode : TestMode :: Yolo ,
116
117
stderr_filters : vec ! [ ] ,
117
118
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" )
119
+ output_conflict_handling : if var_os ( "GITHUB_ACTION " ) . is_none ( )
120
+ && ( var_os ( "RUSTC_BLESS" ) . is_some_and ( |v| v != "0" ) || !args . check )
120
121
{
121
122
OutputConflictHandling :: Bless
122
123
} else {
@@ -158,7 +159,7 @@ fn base_config(test_dir: &str) -> compiletest::Config {
158
159
} else {
159
160
"clippy-driver"
160
161
} ) ;
161
- config
162
+ ( config, args )
162
163
}
163
164
164
165
fn test_filter ( ) -> Box < dyn Sync + Fn ( & Path ) -> bool > {
@@ -171,7 +172,7 @@ fn test_filter() -> Box<dyn Sync + Fn(&Path) -> bool> {
171
172
}
172
173
173
174
fn run_ui ( ) {
174
- let config = base_config ( "ui" ) ;
175
+ let ( config, args ) = base_config ( "ui" ) ;
175
176
//config.rustfix_coverage = true;
176
177
// use tests/clippy.toml
177
178
let _g = VarGuard :: set ( "CARGO_MANIFEST_DIR" , fs:: canonicalize ( "tests" ) . unwrap ( ) ) ;
@@ -189,36 +190,37 @@ fn run_ui() {
189
190
190
191
compiletest:: run_tests_generic (
191
192
config,
192
- move |path| compiletest:: default_file_filter ( path) && test_filter ( path) ,
193
+ args,
194
+ move |path, args| compiletest:: default_file_filter ( path, args) && test_filter ( path) ,
193
195
compiletest:: default_per_file_config,
194
- status_emitter:: Text ,
196
+ status_emitter:: Text :: verbose ( ) ,
195
197
)
196
198
. unwrap ( ) ;
197
- check_rustfix_coverage ( ) ;
198
199
}
199
200
200
201
fn run_internal_tests ( ) {
201
202
// only run internal tests with the internal-tests feature
202
203
if !RUN_INTERNAL_TESTS {
203
204
return ;
204
205
}
205
- let mut config = base_config ( "ui-internal" ) ;
206
+ let ( mut config, args ) = base_config ( "ui-internal" ) ;
206
207
if let OutputConflictHandling :: Error ( err) = & mut config. output_conflict_handling {
207
- * err = "cargo uitest --features internal -- -- --bless " . into ( ) ;
208
+ * err = "cargo uitest --features internal" . into ( ) ;
208
209
}
209
210
let test_filter = test_filter ( ) ;
210
211
211
212
compiletest:: run_tests_generic (
212
213
config,
213
- move |path| compiletest:: default_file_filter ( path) && test_filter ( path) ,
214
+ args,
215
+ move |path, args| compiletest:: default_file_filter ( path, args) && test_filter ( path) ,
214
216
compiletest:: default_per_file_config,
215
- status_emitter:: Text ,
217
+ status_emitter:: Text :: verbose ( ) ,
216
218
)
217
219
. unwrap ( ) ;
218
220
}
219
221
220
222
fn run_ui_toml ( ) {
221
- let mut config = base_config ( "ui-toml" ) ;
223
+ let ( mut config, args ) = base_config ( "ui-toml" ) ;
222
224
223
225
config. stderr_filter (
224
226
& regex:: escape (
@@ -237,7 +239,8 @@ fn run_ui_toml() {
237
239
238
240
ui_test:: run_tests_generic (
239
241
config,
240
- |path| compiletest:: default_file_filter ( path) && test_filter ( path) ,
242
+ args,
243
+ |path, args| compiletest:: default_file_filter ( path, args) && test_filter ( path) ,
241
244
|config, path| {
242
245
let mut config = config. clone ( ) ;
243
246
config
@@ -246,7 +249,7 @@ fn run_ui_toml() {
246
249
. push ( ( "CLIPPY_CONF_DIR" . into ( ) , Some ( path. parent ( ) . unwrap ( ) . into ( ) ) ) ) ;
247
250
Some ( config)
248
251
} ,
249
- status_emitter:: Text ,
252
+ status_emitter:: Text :: verbose ( ) ,
250
253
)
251
254
. unwrap ( ) ;
252
255
}
@@ -256,7 +259,7 @@ fn run_ui_cargo() {
256
259
return ;
257
260
}
258
261
259
- let mut config = base_config ( "ui-cargo" ) ;
262
+ let ( mut config, args ) = base_config ( "ui-cargo" ) ;
260
263
config. program . input_file_flag = CommandBuilder :: cargo ( ) . input_file_flag ;
261
264
config. program . out_dir_flag = CommandBuilder :: cargo ( ) . out_dir_flag ;
262
265
config. program . args = vec ! [ "clippy" . into( ) , "--color" . into( ) , "never" . into( ) , "--quiet" . into( ) ] ;
@@ -291,13 +294,14 @@ fn run_ui_cargo() {
291
294
292
295
ui_test:: run_tests_generic (
293
296
config,
294
- |path| test_filter ( path) && path. ends_with ( "Cargo.toml" ) ,
297
+ args,
298
+ |path, _args| test_filter ( path) && path. ends_with ( "Cargo.toml" ) ,
295
299
|config, path| {
296
300
let mut config = config. clone ( ) ;
297
301
config. out_dir = PathBuf :: from ( "target/ui_test_cargo/" ) . join ( path. parent ( ) . unwrap ( ) ) ;
298
302
Some ( config)
299
303
} ,
300
- status_emitter:: Text ,
304
+ status_emitter:: Text :: verbose ( ) ,
301
305
)
302
306
. unwrap ( ) ;
303
307
}
@@ -322,7 +326,6 @@ fn main() {
322
326
"cargo" => run_ui_cargo as fn ( ) ,
323
327
"toml" => run_ui_toml as fn ( ) ,
324
328
"internal" => run_internal_tests as fn ( ) ,
325
- "rustfix-coverage-known-exceptions-accuracy" => rustfix_coverage_known_exceptions_accuracy as fn ( ) ,
326
329
"ui-cargo-toml-metadata" => ui_cargo_toml_metadata as fn ( ) ,
327
330
328
331
_ => panic ! ( "unknown speedtest: {speedtest} || accepted speedtests are: [ui, cargo, toml, internal]" ) ,
@@ -349,89 +352,10 @@ fn main() {
349
352
run_ui_toml ( ) ;
350
353
run_ui_cargo ( ) ;
351
354
run_internal_tests ( ) ;
352
- rustfix_coverage_known_exceptions_accuracy ( ) ;
353
355
ui_cargo_toml_metadata ( ) ;
354
356
}
355
357
}
356
358
357
- const RUSTFIX_COVERAGE_KNOWN_EXCEPTIONS : & [ & str ] = & [
358
- "assign_ops2.rs" ,
359
- "borrow_deref_ref_unfixable.rs" ,
360
- "cast_size_32bit.rs" ,
361
- "char_lit_as_u8.rs" ,
362
- "cmp_owned/without_suggestion.rs" ,
363
- "dbg_macro.rs" ,
364
- "deref_addrof_double_trigger.rs" ,
365
- "doc/unbalanced_ticks.rs" ,
366
- "eprint_with_newline.rs" ,
367
- "explicit_counter_loop.rs" ,
368
- "iter_skip_next_unfixable.rs" ,
369
- "let_and_return.rs" ,
370
- "literals.rs" ,
371
- "map_flatten.rs" ,
372
- "map_unwrap_or.rs" ,
373
- "match_bool.rs" ,
374
- "mem_replace_macro.rs" ,
375
- "needless_arbitrary_self_type_unfixable.rs" ,
376
- "needless_borrow_pat.rs" ,
377
- "needless_for_each_unfixable.rs" ,
378
- "nonminimal_bool.rs" ,
379
- "print_literal.rs" ,
380
- "redundant_static_lifetimes_multiple.rs" ,
381
- "ref_binding_to_reference.rs" ,
382
- "repl_uninit.rs" ,
383
- "result_map_unit_fn_unfixable.rs" ,
384
- "search_is_some.rs" ,
385
- "single_component_path_imports_nested_first.rs" ,
386
- "string_add.rs" ,
387
- "suspicious_to_owned.rs" ,
388
- "toplevel_ref_arg_non_rustfix.rs" ,
389
- "unit_arg.rs" ,
390
- "unnecessary_clone.rs" ,
391
- "unnecessary_lazy_eval_unfixable.rs" ,
392
- "write_literal.rs" ,
393
- "write_literal_2.rs" ,
394
- ] ;
395
-
396
- fn check_rustfix_coverage ( ) {
397
- let missing_coverage_path = Path :: new ( "debug/test/ui/rustfix_missing_coverage.txt" ) ;
398
- let missing_coverage_path = if let Ok ( target_dir) = std:: env:: var ( "CARGO_TARGET_DIR" ) {
399
- PathBuf :: from ( target_dir) . join ( missing_coverage_path)
400
- } else {
401
- missing_coverage_path. to_path_buf ( )
402
- } ;
403
-
404
- if let Ok ( missing_coverage_contents) = std:: fs:: read_to_string ( missing_coverage_path) {
405
- assert ! ( RUSTFIX_COVERAGE_KNOWN_EXCEPTIONS . iter( ) . is_sorted_by_key( Path :: new) ) ;
406
-
407
- for rs_file in missing_coverage_contents. lines ( ) {
408
- let rs_path = Path :: new ( rs_file) ;
409
- if rs_path. starts_with ( "tests/ui/crashes" ) {
410
- continue ;
411
- }
412
- assert ! ( rs_path. starts_with( "tests/ui/" ) , "{rs_file:?}" ) ;
413
- let filename = rs_path. strip_prefix ( "tests/ui/" ) . unwrap ( ) ;
414
- assert ! (
415
- RUSTFIX_COVERAGE_KNOWN_EXCEPTIONS
416
- . binary_search_by_key( & filename, Path :: new)
417
- . is_ok( ) ,
418
- "`{rs_file}` runs `MachineApplicable` diagnostics but is missing a `run-rustfix` annotation. \
419
- Please either add `//@run-rustfix` at the top of the file or add the file to \
420
- `RUSTFIX_COVERAGE_KNOWN_EXCEPTIONS` in `tests/compile-test.rs`.",
421
- ) ;
422
- }
423
- }
424
- }
425
-
426
- fn rustfix_coverage_known_exceptions_accuracy ( ) {
427
- for filename in RUSTFIX_COVERAGE_KNOWN_EXCEPTIONS {
428
- let rs_path = Path :: new ( "tests/ui" ) . join ( filename) ;
429
- assert ! ( rs_path. exists( ) , "`{}` does not exist" , rs_path. display( ) ) ;
430
- let fixed_path = rs_path. with_extension ( "fixed" ) ;
431
- assert ! ( !fixed_path. exists( ) , "`{}` exists" , fixed_path. display( ) ) ;
432
- }
433
- }
434
-
435
359
fn ui_cargo_toml_metadata ( ) {
436
360
let ui_cargo_path = Path :: new ( "tests/ui-cargo" ) ;
437
361
let cargo_common_metadata_path = ui_cargo_path. join ( "cargo_common_metadata" ) ;
0 commit comments