Skip to content

Commit f7d64e6

Browse files
committed
Update ui test crate
1 parent d446378 commit f7d64e6

File tree

1,215 files changed

+6799
-5797
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,215 files changed

+6799
-5797
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: 22 additions & 98 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,12 +110,13 @@ 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("BLESS").is_some() || env::args().any(|arg| arg == "--bless") {
119+
output_conflict_handling: if var_os("BLESS").is_some() || !args.check {
119120
OutputConflictHandling::Bless
120121
} else {
121122
OutputConflictHandling::Error("cargo uibless".into())
@@ -161,7 +162,7 @@ fn base_config(test_dir: &str) -> compiletest::Config {
161162
} else {
162163
"clippy-driver"
163164
});
164-
config
165+
(config, args)
165166
}
166167

167168
fn test_filter() -> Box<dyn Sync + Fn(&Path) -> bool> {
@@ -174,7 +175,7 @@ fn test_filter() -> Box<dyn Sync + Fn(&Path) -> bool> {
174175
}
175176

176177
fn run_ui() {
177-
let config = base_config("ui");
178+
let (config, args) = base_config("ui");
178179
//config.rustfix_coverage = true;
179180
// use tests/clippy.toml
180181
let _g = VarGuard::set("CARGO_MANIFEST_DIR", fs::canonicalize("tests").unwrap());
@@ -192,36 +193,37 @@ fn run_ui() {
192193

193194
compiletest::run_tests_generic(
194195
config,
195-
move |path| compiletest::default_file_filter(path) && test_filter(path),
196+
args,
197+
move |path, args| compiletest::default_file_filter(path, args) && test_filter(path),
196198
compiletest::default_per_file_config,
197-
status_emitter::Text,
199+
status_emitter::Text::verbose(),
198200
)
199201
.unwrap();
200-
check_rustfix_coverage();
201202
}
202203

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

214215
compiletest::run_tests_generic(
215216
config,
216-
move |path| compiletest::default_file_filter(path) && test_filter(path),
217+
args,
218+
move |path, args| compiletest::default_file_filter(path, args) && test_filter(path),
217219
compiletest::default_per_file_config,
218-
status_emitter::Text,
220+
status_emitter::Text::verbose(),
219221
)
220222
.unwrap();
221223
}
222224

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

226228
config.stderr_filter(
227229
&regex::escape(
@@ -240,7 +242,8 @@ fn run_ui_toml() {
240242

241243
ui_test::run_tests_generic(
242244
config,
243-
|path| compiletest::default_file_filter(path) && test_filter(path),
245+
args,
246+
|path, args| compiletest::default_file_filter(path, args) && test_filter(path),
244247
|config, path| {
245248
let mut config = config.clone();
246249
config
@@ -249,7 +252,7 @@ fn run_ui_toml() {
249252
.push(("CLIPPY_CONF_DIR".into(), Some(path.parent().unwrap().into())));
250253
Some(config)
251254
},
252-
status_emitter::Text,
255+
status_emitter::Text::verbose(),
253256
)
254257
.unwrap();
255258
}
@@ -259,7 +262,7 @@ fn run_ui_cargo() {
259262
return;
260263
}
261264

262-
let mut config = base_config("ui-cargo");
265+
let (mut config, args) = base_config("ui-cargo");
263266
config.program.input_file_flag = CommandBuilder::cargo().input_file_flag;
264267
config.program.out_dir_flag = CommandBuilder::cargo().out_dir_flag;
265268
config.program.args = vec!["clippy".into(), "--color".into(), "never".into(), "--quiet".into()];
@@ -294,13 +297,14 @@ fn run_ui_cargo() {
294297

295298
ui_test::run_tests_generic(
296299
config,
297-
|path| test_filter(path) && path.ends_with("Cargo.toml"),
300+
args,
301+
|path, _args| test_filter(path) && path.ends_with("Cargo.toml"),
298302
|config, path| {
299303
let mut config = config.clone();
300304
config.out_dir = PathBuf::from("target/ui_test_cargo/").join(path.parent().unwrap());
301305
Some(config)
302306
},
303-
status_emitter::Text,
307+
status_emitter::Text::verbose(),
304308
)
305309
.unwrap();
306310
}
@@ -325,7 +329,6 @@ fn main() {
325329
"cargo" => run_ui_cargo as fn(),
326330
"toml" => run_ui_toml as fn(),
327331
"internal" => run_internal_tests as fn(),
328-
"rustfix-coverage-known-exceptions-accuracy" => rustfix_coverage_known_exceptions_accuracy as fn(),
329332
"ui-cargo-toml-metadata" => ui_cargo_toml_metadata as fn(),
330333

331334
_ => panic!("unknown speedtest: {speedtest} || accepted speedtests are: [ui, cargo, toml, internal]"),
@@ -352,89 +355,10 @@ fn main() {
352355
run_ui_toml();
353356
run_ui_cargo();
354357
run_internal_tests();
355-
rustfix_coverage_known_exceptions_accuracy();
356358
ui_cargo_toml_metadata();
357359
}
358360
}
359361

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