Add warning if `panic` is set in test or bench profile.
authorEric Huss <eric@huss.org>
Sat, 21 Apr 2018 16:40:00 +0000 (09:40 -0700)
committerEric Huss <eric@huss.org>
Fri, 27 Apr 2018 20:42:30 +0000 (13:42 -0700)
src/cargo/util/toml/mod.rs
tests/testsuite/profiles.rs

index f101b952fc7a518e907a63d2c6a778e02eb84878..acd4b0af20827e4ece56601a488960672c65f8ae 100644 (file)
@@ -245,21 +245,21 @@ pub struct TomlProfiles {
 }
 
 impl TomlProfiles {
-    fn validate(&self, features: &Features) -> CargoResult<()> {
+    fn validate(&self, features: &Features, warnings: &mut Vec<String>) -> CargoResult<()> {
         if let Some(ref test) = self.test {
-            test.validate("test", features)?;
+            test.validate("test", features, warnings)?;
         }
         if let Some(ref doc) = self.doc {
-            doc.validate("doc", features)?;
+            doc.validate("doc", features, warnings)?;
         }
         if let Some(ref bench) = self.bench {
-            bench.validate("bench", features)?;
+            bench.validate("bench", features, warnings)?;
         }
         if let Some(ref dev) = self.dev {
-            dev.validate("dev", features)?;
+            dev.validate("dev", features, warnings)?;
         }
         if let Some(ref release) = self.release {
-            release.validate("release", features)?;
+            release.validate("release", features, warnings)?;
         }
         Ok(())
     }
@@ -385,7 +385,12 @@ pub struct TomlProfile {
 }
 
 impl TomlProfile {
-    fn validate(&self, name: &str, features: &Features) -> CargoResult<()> {
+    fn validate(
+        &self,
+        name: &str,
+        features: &Features,
+        warnings: &mut Vec<String>,
+    ) -> CargoResult<()> {
         if let Some(ref profile) = self.build_override {
             features.require(Feature::profile_overrides())?;
             profile.validate_override()?;
@@ -409,6 +414,15 @@ impl TomlProfile {
                 }
             }
         }
+
+        match name {
+            "test" | "bench" => {
+                if self.panic.is_some() {
+                    warnings.push(format!("`panic` setting is ignored for `{}` profile", name))
+                }
+            }
+            _ => {}
+        }
         Ok(())
     }
 
@@ -861,7 +875,7 @@ impl TomlManifest {
             ),
         };
         if let Some(ref profiles) = me.profile {
-            profiles.validate(&features)?;
+            profiles.validate(&features, &mut warnings)?;
         }
         let profiles = build_profiles(&me.profile);
         let publish = match project.publish {
index 4e526a9327454ad52fb52874e6822a3be1186f53..be5c6b615b2f97654f1eb6356d105df6eeacccac 100644 (file)
@@ -482,3 +482,31 @@ Did you mean `bar`?
 [COMPILING] [..]
 "));
 }
+
+#[test]
+fn profile_panic_test_bench() {
+    let p = project("foo")
+        .file(
+            "Cargo.toml",
+            r#"
+            [package]
+            name = "foo"
+            version = "0.0.1"
+
+            [profile.test]
+            panic = "abort"
+
+            [profile.bench]
+            panic = "abort"
+        "#,
+        )
+        .file("src/lib.rs", "")
+        .build();
+
+    assert_that(
+        p.cargo("build"),
+        execs().with_status(0).with_stderr_contains("\
+[WARNING] `panic` setting is ignored for `test` profile
+[WARNING] `panic` setting is ignored for `bench` profile
+"));
+}