]> git.proxmox.com Git - cargo.git/commitdiff
Add tests for namespaced features
authorDirkjan Ochtman <dirkjan@ochtman.nl>
Wed, 18 Apr 2018 10:12:43 +0000 (12:12 +0200)
committerDirkjan Ochtman <dirkjan@ochtman.nl>
Sat, 28 Apr 2018 11:41:18 +0000 (13:41 +0200)
tests/testsuite/features.rs

index 42493b9b68a72a9890bf06f83daf6ad5706fa0e8..f65644b3dc4b525bae743eebe6d9aa470938de2d 100644 (file)
@@ -1714,3 +1714,262 @@ fn combining_features_and_package() {
         execs().with_status(0),
     );
 }
+
+#[test]
+fn namespaced_invalid_feature() {
+    let p = project("foo")
+        .file(
+            "Cargo.toml",
+            r#"
+            [project]
+            name = "foo"
+            version = "0.0.1"
+            authors = []
+            namespaced-features = true
+
+            [features]
+            bar = ["baz"]
+        "#,
+        )
+        .file("src/main.rs", "")
+        .build();
+
+    assert_that(
+        p.cargo("build"),
+        execs().with_status(101).with_stderr(
+            "\
+[ERROR] failed to parse manifest at `[..]`
+
+Caused by:
+  Feature `bar` includes `baz` which is not defined as a feature
+",
+        ),
+    );
+}
+
+#[test]
+fn namespaced_invalid_dependency() {
+    let p = project("foo")
+        .file(
+            "Cargo.toml",
+            r#"
+            [project]
+            name = "foo"
+            version = "0.0.1"
+            authors = []
+            namespaced-features = true
+
+            [features]
+            bar = ["crate:baz"]
+        "#,
+        )
+        .file("src/main.rs", "")
+        .build();
+
+    assert_that(
+        p.cargo("build"),
+        execs().with_status(101).with_stderr(
+            "\
+[ERROR] failed to parse manifest at `[..]`
+
+Caused by:
+  Feature `bar` includes `crate:baz` which is not a known dependency
+",
+        ),
+    );
+}
+
+#[test]
+fn namespaced_non_optional_dependency() {
+    let p = project("foo")
+        .file(
+            "Cargo.toml",
+            r#"
+            [project]
+            name = "foo"
+            version = "0.0.1"
+            authors = []
+            namespaced-features = true
+
+            [features]
+            bar = ["crate:baz"]
+
+            [dependencies]
+            baz = "0.1"
+        "#,
+        )
+        .file("src/main.rs", "")
+        .build();
+
+    assert_that(
+        p.cargo("build"),
+        execs().with_status(101).with_stderr(
+            "\
+[ERROR] failed to parse manifest at `[..]`
+
+Caused by:
+  Feature `bar` includes `crate:baz` which is not an optional dependency.
+Consider adding `optional = true` to the dependency
+",
+        ),
+    );
+}
+
+#[test]
+fn namespaced_implicit_feature() {
+    let p = project("foo")
+        .file(
+            "Cargo.toml",
+            r#"
+            [project]
+            name = "foo"
+            version = "0.0.1"
+            authors = []
+            namespaced-features = true
+
+            [features]
+            bar = ["baz"]
+
+            [dependencies]
+            baz = { version = "0.1", optional = true }
+        "#,
+        )
+        .file("src/main.rs", "fn main() {}")
+        .build();
+
+    assert_that(p.cargo("build"), execs().with_status(0));
+}
+
+#[test]
+fn namespaced_shadowed_dep() {
+    let p = project("foo")
+        .file(
+            "Cargo.toml",
+            r#"
+            [project]
+            name = "foo"
+            version = "0.0.1"
+            authors = []
+            namespaced-features = true
+
+            [features]
+            baz = []
+
+            [dependencies]
+            baz = { version = "0.1", optional = true }
+        "#,
+        )
+        .file("src/main.rs", "fn main() {}")
+        .build();
+
+    assert_that(
+        p.cargo("build"),
+        execs().with_status(101).with_stderr(
+            "\
+[ERROR] failed to parse manifest at `[..]`
+
+Caused by:
+  Feature `baz` includes the optional dependency of the same name, but this is left implicit in the features included by this feature.
+Consider adding `crate:baz` to this feature's requirements.
+",
+        ),
+    );
+}
+
+#[test]
+fn namespaced_shadowed_non_optional() {
+    let p = project("foo")
+        .file(
+            "Cargo.toml",
+            r#"
+            [project]
+            name = "foo"
+            version = "0.0.1"
+            authors = []
+            namespaced-features = true
+
+            [features]
+            baz = []
+
+            [dependencies]
+            baz = "0.1"
+        "#,
+        )
+        .file("src/main.rs", "fn main() {}")
+        .build();
+
+    assert_that(
+        p.cargo("build"),
+        execs().with_status(101).with_stderr(
+            "\
+[ERROR] failed to parse manifest at `[..]`
+
+Caused by:
+  Feature `baz` includes the dependency of the same name, but this is left implicit in the features included by this feature.
+Additionally, the dependency must be marked as optional to be included in the feature definition.
+Consider adding `crate:baz` to this feature's requirements and marking the dependency as `optional = true`
+",
+        ),
+    );
+}
+
+#[test]
+fn namespaced_implicit_non_optional() {
+    let p = project("foo")
+        .file(
+            "Cargo.toml",
+            r#"
+            [project]
+            name = "foo"
+            version = "0.0.1"
+            authors = []
+            namespaced-features = true
+
+            [features]
+            bar = ["baz"]
+
+            [dependencies]
+            baz = "0.1"
+        "#,
+        )
+        .file("src/main.rs", "fn main() {}")
+        .build();
+
+    assert_that(
+        p.cargo("build"),
+        execs().with_status(101).with_stderr(
+            "\
+[ERROR] failed to parse manifest at `[..]`
+
+Caused by:
+  Feature `bar` includes `baz` which is not defined as a feature.
+A non-optional dependency of the same name is defined; consider adding `optional = true` to its definition
+",
+        ),
+    );
+}
+
+#[test]
+fn namespaced_same_name() {
+    let p = project("foo")
+        .file(
+            "Cargo.toml",
+            r#"
+            [project]
+            name = "foo"
+            version = "0.0.1"
+            authors = []
+            namespaced-features = true
+
+            [features]
+            baz = ["crate:baz"]
+
+            [dependencies]
+            baz = { version = "0.1", optional = true }
+        "#,
+        )
+        .file("src/main.rs", "fn main() {}")
+        .build();
+
+    assert_that(p.cargo("build"), execs().with_status(0));
+}