File tree Expand file tree Collapse file tree 2 files changed +30
-1
lines changed Expand file tree Collapse file tree 2 files changed +30
-1
lines changed Original file line number Diff line number Diff line change @@ -26,7 +26,16 @@ pub fn run(manifest_path: &Path,
26
26
!a. profile ( ) . is_custom_build ( )
27
27
} ) ;
28
28
let bin = try!( bins. next ( ) . chain_error ( || {
29
- human ( "a bin target must be available for `cargo run`" )
29
+ match ( name. as_ref ( ) , & target_kind) {
30
+ ( Some ( name) , & TargetKind :: Bin ) => {
31
+ human ( format ! ( "no bin target named `{}` to run" , name) )
32
+ }
33
+ ( Some ( name) , & TargetKind :: Example ) => {
34
+ human ( format ! ( "no example target named `{}` to run" , name) )
35
+ }
36
+ ( Some ( _) , & TargetKind :: Lib ( ..) ) => unreachable ! ( ) ,
37
+ ( None , _) => human ( "a bin target must be available for `cargo run`" ) ,
38
+ }
30
39
} ) ) ;
31
40
match bins. next ( ) {
32
41
Some ( ..) => return Err (
Original file line number Diff line number Diff line change @@ -1332,3 +1332,23 @@ test!(bin_is_preserved {
1332
1332
execs( ) . with_status( 0 ) ) ;
1333
1333
assert_that( & p. bin( "foo" ) , existing_file( ) ) ;
1334
1334
} ) ;
1335
+
1336
+ test ! ( bad_example {
1337
+ let p = project( "foo" )
1338
+ . file( "Cargo.toml" , r#"
1339
+ [package]
1340
+ name = "foo"
1341
+ version = "0.0.1"
1342
+ authors = []
1343
+ "# )
1344
+ . file( "src/lib.rs" , "" ) ;
1345
+
1346
+ assert_that( p. cargo_process( "run" ) . arg( "--example" ) . arg( "foo" ) ,
1347
+ execs( ) . with_status( 101 ) . with_stderr( "\
1348
+ no example target named `foo` to run
1349
+ " ) ) ;
1350
+ assert_that( p. cargo_process( "run" ) . arg( "--bin" ) . arg( "foo" ) ,
1351
+ execs( ) . with_status( 101 ) . with_stderr( "\
1352
+ no bin target named `foo` to run
1353
+ " ) ) ;
1354
+ } ) ;
You can’t perform that action at this time.
0 commit comments