Skip to content

Commit 7b603ba

Browse files
committed
Update ui test crate
1 parent 1eb254e commit 7b603ba

File tree

1,219 files changed

+6849
-5809
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

1,219 files changed

+6849
-5809
lines changed

.cargo/config.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[alias]
2-
uitest = "test --test compile-test"
3-
uibless = "test --test compile-test -- -- --bless"
4-
bless = "test -- -- --bless"
2+
uitest = "test --test compile-test -- --check"
3+
uibless = "test --test compile-test"
4+
bless = "test"
55
dev = "run --package clippy_dev --bin clippy_dev --manifest-path clippy_dev/Cargo.toml --"
66
lintcheck = "run --package lintcheck --bin lintcheck --manifest-path lintcheck/Cargo.toml -- "
77
collect-metadata = "test --test dogfood --features internal -- run_metadata_collection_lint --ignored"

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ tempfile = { version = "3.2", optional = true }
2727
termize = "0.1"
2828

2929
[dev-dependencies]
30-
ui_test = "0.11.5"
30+
ui_test = "0.12"
3131
tester = "0.9"
3232
regex = "1.5"
3333
toml = "0.7.3"

book/src/development/adding_lints.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,8 +161,8 @@ The process of generating the `.stderr` file is the same, and prepending the
161161
## Rustfix tests
162162

163163
If the lint you are working on is making use of structured suggestions, the test
164-
file should include a `//@run-rustfix` comment at the top. This will
165-
additionally run [rustfix] for that test. Rustfix will apply the suggestions
164+
will create a `.fixed` file by running [rustfix] for that test.
165+
Rustfix will apply the suggestions
166166
from the lint to the code of the test file and compare that to the contents of a
167167
`.fixed` file.
168168

