From: Eric Huss Date: Sat, 21 Apr 2018 16:40:00 +0000 (-0700) Subject: Add warning if `panic` is set in test or bench profile. X-Git-Tag: archive/raspbian/0.35.0-2+rpi1~3^2^2^2^2^2^2^2~22^2~1^2~41^2~13 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=36b876902552cce138dbdd97e271c02f77703df6;p=cargo.git Add warning if `panic` is set in test or bench profile. --- diff --git a/src/cargo/util/toml/mod.rs b/src/cargo/util/toml/mod.rs index f101b952f..acd4b0af2 100644 --- a/src/cargo/util/toml/mod.rs +++ b/src/cargo/util/toml/mod.rs @@ -245,21 +245,21 @@ pub struct TomlProfiles { } impl TomlProfiles { - fn validate(&self, features: &Features) -> CargoResult<()> { + fn validate(&self, features: &Features, warnings: &mut Vec) -> 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, + ) -> 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 { diff --git a/tests/testsuite/profiles.rs b/tests/testsuite/profiles.rs index 4e526a932..be5c6b615 100644 --- a/tests/testsuite/profiles.rs +++ b/tests/testsuite/profiles.rs @@ -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 +")); +}