Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bug with -Zfeatures=dev_dep and check --profile=test. #8027

Merged
merged 1 commit into from
Mar 23, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 12 additions & 10 deletions src/cargo/ops/cargo_compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
}
}
Expand Down
77 changes: 77 additions & 0 deletions tests/testsuite/features2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}