Add some more tests.
authorEric Huss <eric@huss.org>
Sun, 22 Apr 2018 00:21:42 +0000 (17:21 -0700)
committerEric Huss <eric@huss.org>
Fri, 27 Apr 2018 20:42:30 +0000 (13:42 -0700)
tests/testsuite/cargotest/support/mod.rs
tests/testsuite/profile_overrides.rs
tests/testsuite/rustc.rs
tests/testsuite/test.rs

index f51ea4384aa9556adec7939712e1b2115c7c3e8c..4ae3aeabc51bf1b75babb6e4b7afc1910a6362ff 100644 (file)
@@ -9,26 +9,28 @@ use std::process::Output;
 use std::str;
 use std::usize;
 
-use serde_json::{self, Value};
-use url::Url;
-use hamcrest as ham;
 use cargo::util::ProcessBuilder;
 use cargo::util::ProcessError;
+use hamcrest as ham;
+use serde_json::{self, Value};
+use url::Url;
 
 use cargotest::support::paths::CargoPathExt;
 
 macro_rules! t {
-    ($e:expr) => (match $e {
-        Ok(e) => e,
-        Err(e) => panic!("{} failed with {}", stringify!($e), e),
-    })
+    ($e:expr) => {
+        match $e {
+            Ok(e) => e,
+            Err(e) => panic!("{} failed with {}", stringify!($e), e),
+        }
+    };
 }
 
-pub mod paths;
-pub mod git;
-pub mod registry;
 pub mod cross_compile;
+pub mod git;
+pub mod paths;
 pub mod publish;
