mirror of
https://github.com/rust-lang/cargo.git
synced 2025-09-28 11:20:36 +00:00
Allow crate_type=bin examples to run
This commit is contained in:
parent
53e436d665
commit
e95036467e
@ -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)
|
||||
|
@ -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(),
|
||||
|
Loading…
x
Reference in New Issue
Block a user