Skip to content

Commit 26ac282

Browse files
committed
auto merge of #1097 : alexcrichton/cargo/dev-deps-for-examples, r=brson
2 parents b460155 + a6dc8ed commit 26ac282

File tree

2 files changed

+40
-2
lines changed

2 files changed

+40
-2
lines changed

src/cargo/ops/cargo_rustc/context.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -284,9 +284,10 @@ impl<'a, 'b: 'a> Context<'a, 'b> {
284284
target.get_profile().is_custom_build() == pkg_dep.is_build();
285285

286286
// If this dependency is *not* a transitive dependency, then it
287-
// only applies to test targets
287+
// only applies to test/example targets
288288
let is_actual_dep = pkg_dep.is_transitive() ||
289-
target.get_profile().is_test();
289+
target.get_profile().is_test() ||
290+
target.is_example();
290291

291292
is_correct_dep && is_actual_dep
292293
}).filter_map(|pkg| {

tests/test_cargo_test.rs

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1273,3 +1273,40 @@ test!(test_with_example_twice {
12731273
execs().with_status(0));
12741274
assert_that(&p.bin("examples/foo"), existing_file());
12751275
});
1276+
1277+
test!(example_with_dev_dep {
1278+
let p = project("foo")
1279+
.file("Cargo.toml", r#"
1280+
[package]
1281+
name = "foo"
1282+
version = "0.0.1"
1283+
authors = []
1284+
1285+
[lib]
1286+
name = "foo"
1287+
test = false
1288+
doctest = false
1289+
1290+
[dev-dependencies.a]
1291+
path = "a"
1292+
"#)
1293+
.file("src/lib.rs", "")
1294+
.file("examples/ex.rs", "extern crate a; fn main() {}")
1295+
.file("a/Cargo.toml", r#"
1296+
[package]
1297+
name = "a"
1298+
version = "0.0.1"
1299+
authors = []
1300+
"#)
1301+
.file("a/src/lib.rs", "");
1302+
1303+
assert_that(p.cargo_process("test").arg("-v"),
1304+
execs().with_status(0)
1305+
.with_stdout(format!("\
1306+
[..]
1307+
[..]
1308+
[..]
1309+
[..]
1310+
{running} `rustc [..] --crate-name ex [..] --extern a=[..]`
1311+
", running = RUNNING).as_slice()));
1312+
});

0 commit comments

Comments
 (0)