From: Eric Huss Date: Sat, 21 Apr 2018 02:43:57 +0000 (-0700) Subject: Minor tweaks on how examples are handled with tests, and some panic propagation. X-Git-Tag: archive/raspbian/0.35.0-2+rpi1~3^2^2^2^2^2^2^2~22^2~1^2~41^2~15 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=7dc9e071c77965d8d9326a311123d6c1c9dbfbcf;p=cargo.git Minor tweaks on how examples are handled with tests, and some panic propagation. --- diff --git a/src/cargo/core/compiler/fingerprint.rs b/src/cargo/core/compiler/fingerprint.rs index e41f546f4..b71b47d85 100644 --- a/src/cargo/core/compiler/fingerprint.rs +++ b/src/cargo/core/compiler/fingerprint.rs @@ -764,7 +764,7 @@ fn filename<'a, 'cfg>(cx: &mut Context<'a, 'cfg>, unit: &Unit<'a>) -> String { TargetKind::Bench => "bench", TargetKind::CustomBuild => "build-script", }; - let flavor = if unit.mode.is_any_test() && !unit.mode.is_check() { + let flavor = if unit.mode.is_any_test() { "test-" } else if unit.mode.is_doc() { "doc-" diff --git a/src/cargo/core/manifest.rs b/src/cargo/core/manifest.rs index da7269c5f..e8c111808 100644 --- a/src/cargo/core/manifest.rs +++ b/src/cargo/core/manifest.rs @@ -472,6 +472,7 @@ impl Target { kind, name: name.to_string(), required_features, + tested: false, benched: false, ..Target::with_path(src_path) } diff --git a/src/cargo/ops/cargo_compile.rs b/src/cargo/ops/cargo_compile.rs index 6025b2932..6ff4cc01a 100644 --- a/src/cargo/ops/cargo_compile.rs +++ b/src/cargo/ops/cargo_compile.rs @@ -339,7 +339,7 @@ pub fn compile_ws<'a>( .into_path_unlocked(); let mut build_config = BuildConfig::new(config, jobs, &target, Some(rustc_info_cache))?; build_config.release = release; - build_config.test = mode == CompileMode::Test; + build_config.test = mode == CompileMode::Test || mode == CompileMode::Bench; build_config.json_messages = message_format == MessageFormat::Json; let default_arch_kind = if build_config.requested_target.is_some() { Kind::Target @@ -571,12 +571,13 @@ fn generate_targets<'a>( // Helper for creating a Unit struct. let new_unit = |pkg: &'a Package, target: &'a Target, target_mode: CompileMode| { - let profile_for = if mode == CompileMode::Test { + let profile_for = if mode.is_any_test() { // NOTE: The ProfileFor here is subtle. If you have a profile - // with `panic` set, the `panic` flag is cleared for tests and - // their dependencies. If we left this as an "Any" profile, - // then the lib would get compiled three times (once with - // panic, once without, and once with --test). + // with `panic` set, the `panic` flag is cleared for + // tests/benchmarks and their dependencies. If we left this + // as an "Any" profile, then the lib would get compiled three + // times (once with panic, once without, and once with + // --test). // // This would cause a problem for Doc tests, which would fail // because `rustdoc` would attempt to link with both libraries @@ -793,7 +794,7 @@ fn resolve_all_features( fn generate_default_targets(targets: &[Target], mode: CompileMode) -> Vec<&Target> { match mode { CompileMode::Bench => targets.iter().filter(|t| t.benched()).collect(), - CompileMode::Test => targets.iter().filter(|t| t.tested()).collect(), + CompileMode::Test => targets.iter().filter(|t| t.tested() || t.is_example()).collect(), CompileMode::Build | CompileMode::Check { .. } => targets .iter() .filter(|t| t.is_bin() || t.is_lib()) diff --git a/tests/testsuite/check.rs b/tests/testsuite/check.rs index 8e3667c2a..d9ecfb5c8 100644 --- a/tests/testsuite/check.rs +++ b/tests/testsuite/check.rs @@ -747,14 +747,13 @@ fn check_filters() { .with_stderr_contains("[..] --crate-name foo src[/]lib.rs [..] --test [..]") .with_stderr_contains("[..] --crate-name foo src[/]lib.rs --crate-type lib [..]") .with_stderr_contains("[..] --crate-name foo src[/]main.rs [..] --test [..]") - // .with_stderr_contains("[..] --crate-name foo src[/]main.rs --crate-type bin [..]") .with_stderr_contains("[..]unused_unit_lib[..]") .with_stderr_contains("[..]unused_unit_bin[..]") .with_stderr_contains("[..]unused_normal_lib[..]") .with_stderr_contains("[..]unused_normal_bin[..]") .with_stderr_contains("[..]unused_unit_t1[..]") - .with_stderr_contains("[..]unused_normal_ex1[..]") - .with_stderr_contains("[..]unused_unit_ex1[..]") + .with_stderr_does_not_contain("[..]unused_normal_ex1[..]") + .with_stderr_does_not_contain("[..]unused_unit_ex1[..]") .with_stderr_does_not_contain("[..]unused_normal_b1[..]") .with_stderr_does_not_contain("[..]unused_unit_b1[..]"), // with_stderr_does_not_contain --crate-type lib @@ -789,7 +788,7 @@ fn check_filters() { .with_stderr_contains("[..]unused_unit_t1[..]") .with_stderr_contains("[..]unused_unit_lib[..]") .with_stderr_contains("[..]unused_unit_bin[..]") - .with_stderr_contains("[..]unused_unit_ex1[..]"), + .with_stderr_does_not_contain("[..]unused_unit_ex1[..]"), ); }