clippy_dev/src/update_lints.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -690,7 +690,6 @@ fn gen_deprecated_lints_test(lints: &[DeprecatedLint]) -> String {
690690
fn gen_renamed_lints_test(lints: &[RenamedLint]) -> String {
691691
let mut seen_lints = HashSet::new();
692692
let mut res: String = GENERATED_FILE_COMMENT.into();
693-
res.push_str("//@run-rustfix\n\n");
694693
for lint in lints {
695694
if seen_lints.insert(&lint.new_name) {
696695
writeln!(res, "#![allow({})]", lint.new_name).unwrap();

tests/compile-test.rs

Lines changed: 23 additions & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
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};
99
use ui_test as compiletest;
1010
use ui_test::Mode as TestMode;
1111

@@ -110,13 +110,14 @@ mod test_utils;
110110
// whether to run internal tests or not
111111
const 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 {
@@ -163,7 +164,7 @@ fn base_config(test_dir: &str) -> compiletest::Config {
163164
} else {
164165
"clippy-driver"
165166
});
166-
config
167+
(config, args)
167168
}
168169

169170
fn test_filter() -> Box<dyn Sync + Fn(&Path) -> bool> {
@@ -176,7 +177,7 @@ fn test_filter() -> Box<dyn Sync + Fn(&Path) -> bool> {
176177
}
177178

178179
fn run_ui() {
179-
let config = base_config("ui");
180+
let (config, args) = base_config("ui");
180181
//config.rustfix_coverage = true;
181182
// use tests/clippy.toml
182183
let _g = VarGuard::set("CARGO_MANIFEST_DIR", fs::canonicalize("tests").unwrap());
@@ -194,36 +195,37 @@ fn run_ui() {
194195

195196
compiletest::run_tests_generic(
196197
config,
197-
move |path| compiletest::default_file_filter(path) && test_filter(path),
198+
args,
199+
move |path, args| compiletest::default_file_filter(path, args) && test_filter(path),
198200
compiletest::default_per_file_config,
199-
status_emitter::Text,
201+
status_emitter::Text::verbose(),
200202
)
201203
.unwrap();
202-
check_rustfix_coverage();
203204
}
204205

205206
fn run_internal_tests() {
206207
// only run internal tests with the internal-tests feature
207208
if !RUN_INTERNAL_TESTS {
208209
return;
209210
}
210-
let mut config = base_config("ui-internal");
211+
let (mut config, args) = base_config("ui-internal");
211212
if let OutputConflictHandling::Error(err) = &mut config.output_conflict_handling {
212-
*err = "cargo uitest --features internal -- -- --bless".into();
213+
*err = "cargo uitest --features internal".into();
213214
}
214215
let test_filter = test_filter();
215216

216217
compiletest::run_tests_generic(
217218
config,
218-
move |path| compiletest::default_file_filter(path) && test_filter(path),
219+
args,
220+
move |path, args| compiletest::default_file_filter(path, args) && test_filter(path),
219221
compiletest::default_per_file_config,
220-
status_emitter::Text,
222+
status_emitter::Text::verbose(),
221223
)
222224
.unwrap();
223225
}
224226

225227
fn run_ui_toml() {
226-
let mut config = base_config("ui-toml");
228+
let (mut config, args) = base_config("ui-toml");
227229

228230
config.stderr_filter(
229231
&regex::escape(
@@ -242,7 +244,8 @@ fn run_ui_toml() {
242244

243245
ui_test::run_tests_generic(
244246
config,
245-
|path| compiletest::default_file_filter(path) && test_filter(path),
247+
args,
248+
|path, args| compiletest::default_file_filter(path, args) && test_filter(path),
246249
|config, path| {
247250
let mut config = config.clone();
248251
config
@@ -251,7 +254,7 @@ fn run_ui_toml() {
251254
.push(("CLIPPY_CONF_DIR".into(), Some(path.parent().unwrap().into())));
252255
Some(config)
253256
},
254-
status_emitter::Text,
257+
status_emitter::Text::verbose(),
255258
)
256259
.unwrap();
257260
}
@@ -261,7 +264,7 @@ fn run_ui_cargo() {
261264
return;
262265
}
263266

264-
let mut config = base_config("ui-cargo");
267+
let (mut config, args) = base_config("ui-cargo");
265268
config.program.input_file_flag = CommandBuilder::cargo().input_file_flag;
266269
config.program.out_dir_flag = CommandBuilder::cargo().out_dir_flag;
267270
config.program.args = vec!["clippy".into(), "--color".into(), "never".into(), "--quiet".into()];
@@ -296,13 +299,14 @@ fn run_ui_cargo() {
296299

297300
ui_test::run_tests_generic(
298301
config,
299-
|path| test_filter(path) && path.ends_with("Cargo.toml"),
302+
args,
303+
|path, _args| test_filter(path) && path.ends_with("Cargo.toml"),
300304
|config, path| {
301305
let mut config = config.clone();
302306
config.out_dir = PathBuf::from("target/ui_test_cargo/").join(path.parent().unwrap());
303307
Some(config)
304308
},
305-
status_emitter::Text,
309+
status_emitter::Text::verbose(),
306310
)
307311
.unwrap();
308312
}
@@ -327,7 +331,6 @@ fn main() {
327331
"cargo" => run_ui_cargo as fn(),
328332
"toml" => run_ui_toml as fn(),
329333
"internal" => run_internal_tests as fn(),
330-
"rustfix-coverage-known-exceptions-accuracy" => rustfix_coverage_known_exceptions_accuracy as fn(),
331334
"ui-cargo-toml-metadata" => ui_cargo_toml_metadata as fn(),
332335

333336
_ => panic!("unknown speedtest: {speedtest} || accepted speedtests are: [ui, cargo, toml, internal]"),
@@ -354,89 +357,10 @@ fn main() {
354357
run_ui_toml();
355358
run_ui_cargo();
356359
run_internal_tests();
357-
rustfix_coverage_known_exceptions_accuracy();
358360
ui_cargo_toml_metadata();
359361
}
360362
}
361363

362-
const RUSTFIX_COVERAGE_KNOWN_EXCEPTIONS: &[&str] = &[
363-
"assign_ops2.rs",
364-
"borrow_deref_ref_unfixable.rs",
365-
"cast_size_32bit.rs",
366-
"char_lit_as_u8.rs",
367-
"cmp_owned/without_suggestion.rs",
368-
"dbg_macro.rs",
369-
"deref_addrof_double_trigger.rs",
370-
"doc/unbalanced_ticks.rs",
371-
"eprint_with_newline.rs",
372-
"explicit_counter_loop.rs",
373-
"iter_skip_next_unfixable.rs",
374-
"let_and_return.rs",
375-
"literals.rs",
376-
"map_flatten.rs",
377-
"map_unwrap_or.rs",
378-
"match_bool.rs",
379-
"mem_replace_macro.rs",
380-
"needless_arbitrary_self_type_unfixable.rs",
381-
"needless_borrow_pat.rs",
382-
"needless_for_each_unfixable.rs",
383-
"nonminimal_bool.rs",
384-
"print_literal.rs",
385-
"redundant_static_lifetimes_multiple.rs",
386-
"ref_binding_to_reference.rs",
387-
"repl_uninit.rs",
388-
"result_map_unit_fn_unfixable.rs",
389-
"search_is_some.rs",
390-
"single_component_path_imports_nested_first.rs",
391-
"string_add.rs",
392-
"suspicious_to_owned.rs",
393-
"toplevel_ref_arg_non_rustfix.rs",
394-
"unit_arg.rs",
395-
"unnecessary_clone.rs",
396-
"unnecessary_lazy_eval_unfixable.rs",
397-
"write_literal.rs",
398-
"write_literal_2.rs",
399-
];
400-
401-
fn check_rustfix_coverage() {
402-
let missing_coverage_path = Path::new("debug/test/ui/rustfix_missing_coverage.txt");
403-
let missing_coverage_path = if let Ok(target_dir) = std::env::var("CARGO_TARGET_DIR") {
404-
PathBuf::from(target_dir).join(missing_coverage_path)
405-
} else {
406-
missing_coverage_path.to_path_buf()
407-
};
408-
409-
if let Ok(missing_coverage_contents) = std::fs::read_to_string(missing_coverage_path) {
410-
assert!(RUSTFIX_COVERAGE_KNOWN_EXCEPTIONS.iter().is_sorted_by_key(Path::new));
411-
412-
for rs_file in missing_coverage_contents.lines() {
413-
let rs_path = Path::new(rs_file);
414-
if rs_path.starts_with("tests/ui/crashes") {
415-
continue;
416-
}
417-
assert!(rs_path.starts_with("tests/ui/"), "{rs_file:?}");
418-
let filename = rs_path.strip_prefix("tests/ui/").unwrap();
419-
assert!(
420-
RUSTFIX_COVERAGE_KNOWN_EXCEPTIONS
421-
.binary_search_by_key(&filename, Path::new)
422-
.is_ok(),
423-
"`{rs_file}` runs `MachineApplicable` diagnostics but is missing a `run-rustfix` annotation. \
424-
Please either add `//@run-rustfix` at the top of the file or add the file to \
425-
`RUSTFIX_COVERAGE_KNOWN_EXCEPTIONS` in `tests/compile-test.rs`.",
426-
);
427-
}
428-
}
429-
}
430-
431-
fn rustfix_coverage_known_exceptions_accuracy() {
432-
for filename in RUSTFIX_COVERAGE_KNOWN_EXCEPTIONS {
433-
let rs_path = Path::new("tests/ui").join(filename);
434-
assert!(rs_path.exists(), "`{}` does not exist", rs_path.display());
435-
let fixed_path = rs_path.with_extension("fixed");
436-
assert!(!fixed_path.exists(), "`{}` exists", fixed_path.display());
437-
}
438-
}
439-
440364
fn ui_cargo_toml_metadata() {
441365
let ui_cargo_path = Path::new("tests/ui-cargo");
442366
let cargo_common_metadata_path = ui_cargo_path.join("cargo_common_metadata");

tests/ui-internal/collapsible_span_lint_calls.fixed

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//@run-rustfix
1+
22
#![deny(clippy::internal)]
33
#![allow(clippy::missing_clippy_version_attribute)]
44
#![feature(rustc_private)]

tests/ui-internal/collapsible_span_lint_calls.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
//@run-rustfix
21
#![deny(clippy::internal)]
32
#![allow(clippy::missing_clippy_version_attribute)]
43
#![feature(rustc_private)]

tests/ui-internal/interning_defined_symbol.fixed

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//@run-rustfix
1+
22
#![deny(clippy::internal)]
33
#![allow(clippy::missing_clippy_version_attribute, clippy::let_unit_value)]
44
#![feature(rustc_private)]

tests/ui-internal/interning_defined_symbol.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
//@run-rustfix
21
#![deny(clippy::internal)]
32
#![allow(clippy::missing_clippy_version_attribute, clippy::let_unit_value)]
43
#![feature(rustc_private)]

tests/ui-internal/invalid_msrv_attr_impl.fixed

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//@run-rustfix
1+
22

33
#![deny(clippy::internal)]
44
#![allow(clippy::missing_clippy_version_attribute)]

tests/ui-internal/invalid_msrv_attr_impl.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
//@run-rustfix
2-
31
#![deny(clippy::internal)]
42
#![allow(clippy::missing_clippy_version_attribute)]
53
#![feature(rustc_private)]

tests/ui-internal/outer_expn_data.fixed

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//@run-rustfix
1+
22

33
#![deny(clippy::internal)]
44
#![allow(clippy::missing_clippy_version_attribute)]

tests/ui-internal/outer_expn_data.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
//@run-rustfix
2-
31
#![deny(clippy::internal)]
42
#![allow(clippy::missing_clippy_version_attribute)]
53
#![feature(rustc_private)]

tests/ui-internal/unnecessary_def_path.fixed

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//@run-rustfix
1+
22
//@aux-build:paths.rs
33
#![deny(clippy::internal)]
44
#![feature(rustc_private)]

tests/ui-internal/unnecessary_def_path.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
//@run-rustfix
21
//@aux-build:paths.rs
32
#![deny(clippy::internal)]
43
#![feature(rustc_private)]

tests/ui-internal/unnecessary_symbol_str.fixed

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//@run-rustfix
1+
22
#![feature(rustc_private)]
33
#![deny(clippy::internal)]
44
#![allow(

tests/ui-internal/unnecessary_symbol_str.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
//@run-rustfix
21
#![feature(rustc_private)]
32
#![deny(clippy::internal)]
43
#![allow(

tests/ui-toml/allow_mixed_uninlined_format_args/uninlined_format_args.fixed

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
//@run-rustfix
21
#![warn(clippy::uninlined_format_args)]
32
#![allow(clippy::unnecessary_literal_unwrap)]
43

tests/ui-toml/allow_mixed_uninlined_format_args/uninlined_format_args.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
//@run-rustfix
21
#![warn(clippy::uninlined_format_args)]
32
#![allow(clippy::unnecessary_literal_unwrap)]
43

0 commit comments

Comments
 (0)