Skip to content

Commit 35d48ea

Browse files
committed
Port clippy away from compiletest to ui_test
1 parent 78e36d9 commit 35d48ea

File tree

14 files changed

+204
-393
lines changed

14 files changed

+204
-393
lines changed

.cargo/config.toml

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
[alias]
22
uitest = "test --test compile-test"
3+
uibless = "test --test compile-test -- -- --bless"
4+
bless = "test -- -- --bless"
35
dev = "run --package clippy_dev --bin clippy_dev --manifest-path clippy_dev/Cargo.toml --"
46
lintcheck = "run --package lintcheck --bin lintcheck --manifest-path lintcheck/Cargo.toml -- "
57
collect-metadata = "test --test dogfood --features internal -- run_metadata_collection_lint --ignored"

Cargo.toml

+5-14
Original file line numberDiff line numberDiff line change
@@ -27,27 +27,14 @@ tempfile = { version = "3.2", optional = true }
2727
termize = "0.1"
2828

2929
[dev-dependencies]
30-
compiletest_rs = { version = "0.10", features = ["tmp"] }
30+
ui_test = "0.11.1"
3131
tester = "0.9"
3232
regex = "1.5"
3333
toml = "0.7.3"
3434
walkdir = "2.3"
3535
# This is used by the `collect-metadata` alias.
3636
filetime = "0.2"
37-
38-
# UI test dependencies
39-
clap = { version = "4.1.4", features = ["derive"] }
40-
clippy_utils = { path = "clippy_utils" }
41-
derive-new = "0.5"
42-
if_chain = "1.0"
4337
itertools = "0.10.1"
44-
quote = "1.0"
45-
serde = { version = "1.0.125", features = ["derive"] }
46-
syn = { version = "2.0", features = ["full"] }
47-
futures = "0.3"
48-
parking_lot = "0.12"
49-
tokio = { version = "1", features = ["io-util"] }
50-
rustc-semver = "1.1"
5138

5239
[build-dependencies]
5340
rustc_tools_util = "0.3.0"
@@ -60,3 +47,7 @@ internal = ["clippy_lints/internal", "tempfile"]
6047
[package.metadata.rust-analyzer]
6148
# This package uses #[feature(rustc_private)]
6249
rustc_private = true
50+
51+
[[test]]
52+
name = "compile-test"
53+
harness = false

book/src/development/adding_lints.md

