File tree Expand file tree Collapse file tree 2 files changed +34
-1
lines changed Expand file tree Collapse file tree 2 files changed +34
-1
lines changed Original file line number Diff line number Diff line change @@ -660,7 +660,11 @@ impl Target {
660
660
required_features : Option < Vec < String > > ,
661
661
edition : Edition ,
662
662
) -> 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
+ {
664
668
TargetKind :: ExampleBin
665
669
} else {
666
670
TargetKind :: ExampleLib ( crate_targets)
Original file line number Diff line number Diff line change @@ -349,6 +349,35 @@ fn run_library_example() {
349
349
. run ( ) ;
350
350
}
351
351
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
+
352
381
fn autodiscover_examples_project ( rust_edition : & str , autoexamples : Option < bool > ) -> Project {
353
382
let autoexamples = match autoexamples {
354
383
None => "" . to_string ( ) ,
You can’t perform that action at this time.
0 commit comments