55#![ warn( rust_2018_idioms, unused_lifetimes) ]
66#![ allow( unused_extern_crates) ]
77
8- use compiletest:: { status_emitter, CommandBuilder , OutputConflictHandling } ;
8+ use compiletest:: { status_emitter, Args , CommandBuilder , OutputConflictHandling } ;
99use ui_test as compiletest;
1010use ui_test:: Mode as TestMode ;
1111
@@ -110,13 +110,14 @@ mod test_utils;
110110// whether to run internal tests or not
111111const RUN_INTERNAL_TESTS : bool = cfg ! ( feature = "internal" ) ;
112112
113- fn base_config ( test_dir : & str ) -> compiletest:: Config {
113+ fn base_config ( test_dir : & str ) -> ( compiletest:: Config , Args ) {
114+ let args = Args :: test ( ) ;
114115 let mut config = compiletest:: Config {
115116 mode : TestMode :: Yolo ,
116117 stderr_filters : vec ! [ ] ,
117118 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 )
120121 {
121122 OutputConflictHandling :: Bless
122123 } else {
@@ -158,7 +159,7 @@ fn base_config(test_dir: &str) -> compiletest::Config {
158159 } else {
159160 "clippy-driver"
160161 } ) ;
161- config
162+ ( config, args )
162163}
163164
164165fn test_filter ( ) -> Box < dyn Sync + Fn ( & Path ) -> bool > {
@@ -171,7 +172,7 @@ fn test_filter() -> Box<dyn Sync + Fn(&Path) -> bool> {
171172}
172173
173174fn run_ui ( ) {
174- let config = base_config ( "ui" ) ;
175+ let ( config, args ) = base_config ( "ui" ) ;
175176 //config.rustfix_coverage = true;
176177 // use tests/clippy.toml
177178 let _g = VarGuard :: set ( "CARGO_MANIFEST_DIR" , fs:: canonicalize ( "tests" ) . unwrap ( ) ) ;
@@ -189,36 +190,37 @@ fn run_ui() {
189190
190191 compiletest:: run_tests_generic (
191192 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) ,
193195 compiletest:: default_per_file_config,
194- status_emitter:: Text ,
196+ status_emitter:: Text :: verbose ( ) ,
195197 )
196198 . unwrap ( ) ;
197- check_rustfix_coverage ( ) ;
198199}
199200
200201fn run_internal_tests ( ) {
201202 // only run internal tests with the internal-tests feature
202203 if !RUN_INTERNAL_TESTS {
203204 return ;
204205 }
205- let mut config = base_config ( "ui-internal" ) ;
206+ let ( mut config, args ) = base_config ( "ui-internal" ) ;
206207 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 ( ) ;
208209 }
209210 let test_filter = test_filter ( ) ;
210211
211212 compiletest:: run_tests_generic (
212213 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) ,
214216 compiletest:: default_per_file_config,
215- status_emitter:: Text ,
217+ status_emitter:: Text :: verbose ( ) ,
216218 )
217219 . unwrap ( ) ;
218220}
219221
220222fn run_ui_toml ( ) {
221- let mut config = base_config ( "ui-toml" ) ;
223+ let ( mut config, args ) = base_config ( "ui-toml" ) ;
222224
223225 config. stderr_filter (
224226 & regex:: escape (
@@ -237,7 +239,8 @@ fn run_ui_toml() {
237239
238240 ui_test:: run_tests_generic (
239241 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) ,
241244 |config, path| {
242245 let mut config = config. clone ( ) ;
243246 config
@@ -246,7 +249,7 @@ fn run_ui_toml() {
246249 . push ( ( "CLIPPY_CONF_DIR" . into ( ) , Some ( path. parent ( ) . unwrap ( ) . into ( ) ) ) ) ;
247250 Some ( config)
248251 } ,
249- status_emitter:: Text ,
252+ status_emitter:: Text :: verbose ( ) ,
250253 )
251254 . unwrap ( ) ;
252255}
@@ -256,7 +259,7 @@ fn run_ui_cargo() {
256259 return ;
257260 }
258261
259- let mut config = base_config ( "ui-cargo" ) ;
262+ let ( mut config, args ) = base_config ( "ui-cargo" ) ;
260263 config. program . input_file_flag = CommandBuilder :: cargo ( ) . input_file_flag ;
261264 config. program . out_dir_flag = CommandBuilder :: cargo ( ) . out_dir_flag ;
262265 config. program . args = vec ! [ "clippy" . into( ) , "--color" . into( ) , "never" . into( ) , "--quiet" . into( ) ] ;
@@ -291,13 +294,14 @@ fn run_ui_cargo() {
291294
292295 ui_test:: run_tests_generic (
293296 config,
294- |path| test_filter ( path) && path. ends_with ( "Cargo.toml" ) ,
297+ args,
298+ |path, _args| test_filter ( path) && path. ends_with ( "Cargo.toml" ) ,
295299 |config, path| {
296300 let mut config = config. clone ( ) ;
297301 config. out_dir = PathBuf :: from ( "target/ui_test_cargo/" ) . join ( path. parent ( ) . unwrap ( ) ) ;
298302 Some ( config)
299303 } ,
300- status_emitter:: Text ,
304+ status_emitter:: Text :: verbose ( ) ,
301305 )
302306 . unwrap ( ) ;
303307}
@@ -322,7 +326,6 @@ fn main() {
322326 "cargo" => run_ui_cargo as fn ( ) ,
323327 "toml" => run_ui_toml as fn ( ) ,
324328 "internal" => run_internal_tests as fn ( ) ,
325- "rustfix-coverage-known-exceptions-accuracy" => rustfix_coverage_known_exceptions_accuracy as fn ( ) ,
326329 "ui-cargo-toml-metadata" => ui_cargo_toml_metadata as fn ( ) ,
327330
328331 _ => panic ! ( "unknown speedtest: {speedtest} || accepted speedtests are: [ui, cargo, toml, internal]" ) ,
@@ -349,89 +352,10 @@ fn main() {
349352 run_ui_toml ( ) ;
350353 run_ui_cargo ( ) ;
351354 run_internal_tests ( ) ;
352- rustfix_coverage_known_exceptions_accuracy ( ) ;
353355 ui_cargo_toml_metadata ( ) ;
354356 }
355357}
356358
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-
435359fn ui_cargo_toml_metadata ( ) {
436360 let ui_cargo_path = Path :: new ( "tests/ui-cargo" ) ;
437361 let cargo_common_metadata_path = ui_cargo_path. join ( "cargo_common_metadata" ) ;
0 commit comments