Add warning if panic is set in test or bench profile.

This commit is contained in:
Eric Huss 2018-04-21 09:40:00 -07:00
parent a0a880c36e
commit 36b8769025
2 changed files with 50 additions and 8 deletions

View 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 {

View 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
"));
}