From a38d44c2b03b9ef10137a285f8381a55cea35784 Mon Sep 17 00:00:00 2001 From: Ed Page Date: Thu, 24 Apr 2025 16:33:15 -0500 Subject: [PATCH] test(features): Show typoed feature behavior --- tests/testsuite/features.rs | 82 +++++++++++++++++++++++++++++++++++++ 1 file changed, 82 insertions(+) diff --git a/tests/testsuite/features.rs b/tests/testsuite/features.rs index 37d7a4127..7d9d61208 100644 --- a/tests/testsuite/features.rs +++ b/tests/testsuite/features.rs @@ -36,6 +36,38 @@ Caused by: .run(); } +#[cargo_test] +fn feature_activates_typoed_feature() { + let p = project() + .file( + "Cargo.toml", + r#" + [package] + name = "foo" + version = "0.0.1" + edition = "2015" + authors = [] + + [features] + bar = ["baz"] + jaz = [] + "#, + ) + .file("src/main.rs", "") + .build(); + + p.cargo("check") + .with_status(101) + .with_stderr_data(str![[r#" +[ERROR] failed to parse manifest at `[ROOT]/foo/Cargo.toml` + +Caused by: + feature `bar` includes `baz` which is neither a dependency nor another feature + +"#]]) + .run(); +} + #[cargo_test] fn empty_feature_name() { let p = project() @@ -202,6 +234,56 @@ failed to select a version for `bar` which could resolve this conflict .run(); } +#[cargo_test] +fn dependency_activates_typoed_feature() { + let p = project() + .file( + "Cargo.toml", + r#" + [package] + name = "foo" + version = "0.0.1" + edition = "2015" + authors = [] + + [dependencies.bar] + path = "bar" + features = ["bar"] + "#, + ) + .file("src/main.rs", "") + .file( + "bar/Cargo.toml", + r#" + [package] + name = "bar" + version = "0.0.1" + edition = "2015" + authors = [] + + [features] + baz = [] +"#, + ) + .file("bar/src/lib.rs", "") + .build(); + + p.cargo("check") + .with_status(101) + .with_stderr_data(str![[r#" +[ERROR] failed to select a version for `bar`. + ... required by package `foo v0.0.1 ([ROOT]/foo)` +versions that meet the requirements `*` are: 0.0.1 + +the package `foo` depends on `bar`, with features: `bar` but `bar` does not have these features. + + +failed to select a version for `bar` which could resolve this conflict + +"#]]) + .run(); +} + #[cargo_test] fn optional_dev_dependency() { let p = project()