]> git.proxmox.com Git - cargo.git/commitdiff
Provide error for testing non-workspaces packages with dev-dependencies.
authorEric Huss <eric@huss.org>
Sat, 20 Oct 2018 01:04:36 +0000 (18:04 -0700)
committerEric Huss <eric@huss.org>
Sat, 20 Oct 2018 01:04:36 +0000 (18:04 -0700)
Considering in most cases it just won't work, might as well display
a better error message explaining why.

src/cargo/ops/cargo_compile.rs
tests/testsuite/test.rs

index 56293249f57571033ae7b074ef91bed4cf12f154..54f2c41e829b2fa839ac8fc4037501047c11c4c5 100644 (file)
@@ -255,6 +255,17 @@ pub fn compile_ws<'a>(
 
     for pkg in to_builds.iter() {
         pkg.manifest().print_teapot(ws.config());
+
+        if build_config.mode.is_any_test()
+            && !ws.is_member(pkg)
+            && pkg.dependencies().iter().any(|dep| !dep.is_transitive())
+        {
+            bail!(
+                "package `{}` cannot be tested because it requires dev-dependencies \
+                 and is not a member of the workspace",
+                pkg.name()
+            );
+        }
     }
 
     let (extra_args, extra_args_name) = match (target_rustc_args, target_rustdoc_args) {
index 3de5262801bf6048f2f829f51c0dac1667ed1af1..d3f24e5bf415c4637ea4874dab35c7fdf929d170 100644 (file)
@@ -3182,3 +3182,43 @@ fn test_all_targets_lib() {
 ",
         ).run();
 }
+
+
+#[test]
+fn test_dep_with_dev() {
+    Package::new("devdep", "0.1.0").publish();
+    let p = project()
+        .file(
+            "Cargo.toml",
+            r#"
+            [package]
+            name = "foo"
+            version = "0.0.1"
+
+            [dependencies]
+            bar = { path = "bar" }
+        "#,
+        )
+        .file("src/lib.rs", "")
+        .file(
+            "bar/Cargo.toml",
+            r#"
+            [package]
+            name = "bar"
+            version = "0.0.1"
+
+            [dev-dependencies]
+            devdep = "0.1"
+        "#,
+        )
+        .file("bar/src/lib.rs", "")
+        .build();
+
+    p.cargo("test -p bar")
+        .with_status(101)
+        .with_stderr(
+            "[ERROR] package `bar` cannot be tested because it requires dev-dependencies \
+             and is not a member of the workspace",
+        )
+        .run();
+}