Skip to content

Commit baca68e

Browse files
committed
Auto merge of #13880 - Muscraft:refactor-cargo-lint-tests, r=weihanglo
Refactor cargo lint tests In #13621, it was brought up that [the lints tests are nested more deeply than other UI tests](#13621 (comment)). This got me wondering if there was a better way to structure all the lint tests. What I came up with was: - Lints should not have UI tests, only parts of the diagnostic system, i.e., how warnings, errors, notes, etc., look - This is because UI tests should focus on parts of the system that make up each lint's output - We can always add UI tests for each lint if desired - All tests related to the linting system should live in `tests/testsuite/lints/` - Tests related to `[lints.cargo]` should stay in `lints_table.rs` as it is for the whole lints table - Each lint will get a file in `lints/` for all of its tests - This makes `lints/mod.rs` smaller and targeted only at tests for the linting system itself - It makes it much easier to know where to place a test
2 parents 7297f0f + b79fd59 commit baca68e

File tree

25 files changed

+793
-914
lines changed

25 files changed

+793
-914
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,36 @@
11
use cargo_test_support::prelude::*;
2-
use cargo_test_support::project;
3-
use cargo_test_support::registry::Package;
4-
use cargo_test_support::{file, str};
2+
use cargo_test_support::str;
3+
use cargo_test_support::{file, project};
54

65
#[cargo_test]
76
fn case() {
8-
Package::new("bar", "0.1.0").publish();
97
let p = project()
108
.file(
119
"Cargo.toml",
1210
r#"
11+
cargo-features = ["test-dummy-unstable"]
12+
1313
[package]
1414
name = "foo"
15-
version = "0.1.0"
16-
edition = "2021"
17-
18-
[dependencies]
19-
bar = { version = "0.1.0", optional = true }
15+
version = "0.0.1"
16+
edition = "2015"
17+
authors = []
18+
im-a-teapot = true
2019
2120
[lints.cargo]
22-
implicit_features = "allow"
23-
"#,
21+
im_a_teapot = "deny"
22+
"#,
2423
)
2524
.file("src/lib.rs", "")
2625
.build();
2726

2827
snapbox::cmd::Command::cargo_ui()
29-
.masquerade_as_nightly_cargo(&["cargo-lints"])
28+
.masquerade_as_nightly_cargo(&["cargo-lints", "test-dummy-unstable"])
3029
.current_dir(p.root())
3130
.arg("check")
3231
.arg("-Zcargo-lints")
3332
.assert()
34-
.success()
33+
.code(101)
3534
.stdout_matches(str![""])
3635
.stderr_matches(file!["stderr.term.svg"]);
3736
}

Diff for: tests/testsuite/lints/error/stderr.term.svg

+41
Loading

Diff for: tests/testsuite/lints/implicit_features.rs

+137
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
use cargo_test_support::project;
2+
use cargo_test_support::registry::Package;
3+
4+
#[cargo_test]
5+
fn default() {
6+
Package::new("bar", "0.1.0").publish();
7+
let p = project()
8+
.file(
9+
"Cargo.toml",
10+
r#"
11+
[package]
12+
name = "foo"
13+
version = "0.1.0"
14+
edition = "2021"
15+
16+
[dependencies]
17+
bar = { version = "0.1.0", optional = true }
18+
"#,
19+
)
20+
.file("src/lib.rs", "")
21+
.build();
22+
23+
p.cargo("check -Zcargo-lints")
24+
.masquerade_as_nightly_cargo(&["cargo-lints"])
25+
.with_stderr(
26+
"\
27+
[UPDATING] [..]
28+
[LOCKING] 2 packages to latest compatible versions
29+
[CHECKING] foo v0.1.0 ([CWD])
30+
[FINISHED] [..]
31+
",
32+
)
33+
.run();
34+
}
35+
36+
#[cargo_test]
37+
fn warn() {
38+
Package::new("bar", "0.1.0").publish();
39+
Package::new("baz", "0.1.0").publish();
40+
Package::new("target-dep", "0.1.0").publish();
41+
let p = project()
42+
.file(
43+
"Cargo.toml",
44+
r#"
45+
[package]
46+
name = "foo"
47+
version = "0.1.0"
48+
edition = "2021"
49+
50+
[dependencies]
51+
bar = { version = "0.1.0", optional = true }
52+
53+
[build-dependencies]
54+
baz = { version = "0.1.0", optional = true }
55+
56+
[target.'cfg(target_os = "linux")'.dependencies]
57+
target-dep = { version = "0.1.0", optional = true }
58+
59+
[lints.cargo]
60+
implicit_features = "warn"
61+
"#,
62+
)
63+
.file("src/lib.rs", "")
64+
.build();
65+
66+
p.cargo("check -Zcargo-lints")
67+
.masquerade_as_nightly_cargo(&["cargo-lints"])
68+
.with_stderr(
69+
"\
70+
warning: implicit features for optional dependencies is deprecated and will be unavailable in the 2024 edition
71+
--> Cargo.toml:8:1
72+
|
73+
8 | bar = { version = \"0.1.0\", optional = true }
74+
| ---
75+
|
76+
= note: `cargo::implicit_features` is set to `warn` in `[lints]`
77+
warning: implicit features for optional dependencies is deprecated and will be unavailable in the 2024 edition
78+
--> Cargo.toml:11:1
79+
|
80+
11 | baz = { version = \"0.1.0\", optional = true }
81+
| ---
82+
|
83+
warning: implicit features for optional dependencies is deprecated and will be unavailable in the 2024 edition
84+
--> Cargo.toml:14:1
85+
|
86+
14 | target-dep = { version = \"0.1.0\", optional = true }
87+
| ----------
88+
|
89+
[UPDATING] [..]
90+
[LOCKING] 4 packages to latest compatible versions
91+
[CHECKING] foo v0.1.0 ([CWD])
92+
[FINISHED] [..]
93+
",
94+
)
95+
.run();
96+
}
97+
98+
#[cargo_test(nightly, reason = "edition2024 is not stable")]
99+
fn implicit_features_edition_2024() {
100+
Package::new("bar", "0.1.0").publish();
101+
Package::new("baz", "0.1.0").publish();
102+
let p = project()
103+
.file(
104+
"Cargo.toml",
105+
r#"
106+
cargo-features = ["edition2024"]
107+
[package]
108+
name = "foo"
109+
version = "0.1.0"
110+
edition = "2024"
111+
112+
[dependencies]
113+
bar = { version = "0.1.0", optional = true }
114+
baz = { version = "0.1.0", optional = true }
115+
116+
[features]
117+
baz = ["dep:baz"]
118+
119+
[lints.cargo]
120+
unused_optional_dependency = "allow"
121+
"#,
122+
)
123+
.file("src/lib.rs", "")
124+
.build();
125+
126+
p.cargo("check -Zcargo-lints")
127+
.masquerade_as_nightly_cargo(&["cargo-lints", "edition2024"])
128+
.with_stderr(
129+
"\
130+
[UPDATING] [..]
131+
[LOCKING] 2 packages to latest Rust [..] compatible versions
132+
[CHECKING] foo v0.1.0 ([CWD])
133+
[FINISHED] [..]
134+
",
135+
)
136+
.run();
137+
}

Diff for: tests/testsuite/lints/implicit_features/edition_2021/mod.rs

-32
This file was deleted.

Diff for: tests/testsuite/lints/implicit_features/edition_2021/stderr.term.svg

-33
This file was deleted.

Diff for: tests/testsuite/lints/implicit_features/edition_2021_warn/mod.rs

-45
This file was deleted.

0 commit comments

Comments
 (0)