Skip to content

Commit 85060d8

Browse files
committed
Auto merge of #6330 - dwijnand:run_bin_example, r=alexcrichton
Allow crate_type=bin examples to run Fixes #6159
2 parents bf6aa59 + e950364 commit 85060d8

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed

src/cargo/core/manifest.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -660,7 +660,11 @@ impl Target {
660660
required_features: Option<Vec<String>>,
661661
edition: Edition,
662662
) -> Target {
663-
let kind = if crate_targets.is_empty() {
663+
let kind = if crate_targets.is_empty()
664+
|| crate_targets
665+
.iter()
666+
.all(|t| *t == LibKind::Other("bin".into()))
667+
{
664668
TargetKind::ExampleBin
665669
} else {
666670
TargetKind::ExampleLib(crate_targets)

tests/testsuite/run.rs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,35 @@ fn run_library_example() {
349349
.run();
350350
}
351351

352+
#[test]
353+
fn run_bin_example() {
354+
let p = project()
355+
.file(
356+
"Cargo.toml",
357+
r#"
358+
[package]
359+
name = "foo"
360+
version = "0.0.1"
361+
[[example]]
362+
name = "bar"
363+
crate_type = ["bin"]
364+
"#,
365+
)
366+
.file("src/lib.rs", "")
367+
.file("examples/bar.rs", r#"fn main() { println!("example"); }"#)
368+
.build();
369+
370+
p.cargo("run --example bar")
371+
.with_stderr(
372+
"\
373+
[COMPILING] foo v0.0.1 ([CWD])
374+
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
375+
[RUNNING] `target/debug/examples/bar[EXE]`",
376+
)
377+
.with_stdout("example")
378+
.run();
379+
}
380+
352381
fn autodiscover_examples_project(rust_edition: &str, autoexamples: Option<bool>) -> Project {
353382
let autoexamples = match autoexamples {
354383
None => "".to_string(),

0 commit comments

Comments
 (0)