Minor tweaks on how examples are handled with tests, and some panic propagation.
authorEric Huss <eric@huss.org>
Sat, 21 Apr 2018 02:43:57 +0000 (19:43 -0700)
committerEric Huss <eric@huss.org>
Fri, 27 Apr 2018 20:42:30 +0000 (13:42 -0700)
src/cargo/core/compiler/fingerprint.rs
src/cargo/core/manifest.rs
src/cargo/ops/cargo_compile.rs
tests/testsuite/check.rs

index e41f546f4ea1169a63444f69f08eb517380499fd..b71b47d859c56af14251f140392b8cdbf2a4ab9e 100644 (file)
@@ -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-"
index da7269c5faa9c00c172d35d83e595a3982b41da5..e8c111808232ddd9538e080c4e3bc2c2edd9e775 100644 (file)
@@ -472,6 +472,7 @@ impl Target {
             kind,
             name: name.to_string(),
             required_features,
+            tested: false,
             benched: false,
             ..Target::with_path(src_path)
         }
index 6025b2932535a2e926cd809de950a80c1a4a3fb0..6ff4cc01a8de93d467d43368ea08a928e7447426 100644 (file)
@@ -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())
index 8e3667c2a880206472e4e1cfd8602d6b715bc4ce..d9ecfb5c8e9ecf824ad4b3f70990f0ce93c3f2f1 100644 (file)
@@ -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[..]"),
     );
 }