Skip to content

Commit 6f81cff

Browse files
committed
refactor: Move lint specific tests to lints/mod.rs
1 parent c1f0c0b commit 6f81cff

File tree

2 files changed

+327
-324
lines changed

2 files changed

+327
-324
lines changed

tests/testsuite/lints/mod.rs

Lines changed: 327 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,330 @@
1+
use cargo_test_support::project;
2+
use cargo_test_support::registry::Package;
3+
14
mod implicit_features;
25
mod unknown_lints;
36
mod unused_optional_dependencies;
7+
8+
#[cargo_test]
9+
fn dashes_dont_get_rewritten() {
10+
let foo = project()
11+
.file(
12+
"Cargo.toml",
13+
r#"
14+
cargo-features = ["test-dummy-unstable"]
15+
16+
[package]
17+
name = "foo"
18+
version = "0.0.1"
19+
edition = "2015"
20+
authors = []
21+
im-a-teapot = true
22+
23+
[lints.cargo]
24+
im-a-teapot = "warn"
25+
"#,
26+
)
27+
.file("src/lib.rs", "")
28+
.build();
29+
30+
foo.cargo("check -Zcargo-lints")
31+
.masquerade_as_nightly_cargo(&["cargo-lints", "test-dummy-unstable"])
32+
.with_stderr(
33+
"\
34+
warning: unknown lint: `im-a-teapot`
35+
--> Cargo.toml:12:1
36+
|
37+
12 | im-a-teapot = \"warn\"
38+
| ^^^^^^^^^^^
39+
|
40+
= note: `cargo::unknown_lints` is set to `warn` by default
41+
= help: there is a lint with a similar name: `im_a_teapot`
42+
[CHECKING] foo v0.0.1 ([CWD])
43+
[FINISHED] [..]
44+
",
45+
)
46+
.run();
47+
}
48+
49+
#[cargo_test]
50+
fn forbid_not_overridden() {
51+
let p = project()
52+
.file(
53+
"Cargo.toml",
54+
r#"
55+
cargo-features = ["test-dummy-unstable"]
56+
57+
[package]
58+
name = "foo"
59+
version = "0.0.1"
60+
edition = "2015"
61+
authors = []
62+
im-a-teapot = true
63+
64+
[lints.cargo]
65+
im_a_teapot = { level = "warn", priority = 10 }
66+
test_dummy_unstable = { level = "forbid", priority = -1 }
67+
"#,
68+
)
69+
.file("src/lib.rs", "")
70+
.build();
71+
72+
p.cargo("check -Zcargo-lints")
73+
.masquerade_as_nightly_cargo(&["cargo-lints", "test-dummy-unstable"])
74+
.with_status(101)
75+
.with_stderr(
76+
"\
77+
error: `im_a_teapot` is specified
78+
--> Cargo.toml:9:1
79+
|
80+
9 | im-a-teapot = true
81+
| ^^^^^^^^^^^^^^^^^^
82+
|
83+
= note: `cargo::im_a_teapot` is set to `forbid` in `[lints]`
84+
",
85+
)
86+
.run();
87+
}
88+
89+
#[cargo_test]
90+
fn workspace_lints() {
91+
let p = project()
92+
.file(
93+
"Cargo.toml",
94+
r#"
95+
cargo-features = ["test-dummy-unstable"]
96+
97+
[workspace.lints.cargo]
98+
im_a_teapot = { level = "warn", priority = 10 }
99+
test_dummy_unstable = { level = "forbid", priority = -1 }
100+
101+
[package]
102+
name = "foo"
103+
version = "0.0.1"
104+
edition = "2015"
105+
authors = []
106+
im-a-teapot = true
107+
108+
[lints]
109+
workspace = true
110+
"#,
111+
)
112+
.file("src/lib.rs", "")
113+
.build();
114+
115+
p.cargo("check -Zcargo-lints")
116+
.masquerade_as_nightly_cargo(&["cargo-lints", "test-dummy-unstable"])
117+
.with_status(101)
118+
.with_stderr(
119+
"\
120+
error: `im_a_teapot` is specified
121+
--> Cargo.toml:13:1
122+
|
123+
13 | im-a-teapot = true
124+
| ^^^^^^^^^^^^^^^^^^
125+
|
126+
= note: `cargo::im_a_teapot` is set to `forbid` in `[lints]`
127+
",
128+
)
129+
.run();
130+
}
131+
132+
#[cargo_test]
133+
fn dont_always_inherit_workspace_lints() {
134+
let p = project()
135+
.file(
136+
"Cargo.toml",
137+
r#"
138+
[workspace]
139+
members = ["foo"]
140+
141+
[workspace.lints.cargo]
142+
im_a_teapot = "warn"
143+
"#,
144+
)
145+
.file(
146+
"foo/Cargo.toml",
147+
r#"
148+
cargo-features = ["test-dummy-unstable"]
149+
150+
[package]
151+
name = "foo"
152+
version = "0.0.1"
153+
edition = "2015"
154+
authors = []
155+
im-a-teapot = true
156+
"#,
157+
)
158+
.file("foo/src/lib.rs", "")
159+
.build();
160+
161+
p.cargo("check -Zcargo-lints")
162+
.masquerade_as_nightly_cargo(&["cargo-lints"])
163+
.with_stderr(
164+
"\
165+
[CHECKING] foo v0.0.1 ([CWD]/foo)
166+
[FINISHED] [..]
167+
",
168+
)
169+
.run();
170+
}
171+
172+
#[cargo_test]
173+
fn cap_lints() {
174+
Package::new("baz", "0.1.0").publish();
175+
Package::new("bar", "0.1.0")
176+
.file(
177+
"Cargo.toml",
178+
r#"
179+
[package]
180+
name = "bar"
181+
version = "0.1.0"
182+
edition = "2021"
183+
184+
[dependencies]
185+
baz = { version = "0.1.0", optional = true }
186+
187+
[lints.cargo]
188+
implicit_features = "warn"
189+
"#,
190+
)
191+
.file("src/lib.rs", "")
192+
.publish();
193+
let p = project()
194+
.file(
195+
"Cargo.toml",
196+
r#"
197+
[package]
198+
name = "foo"
199+
version = "0.1.0"
200+
edition = "2021"
201+
202+
[dependencies]
203+
bar = "0.1.0"
204+
205+
[lints.cargo]
206+
implicit_features = "warn"
207+
"#,
208+
)
209+
.file("src/lib.rs", "")
210+
.build();
211+
212+
p.cargo("check -Zcargo-lints")
213+
.masquerade_as_nightly_cargo(&["cargo-lints"])
214+
.with_stderr(
215+
"\
216+
[UPDATING] [..]
217+
[LOCKING] 2 packages to latest compatible versions
218+
[DOWNLOADING] crates ...
219+
[DOWNLOADED] bar v0.1.0 ([..])
220+
[CHECKING] bar v0.1.0
221+
[CHECKING] foo v0.1.0 ([CWD])
222+
[FINISHED] [..]
223+
",
224+
)
225+
.run();
226+
}
227+
228+
#[cargo_test]
229+
fn check_feature_gated() {
230+
let p = project()
231+
.file(
232+
"Cargo.toml",
233+
r#"
234+
[package]
235+
name = "foo"
236+
version = "0.0.1"
237+
edition = "2015"
238+
authors = []
239+
240+
[lints.cargo]
241+
im_a_teapot = "warn"
242+
"#,
243+
)
244+
.file("src/lib.rs", "")
245+
.build();
246+
247+
p.cargo("check -Zcargo-lints")
248+
.masquerade_as_nightly_cargo(&["cargo-lints"])
249+
.with_status(101)
250+
.with_stderr(
251+
"\
252+
error: use of unstable lint `im_a_teapot`
253+
--> Cargo.toml:9:1
254+
|
255+
9 | im_a_teapot = \"warn\"
256+
| ^^^^^^^^^^^ this is behind `test-dummy-unstable`, which is not enabled
257+
|
258+
= help: consider adding `cargo-features = [\"test-dummy-unstable\"]` to the top of the manifest
259+
error: encountered 1 errors(s) while verifying lints
260+
",
261+
)
262+
.run();
263+
}
264+
265+
#[cargo_test]
266+
fn check_feature_gated_workspace() {
267+
let p = project()
268+
.file(
269+
"Cargo.toml",
270+
r#"
271+
[workspace]
272+
members = ["foo"]
273+
274+
[workspace.lints.cargo]
275+
im_a_teapot = { level = "warn", priority = 10 }
276+
test_dummy_unstable = { level = "forbid", priority = -1 }
277+
"#,
278+
)
279+
.file(
280+
"foo/Cargo.toml",
281+
r#"
282+
[package]
283+
name = "foo"
284+
version = "0.0.1"
285+
edition = "2015"
286+
authors = []
287+
288+
[lints]
289+
workspace = true
290+
"#,
291+
)
292+
.file("foo/src/lib.rs", "")
293+
.build();
294+
295+
p.cargo("check -Zcargo-lints")
296+
.masquerade_as_nightly_cargo(&["cargo-lints"])
297+
.with_status(101)
298+
.with_stderr(
299+
"\
300+
error: use of unstable lint `im_a_teapot`
301+
--> Cargo.toml:6:1
302+
|
303+
6 | im_a_teapot = { level = \"warn\", priority = 10 }
304+
| ^^^^^^^^^^^ this is behind `test-dummy-unstable`, which is not enabled
305+
|
306+
note: `cargo::im_a_teapot` was inherited
307+
--> foo/Cargo.toml:9:1
308+
|
309+
9 | workspace = true
310+
| ----------------
311+
|
312+
= help: consider adding `cargo-features = [\"test-dummy-unstable\"]` to the top of the manifest
313+
error: use of unstable lint `test_dummy_unstable`
314+
--> Cargo.toml:7:1
315+
|
316+
7 | test_dummy_unstable = { level = \"forbid\", priority = -1 }
317+
| ^^^^^^^^^^^^^^^^^^^ this is behind `test-dummy-unstable`, which is not enabled
318+
|
319+
note: `cargo::test_dummy_unstable` was inherited
320+
--> foo/Cargo.toml:9:1
321+
|
322+
9 | workspace = true
323+
| ----------------
324+
|
325+
= help: consider adding `cargo-features = [\"test-dummy-unstable\"]` to the top of the manifest
326+
error: encountered 2 errors(s) while verifying lints
327+
",
328+
)
329+
.run();
330+
}

0 commit comments

Comments
 (0)