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 {
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)
Original file line number Diff line number Diff 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+
352381fn autodiscover_examples_project ( rust_edition : & str , autoexamples : Option < bool > ) -> Project {
353382 let autoexamples = match autoexamples {
354383 None => "" . to_string ( ) ,
You can’t perform that action at this time.
0 commit comments