+7-10
Original file line numberDiff line numberDiff line change
@@ -122,20 +122,17 @@ fn main() {
122122
}
123123
```
124124

125-
Now we can run the test with `TESTNAME=foo_functions cargo uitest`, currently
125+
Now we can run the test with `TESTNAME=foo_functions cargo uibless`, currently
126126
this test is meaningless though.
127127

128128
While we are working on implementing our lint, we can keep running the UI test.
129-
That allows us to check if the output is turning into what we want.
129+
That allows us to check if the output is turning into what we want by checking the
130+
`.stderr` file that gets updated on every test run.
130131

131-
Once we are satisfied with the output, we need to run `cargo dev bless` to
132-
update the `.stderr` file for our lint. Please note that, we should run
133-
`TESTNAME=foo_functions cargo uitest` every time before running `cargo dev
134-
bless`. Running `TESTNAME=foo_functions cargo uitest` should pass then. When we
132+
Running `TESTNAME=foo_functions cargo uitest` should pass on its own. When we
135133
commit our lint, we need to commit the generated `.stderr` files, too. In
136-
general, you should only commit files changed by `cargo dev bless` for the
137-
specific lint you are creating/editing. Note that if the generated files are
138-
empty, they should be removed.
134+
general, you should only commit files changed by `cargo bless` for the
135+
specific lint you are creating/editing.
139136

140137
> _Note:_ you can run multiple test files by specifying a comma separated list:
141138
> `TESTNAME=foo_functions,test2,test3`.
@@ -169,7 +166,7 @@ additionally run [rustfix] for that test. Rustfix will apply the suggestions
169166
from the lint to the code of the test file and compare that to the contents of a
170167
`.fixed` file.
171168

172-
Use `cargo dev bless` to automatically generate the `.fixed` file after running
169+
Use `cargo bless` to automatically generate the `.fixed` file while running
173170
the tests.
174171

175172
[rustfix]: https://github.com/rust-lang/rustfix

book/src/development/basics.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ If the output of a [UI test] differs from the expected output, you can update
6666
the reference file with:
6767

6868
```bash
69-
cargo dev bless
69+
cargo bless
7070
```
7171

7272
For example, this is necessary if you fix a typo in an error message of a lint,

clippy_dev/src/bless.rs

-60
This file was deleted.

clippy_dev/src/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ use std::io;
1414
use std::path::PathBuf;
1515
use std::process::{self, ExitStatus};
1616

17-
pub mod bless;
1817
pub mod dogfood;
1918
pub mod fmt;
2019
pub mod lint;

clippy_dev/src/main.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,16 @@
33
#![warn(rust_2018_idioms, unused_lifetimes)]
44

55
use clap::{Arg, ArgAction, ArgMatches, Command};
6-
use clippy_dev::{bless, dogfood, fmt, lint, new_lint, serve, setup, update_lints};
6+
use clippy_dev::{dogfood, fmt, lint, new_lint, serve, setup, update_lints};
77
use indoc::indoc;
88
use std::convert::Infallible;
99

1010
fn main() {
1111
let matches = get_clap_config();
1212

1313
match matches.subcommand() {
14-
Some(("bless", matches)) => {
15-
bless::bless(matches.get_flag("ignore-timestamp"));
14+
Some(("bless", _)) => {
15+
eprintln!("use `cargo bless` to automatically replace `.stderr` and `.fixed` files as tests are being run");
1616
},
1717
Some(("dogfood", matches)) => {
1818
dogfood::dogfood(

clippy_dev/src/new_lint.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ fn create_test(lint: &LintData<'_>) -> io::Result<()> {
9696

9797
path.push("src");
9898
fs::create_dir(&path)?;
99-
let header = format!("// compile-flags: --crate-name={lint_name}");
99+
let header = format!("//@compile-flags: --crate-name={lint_name}");
100100
write_file(path.join("main.rs"), get_test_file_contents(lint_name, Some(&header)))?;
101101

102102
Ok(())

clippy_test_deps/Cargo.toml

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
[package]
2+
name = "clippy_test_deps"
3+
version = "0.1.0"
4+
edition = "2021"
5+
6+
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
7+
8+
[dependencies]
9+
clap = { version = "4.1.4", features = ["derive"] }
10+
clippy_utils = { path = "../clippy_utils" }
11+
derive-new = "0.5"
12+
if_chain = "1.0"
13+
itertools = "0.10.1"
14+
quote = "1.0"
15+
serde = { version = "1.0.125", features = ["derive"] }
16+
syn = { version = "2.0", features = ["full"] }
17+
futures = "0.3"
18+
parking_lot = "0.12"
19+
tokio = { version = "1", features = ["io-util"] }
20+
rustc-semver = "1.1"
21+
regex = "1.5"
22+
clippy_lints = { path = "../clippy_lints" }
23+
24+
[features]
25+
internal = ["clippy_lints/internal"]

clippy_test_deps/src/lib.rs

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
pub fn add(left: usize, right: usize) -> usize {
2+
left + right
3+
}
4+
5+
#[cfg(test)]
6+
mod tests {
7+
use super::*;
8+
9+
#[test]
10+
fn it_works() {
11+
let result = add(2, 2);
12+
assert_eq!(result, 4);
13+
}
14+
}

clippy_utils/src/lib.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -2397,7 +2397,7 @@ fn with_test_item_names(tcx: TyCtxt<'_>, module: LocalDefId, f: impl Fn(&[Symbol
23972397

23982398
/// Checks if the function containing the given `HirId` is a `#[test]` function
23992399
///
2400-
/// Note: Add `// compile-flags: --test` to UI tests with a `#[test]` function
2400+
/// Note: Add `//@compile-flags: --test` to UI tests with a `#[test]` function
24012401
pub fn is_in_test_function(tcx: TyCtxt<'_>, id: hir::HirId) -> bool {
24022402
with_test_item_names(tcx, tcx.parent_module(id), |names| {
24032403
tcx.hir()
@@ -2419,7 +2419,7 @@ pub fn is_in_test_function(tcx: TyCtxt<'_>, id: hir::HirId) -> bool {
24192419

24202420
/// Checks if the item containing the given `HirId` has `#[cfg(test)]` attribute applied
24212421
///
2422-
/// Note: Add `// compile-flags: --test` to UI tests with a `#[cfg(test)]` function
2422+
/// Note: Add `//@compile-flags: --test` to UI tests with a `#[cfg(test)]` function
24232423
pub fn is_in_cfg_test(tcx: TyCtxt<'_>, id: hir::HirId) -> bool {
24242424
fn is_cfg_test(attr: &Attribute) -> bool {
24252425
if attr.has_name(sym::cfg)
@@ -2441,7 +2441,7 @@ pub fn is_in_cfg_test(tcx: TyCtxt<'_>, id: hir::HirId) -> bool {
24412441
/// Checks whether item either has `test` attribute applied, or
24422442
/// is a module with `test` in its name.
24432443
///
2444-
/// Note: Add `// compile-flags: --test` to UI tests with a `#[test]` function
2444+
/// Note: Add `//@compile-flags: --test` to UI tests with a `#[test]` function
24452445
pub fn is_test_module_or_function(tcx: TyCtxt<'_>, item: &Item<'_>) -> bool {
24462446
is_in_test_function(tcx, item.hir_id())
24472447
|| matches!(item.kind, ItemKind::Mod(..))

0 commit comments

Comments
 (0)