Skip to content

Commit fc4b033

Browse files
committed
Auto merge of #1283 - alexcrichton:bad-error, r=huonw
Closes rust-lang/crates.io#130
2 parents 0b84923 + 17dc427 commit fc4b033

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

src/cargo/ops/cargo_run.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,16 @@ pub fn run(manifest_path: &Path,
2626
!a.profile().is_custom_build()
2727
});
2828
let bin = try!(bins.next().chain_error(|| {
29-
human("a bin target must be available for `cargo run`")
29+
match (name.as_ref(), &target_kind) {
30+
(Some(name), &TargetKind::Bin) => {
31+
human(format!("no bin target named `{}` to run", name))
32+
}
33+
(Some(name), &TargetKind::Example) => {
34+
human(format!("no example target named `{}` to run", name))
35+
}
36+
(Some(_), &TargetKind::Lib(..)) => unreachable!(),
37+
(None, _) => human("a bin target must be available for `cargo run`"),
38+
}
3039
}));
3140
match bins.next() {
3241
Some(..) => return Err(

tests/test_cargo_test.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1332,3 +1332,23 @@ test!(bin_is_preserved {
13321332
execs().with_status(0));
13331333
assert_that(&p.bin("foo"), existing_file());
13341334
});
1335+
1336+
test!(bad_example {
1337+
let p = project("foo")
1338+
.file("Cargo.toml", r#"
1339+
[package]
1340+
name = "foo"
1341+
version = "0.0.1"
1342+
authors = []
1343+
"#)
1344+
.file("src/lib.rs", "");
1345+
1346+
assert_that(p.cargo_process("run").arg("--example").arg("foo"),
1347+
execs().with_status(101).with_stderr("\
1348+
no example target named `foo` to run
1349+
"));
1350+
assert_that(p.cargo_process("run").arg("--bin").arg("foo"),
1351+
execs().with_status(101).with_stderr("\
1352+
no bin target named `foo` to run
1353+
"));
1354+
});

0 commit comments

Comments
 (0)