From b112255f370a1c1bdfc2ecc484daed0d686f5b4e Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Sun, 22 Mar 2020 10:58:10 -0700 Subject: [PATCH] Fix bug with -Zfeatures=dev_dep and `check --profile=test`. --- src/cargo/ops/cargo_compile.rs | 22 +++++----- tests/testsuite/features2.rs | 77 ++++++++++++++++++++++++++++++++++ 2 files changed, 89 insertions(+), 10 deletions(-) diff --git a/src/cargo/ops/cargo_compile.rs b/src/cargo/ops/cargo_compile.rs index 82d191fb2..f1b0190c2 100644 --- a/src/cargo/ops/cargo_compile.rs +++ b/src/cargo/ops/cargo_compile.rs @@ -608,16 +608,18 @@ impl CompileFilter { pub fn need_dev_deps(&self, mode: CompileMode) -> bool { match mode { CompileMode::Test | CompileMode::Doctest | CompileMode::Bench => true, - CompileMode::Build | CompileMode::Doc { .. } | CompileMode::Check { .. } => match *self - { - CompileFilter::Default { .. } => false, - CompileFilter::Only { - ref examples, - ref tests, - ref benches, - .. - } => examples.is_specific() || tests.is_specific() || benches.is_specific(), - }, + CompileMode::Check { test: true } => true, + CompileMode::Build | CompileMode::Doc { .. } | CompileMode::Check { test: false } => { + match *self { + CompileFilter::Default { .. } => false, + CompileFilter::Only { + ref examples, + ref tests, + ref benches, + .. + } => examples.is_specific() || tests.is_specific() || benches.is_specific(), + } + } CompileMode::RunCustomBuild => panic!("Invalid mode"), } } diff --git a/tests/testsuite/features2.rs b/tests/testsuite/features2.rs index 016826f24..beb950df8 100644 --- a/tests/testsuite/features2.rs +++ b/tests/testsuite/features2.rs @@ -1108,3 +1108,80 @@ fn proc_macro_ws() { .with_stderr_line_without(&["[RUNNING] `rustc --crate-name foo"], &["--cfg[..]feat1"]) .run(); } + +#[cargo_test] +fn has_dev_dep_for_test() { + // Check for a bug where the decision on whether or not "dev dependencies" + // should be used did not consider `check --profile=test`. + let p = project() + .file( + "Cargo.toml", + r#" + [package] + name = "foo" + version = "0.1.0" + + [dev-dependencies] + dep = { path = 'dep', features = ['f1'] } + "#, + ) + .file( + "src/lib.rs", + r#" + #[test] + fn t1() { + dep::f(); + } + "#, + ) + .file( + "dep/Cargo.toml", + r#" + [package] + name = "dep" + version = "0.1.0" + + [features] + f1 = [] + "#, + ) + .file( + "dep/src/lib.rs", + r#" + #[cfg(feature = "f1")] + pub fn f() {} + "#, + ) + .build(); + + p.cargo("check -v") + .with_stderr( + "\ +[CHECKING] foo v0.1.0 [..] +[RUNNING] `rustc --crate-name foo [..] +[FINISHED] [..] +", + ) + .run(); + p.cargo("check -v --profile=test -Zfeatures=dev_dep") + .masquerade_as_nightly_cargo() + .with_stderr( + "\ +[CHECKING] dep v0.1.0 [..] +[RUNNING] `rustc --crate-name dep [..] +[CHECKING] foo v0.1.0 [..] +[RUNNING] `rustc --crate-name foo [..] +[FINISHED] [..] +", + ) + .run(); + p.cargo("check -v --profile=test") + .with_stderr( + "\ +[FRESH] dep [..] +[FRESH] foo [..] +[FINISHED] [..] +", + ) + .run(); +} -- 2.39.5