Add some tests to check that dev-dependencies are not resolved
authorXimin Luo <infinity0@pwned.gg>
Thu, 15 Feb 2018 15:01:36 +0000 (16:01 +0100)
committerXimin Luo <infinity0@pwned.gg>
Thu, 15 Feb 2018 15:01:36 +0000 (16:01 +0100)
tests/build.rs
tests/install.rs

index 14237e4c9b14e8f82c40ba9d8d5f00e4ce72e5c1..ee09ff0beef7639b7487d688a73c61b345cd1b48 100644 (file)
@@ -4188,3 +4188,24 @@ fn no_linkable_target() {
                 [WARNING] The package `the_lib` provides no linkable [..] \
 while compiling `foo`. [..] in `the_lib`'s Cargo.toml. [..]"));
 }
+
+#[test]
+fn avoid_dev_deps() {
+    Package::new("foo", "1.0.0").publish();
+    let p = project("foo")
+        .file("Cargo.toml", r#"
+            [package]
+            name = "bar"
+            version = "0.1.0"
+            authors = []
+
+            [dev-dependencies]
+            baz = "1.0.0"
+        "#)
+        .file("src/main.rs", "fn main() {}")
+        .build();
+
+    assert_that(p.cargo("build"), execs().with_status(101));
+    assert_that(p.cargo("build").masquerade_as_nightly_cargo()
+                .arg("-Zavoid-dev-deps"), execs().with_status(0));
+}
index 1ae6806c447662beba9a5b3725c9d9bafbdee5b8..14b64c6c62391c5173b6438d3f08cfc9da70152b 100644 (file)
@@ -6,6 +6,7 @@ use std::fs::{self, File, OpenOptions};
 use std::io::prelude::*;
 
 use cargo::util::ProcessBuilder;
+use cargotest::ChannelChanger;
 use cargotest::install::{cargo_home, has_installed_exe};
 use cargotest::support::git;
 use cargotest::support::paths;
@@ -907,6 +908,56 @@ fn use_path_workspace() {
     assert!(lock == lock2, "different lockfiles");
 }
 
+#[test]
+fn dev_dependencies_no_check() {
+    Package::new("foo", "1.0.0").publish();
+    let p = project("foo")
+        .file("Cargo.toml", r#"
+            [package]
+            name = "bar"
+            version = "0.1.0"
+            authors = []
+
+            [dev-dependencies]
+            baz = "1.0.0"
+        "#)
+        .file("src/main.rs", "fn main() {}")
+        .build();
+
+    assert_that(p.cargo("build"), execs().with_status(101));
+    assert_that(p.cargo("install"), execs().with_status(0));
+}
+
+#[test]
+fn dev_dependencies_lock_file_untouched() {
+    Package::new("foo", "1.0.0").publish();
+    let p = project("foo")
+        .file("Cargo.toml", r#"
+            [package]
+            name = "foo"
+            version = "0.1.0"
+            authors = []
+
+            [dev-dependencies]
+            bar = { path = "a" }
+        "#)
+        .file("src/main.rs", "fn main() {}")
+        .file("a/Cargo.toml", r#"
+            [package]
+            name = "bar"
+            version = "0.1.0"
+            authors = []
+        "#)
+        .file("a/src/lib.rs", "")
+        .build();
+
+    assert_that(p.cargo("build"), execs().with_status(0));
+    let lock = p.read_lockfile();
+    assert_that(p.cargo("install"), execs().with_status(0));
+    let lock2 = p.read_lockfile();
+    assert!(lock == lock2, "different lockfiles");
+}
+
 #[test]
 fn vers_precise() {
     pkg("foo", "0.1.1");