Skip to content

Commit a38d44c

Browse files
committed
test(features): Show typoed feature behavior
1 parent a1c4644 commit a38d44c

File tree

1 file changed

+82
-0
lines changed

1 file changed

+82
-0
lines changed

tests/testsuite/features.rs

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,38 @@ Caused by:
3636
.run();
3737
}
3838

39+
#[cargo_test]
40+
fn feature_activates_typoed_feature() {
41+
let p = project()
42+
.file(
43+
"Cargo.toml",
44+
r#"
45+
[package]
46+
name = "foo"
47+
version = "0.0.1"
48+
edition = "2015"
49+
authors = []
50+
51+
[features]
52+
bar = ["baz"]
53+
jaz = []
54+
"#,
55+
)
56+
.file("src/main.rs", "")
57+
.build();
58+
59+
p.cargo("check")
60+
.with_status(101)
61+
.with_stderr_data(str![[r#"
62+
[ERROR] failed to parse manifest at `[ROOT]/foo/Cargo.toml`
63+
64+
Caused by:
65+
feature `bar` includes `baz` which is neither a dependency nor another feature
66+
67+
"#]])
68+
.run();
69+
}
70+
3971
#[cargo_test]
4072
fn empty_feature_name() {
4173
let p = project()
@@ -202,6 +234,56 @@ failed to select a version for `bar` which could resolve this conflict
202234
.run();
203235
}
204236

237+
#[cargo_test]
238+
fn dependency_activates_typoed_feature() {
239+
let p = project()
240+
.file(
241+
"Cargo.toml",
242+
r#"
243+
[package]
244+
name = "foo"
245+
version = "0.0.1"
246+
edition = "2015"
247+
authors = []
248+
249+
[dependencies.bar]
250+
path = "bar"
251+
features = ["bar"]
252+
"#,
253+
)
254+
.file("src/main.rs", "")
255+
.file(
256+
"bar/Cargo.toml",
257+
r#"
258+
[package]
259+
name = "bar"
260+
version = "0.0.1"
261+
edition = "2015"
262+
authors = []
263+
264+
[features]
265+
baz = []
266+
"#,
267+
)
268+
.file("bar/src/lib.rs", "")
269+
.build();
270+
271+
p.cargo("check")
272+
.with_status(101)
273+
.with_stderr_data(str![[r#"
274+
[ERROR] failed to select a version for `bar`.
275+
... required by package `foo v0.0.1 ([ROOT]/foo)`
276+
versions that meet the requirements `*` are: 0.0.1
277+
278+
the package `foo` depends on `bar`, with features: `bar` but `bar` does not have these features.
279+
280+
281+
failed to select a version for `bar` which could resolve this conflict
282+
283+
"#]])
284+
.run();
285+
}
286+
205287
#[cargo_test]
206288
fn optional_dev_dependency() {
207289
let p = project()

0 commit comments

Comments
 (0)