+pub mod registry;
 
 /*
  *
@@ -588,7 +590,10 @@ impl Execs {
         if let Some(ref objects) = self.expect_json {
             let stdout = str::from_utf8(&actual.stdout)
                 .map_err(|_| "stdout was not utf8 encoded".to_owned())?;
-            let lines = stdout.lines().collect::<Vec<_>>();
+            let lines = stdout
+                .lines()
+                .filter(|line| line.starts_with("{"))
+                .collect::<Vec<_>>();
             if lines.len() != objects.len() {
                 return Err(format!(
                     "expected {} json lines, got {}, stdout:\n{}",
@@ -744,8 +749,11 @@ impl Execs {
                     };
                 }
                 if a.len() > 0 {
-                    Err(format!("Output included extra lines:\n\
-                        {}\n", a.join("\n")))
+                    Err(format!(
+                        "Output included extra lines:\n\
+                         {}\n",
+                        a.join("\n")
+                    ))
                 } else {
                     Ok(())
                 }
index 458e9e057eed9e3aeedc6029988d4bae28e039bc..59a61616dd4b00e857d87bcb30ca416ec21aeeb4 100644 (file)
@@ -232,3 +232,114 @@ fn profile_override_bad_settings() {
         );
     }
 }
+
+#[test]
+fn profile_override_hierarchy() {
+    // Test that the precedence rules are correct for different types.
+    let p = project("foo")
+        .file(
+            "Cargo.toml",
+            r#"
+            cargo-features = ["profile-overrides"]
+
+            [workspace]
+            members = ["m1", "m2", "m3"]
+
+            [profile.dev]
+            codegen-units = 1
+
+            [profile.dev.overrides.m2]
+            codegen-units = 2
+
+            [profile.dev.overrides."*"]
+            codegen-units = 3
+
+            [profile.dev.build-override]
+            codegen-units = 4
+            "#)
+
+        // m1
+        .file("m1/Cargo.toml",
+            r#"
+            [package]
+            name = "m1"
+            version = "0.0.1"
+
+            [dependencies]
+            m2 = { path = "../m2" }
+            dep = { path = "../../dep" }
+            "#)
+        .file("m1/src/lib.rs",
+            r#"
+            extern crate m2;
+            extern crate dep;
+            "#)
+        .file("m1/build.rs",
+            r#"fn main() {}"#)
+
+        // m2
+        .file("m2/Cargo.toml",
+            r#"
+            [package]
+            name = "m2"
+            version = "0.0.1"
+
+            [dependencies]
+            m3 = { path = "../m3" }
+
+            [build-dependencies]
+            m3 = { path = "../m3" }
+            dep = { path = "../../dep" }
+            "#)
+        .file("m2/src/lib.rs",
+            r#"
+            extern crate m3;
+            "#)
+        .file("m2/build.rs",
+            r#"
+            extern crate m3;
+            extern crate dep;
+            fn main() {}
+            "#)
+
+        // m3
+        .file("m3/Cargo.toml", &basic_lib_manifest("m3"))
+        .file("m3/src/lib.rs", "")
+        .build();
+
+    // dep (outside of workspace)
+    let _dep = project("dep")
+        .file("Cargo.toml", &basic_lib_manifest("dep"))
+        .file("src/lib.rs", "")
+        .build();
+
+    // Profiles should be:
+    // m3: 4 (as build.rs dependency)
+    // m3: 1 (as [profile.dev] as workspace member)
+    // dep: 3 (as [profile.dev.overrides."*"] as non-workspace member)
+    // m1 build.rs: 4 (as [profile.dev.build-override])
+    // m2 build.rs: 2 (as [profile.dev.overrides.m2])
+    // m2: 2 (as [profile.dev.overrides.m2])
+    // m1: 1 (as [profile.dev])
+
+    assert_that(
+        p.cargo("build -v").masquerade_as_nightly_cargo(),
+        execs().with_status(0).with_stderr_unordered("\
+[COMPILING] m3 [..]
+[COMPILING] dep [..]
+[RUNNING] `rustc --crate-name m3 m3[/]src[/]lib.rs --crate-type lib --emit=dep-info,link -C codegen-units=4 [..]
+[RUNNING] `rustc --crate-name dep [..]dep[/]src[/]lib.rs --crate-type lib --emit=dep-info,link -C codegen-units=3 [..]
+[RUNNING] `rustc --crate-name m3 m3[/]src[/]lib.rs --crate-type lib --emit=dep-info,link -C codegen-units=1 [..]
+[RUNNING] `rustc --crate-name build_script_build m1[/]build.rs --crate-type bin --emit=dep-info,link -C codegen-units=4 [..]
+[COMPILING] m2 [..]
+[RUNNING] `rustc --crate-name build_script_build m2[/]build.rs --crate-type bin --emit=dep-info,link -C codegen-units=2 [..]
+[RUNNING] `[..][/]m1-[..][/]build-script-build`
+[RUNNING] `[..][/]m2-[..][/]build-script-build`
+[RUNNING] `rustc --crate-name m2 m2[/]src[/]lib.rs --crate-type lib --emit=dep-info,link -C codegen-units=2 [..]
+[COMPILING] m1 [..]
+[RUNNING] `rustc --crate-name m1 m1[/]src[/]lib.rs --crate-type lib --emit=dep-info,link -C codegen-units=1 [..]
+[FINISHED] dev [unoptimized + debuginfo] [..]
+",
+        ),
+    );
+}
index dd7d51b50a2167b49035ca77214e6ecf59e00df0..95691b8dfb163efd0488bd042440517db352558c 100644 (file)
@@ -1,4 +1,4 @@
-use cargotest::support::{execs, project};
+use cargotest::support::{basic_lib_manifest, execs, project};
 use hamcrest::assert_that;
 
 const CARGO_RUSTC_ERROR: &'static str =
@@ -595,3 +595,57 @@ fn rustc_with_other_profile() {
         execs().with_status(0),
     );
 }
+
+#[test]
+fn rustc_fingerprint() {
+    // Verify that the fingerprint includes the rustc args.
+    let p = project("foo")
+        .file("Cargo.toml", &basic_lib_manifest("foo"))
+        .file("src/lib.rs", "")
+        .build();
+
+    assert_that(
+        p.cargo("rustc -v -- -C debug-assertions"),
+        execs().with_status(0).with_stderr(
+            "\
+[COMPILING] foo [..]
+[RUNNING] `rustc [..]-C debug-assertions [..]
+[FINISHED] [..]
+",
+        ),
+    );
+
+    assert_that(
+        p.cargo("rustc -v -- -C debug-assertions"),
+        execs().with_status(0).with_stderr(
+            "\
+[FRESH] foo [..]
+[FINISHED] [..]
+",
+        ),
+    );
+
+    assert_that(
+        p.cargo("rustc -v"),
+        execs()
+            .with_status(0)
+            .with_stderr_does_not_contain("-C debug-assertions")
+            .with_stderr(
+                "\
+[COMPILING] foo [..]
+[RUNNING] `rustc [..]
+[FINISHED] [..]
+",
+            ),
+    );
+
+    assert_that(
+        p.cargo("rustc -v"),
+        execs().with_status(0).with_stderr(
+            "\
+[FRESH] foo [..]
+[FINISHED] [..]
+",
+        ),
+    );
+}
index 925aa3b55aaefeefbb44cfcc14983e6919b2d12c..315e886c50619ca6e27ae77f23c8c1fc0f2a6458 100644 (file)
@@ -3,12 +3,12 @@ use std::io::prelude::*;
 use std::str;
 
 use cargo;
-use cargotest::{is_nightly, rustc_host, sleep_ms};
-use cargotest::support::{basic_bin_manifest, basic_lib_manifest, cargo_exe, execs, project};
+use cargo::util::process;
 use cargotest::support::paths::CargoPathExt;
 use cargotest::support::registry::Package;
+use cargotest::support::{basic_bin_manifest, basic_lib_manifest, cargo_exe, execs, project};
+use cargotest::{is_nightly, rustc_host, sleep_ms};
 use hamcrest::{assert_that, existing_file, is_not};
-use cargo::util::process;
 
 #[test]
 fn cargo_test_simple() {
@@ -3975,3 +3975,72 @@ fn test_hint_workspace() {
             .with_status(101),
     );
 }
+
+#[test]
+fn json_artifact_includes_test_flag() {
+    // Verify that the JSON artifact output includes `test` flag.
+    let p = project("foo")
+        .file(
+            "Cargo.toml",
+            r#"
+            [package]
+            name = "foo"
+            version = "0.0.1"
+            authors = []
+
+            [profile.test]
+            opt-level = 1
+        "#,
+        )
+        .file("src/lib.rs", "")
+        .build();
+
+    assert_that(
+        p.cargo("test -v --message-format=json"),
+        execs().with_status(0).with_json(
+            r#"
+    {
+        "reason":"compiler-artifact",
+        "profile": {
+            "debug_assertions": true,
+            "debuginfo": 2,
+            "opt_level": "0",
+            "overflow_checks": true,
+            "test": false
+        },
+        "features": [],
+        "package_id":"foo 0.0.1 ([..])",
+        "target":{
+            "kind":["lib"],
+            "crate_types":["lib"],
+            "name":"foo",
+            "src_path":"[..]lib.rs"
+        },
+        "filenames":["[..].rlib"],
+        "fresh": false
+    }
+
+    {
+        "reason":"compiler-artifact",
+        "profile": {
+            "debug_assertions": true,
+            "debuginfo": 2,
+            "opt_level": "1",
+            "overflow_checks": true,
+            "test": true
+        },
+        "features": [],
+        "package_id":"foo 0.0.1 ([..])",
+        "target":{
+            "kind":["lib"],
+            "crate_types":["lib"],
+            "name":"foo",
+            "src_path":"[..]lib.rs"
+        },
+        "filenames":["[..][/]foo-[..]"],
+        "fresh": false
+    }
+"#,
+        ),
+    );
+}