Skip to content

Commit 4d45a90

Browse files
committed
Auto merge of #6192 - ehuss:test-dep-with-dev, r=alexcrichton
Provide error for testing non-workspaces packages with dev-dependencies. Considering in most cases it just won't work, might as well display a better error message explaining why. Closes #6183, #5156
2 parents 73f9f4a + 786848a commit 4d45a90

File tree

2 files changed

+51
-0
lines changed

2 files changed

+51
-0
lines changed

src/cargo/ops/cargo_compile.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,17 @@ pub fn compile_ws<'a>(
255255

256256
for pkg in to_builds.iter() {
257257
pkg.manifest().print_teapot(ws.config());
258+
259+
if build_config.mode.is_any_test()
260+
&& !ws.is_member(pkg)
261+
&& pkg.dependencies().iter().any(|dep| !dep.is_transitive())
262+
{
263+
bail!(
264+
"package `{}` cannot be tested because it requires dev-dependencies \
265+
and is not a member of the workspace",
266+
pkg.name()
267+
);
268+
}
258269
}
259270

260271
let (extra_args, extra_args_name) = match (target_rustc_args, target_rustdoc_args) {

tests/testsuite/test.rs

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3182,3 +3182,43 @@ fn test_all_targets_lib() {
31823182
",
31833183
).run();
31843184
}
3185+
3186+
3187+
#[test]
3188+
fn test_dep_with_dev() {
3189+
Package::new("devdep", "0.1.0").publish();
3190+
let p = project()
3191+
.file(
3192+
"Cargo.toml",
3193+
r#"
3194+
[package]
3195+
name = "foo"
3196+
version = "0.0.1"
3197+
3198+
[dependencies]
3199+
bar = { path = "bar" }
3200+
"#,
3201+
)
3202+
.file("src/lib.rs", "")
3203+
.file(
3204+
"bar/Cargo.toml",
3205+
r#"
3206+
[package]
3207+
name = "bar"
3208+
version = "0.0.1"
3209+
3210+
[dev-dependencies]
3211+
devdep = "0.1"
3212+
"#,
3213+
)
3214+
.file("bar/src/lib.rs", "")
3215+
.build();
3216+
3217+
p.cargo("test -p bar")
3218+
.with_status(101)
3219+
.with_stderr(
3220+
"[ERROR] package `bar` cannot be tested because it requires dev-dependencies \
3221+
and is not a member of the workspace",
3222+
)
3223+
.run();
3224+
}

0 commit comments

Comments
 (0)