Skip to content

Commit

Permalink
Auto merge of #6330 - dwijnand:run_bin_example, r=alexcrichton
Browse files Browse the repository at this point in the history
Allow crate_type=bin examples to run

Fixes #6159
  • Loading branch information
bors committed Nov 19, 2018
2 parents bf6aa59 + e950364 commit 85060d8
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/cargo/core/manifest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -660,7 +660,11 @@ impl Target {
required_features: Option<Vec<String>>,
edition: Edition,
) -> Target {
let kind = if crate_targets.is_empty() {
let kind = if crate_targets.is_empty()
|| crate_targets
.iter()
.all(|t| *t == LibKind::Other("bin".into()))
{
TargetKind::ExampleBin
} else {
TargetKind::ExampleLib(crate_targets)
Expand Down
29 changes: 29 additions & 0 deletions tests/testsuite/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,35 @@ fn run_library_example() {
.run();
}

#[test]
fn run_bin_example() {
let p = project()
.file(
"Cargo.toml",
r#"
[package]
name = "foo"
version = "0.0.1"
[[example]]
name = "bar"
crate_type = ["bin"]
"#,
)
.file("src/lib.rs", "")
.file("examples/bar.rs", r#"fn main() { println!("example"); }"#)
.build();

p.cargo("run --example bar")
.with_stderr(
"\
[COMPILING] foo v0.0.1 ([CWD])
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
[RUNNING] `target/debug/examples/bar[EXE]`",
)
.with_stdout("example")
.run();
}

fn autodiscover_examples_project(rust_edition: &str, autoexamples: Option<bool>) -> Project {
let autoexamples = match autoexamples {
None => "".to_string(),
Expand Down

0 comments on commit 85060d8

Please sign in to comment.