Skip to content

Commit 3d88fae

Browse files
committed
Update ui test crate
1 parent 0afd38b commit 3d88fae

File tree

1,219 files changed

+6850
-5810
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

+6850
-5810
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 {
@@ -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

164165
fn test_filter() -> Box<dyn Sync + Fn(&Path) -> bool> {
@@ -171,7 +172,7 @@ fn test_filter() -> Box<dyn Sync + Fn(&Path) -> bool> {
171172
}
172173

173174
fn 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

200201
fn 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

220222
fn 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-
435359
fn 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");

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)]

0 commit comments

Comments
 (0)