File tree 2 files changed +78
-2
lines changed
2 files changed +78
-2
lines changed Original file line number Diff line number Diff line change @@ -1422,11 +1422,25 @@ fn inferred_bin_path(bin: &TomlBinTarget,
1422
1422
}
1423
1423
1424
1424
return Path :: new ( "src" ) . join ( "bin" ) . join ( & format ! ( "main.rs" ) ) . to_path_buf ( )
1425
+ }
1426
+
1427
+ // bin_len > 1
1428
+ let path = Path :: new ( "src" ) . join ( "bin" ) . join ( & format ! ( "{}.rs" , bin. name( ) ) ) ;
1429
+ if package_root. join ( & path) . exists ( ) {
1430
+ return path. to_path_buf ( )
1431
+ }
1432
+
1433
+ let path = Path :: new ( "src" ) . join ( & format ! ( "{}.rs" , bin. name( ) ) ) ;
1434
+ if package_root. join ( & path) . exists ( ) {
1435
+ return path. to_path_buf ( )
1436
+ }
1425
1437
1438
+ let path = Path :: new ( "src" ) . join ( "bin" ) . join ( & format ! ( "main.rs" ) ) ;
1439
+ if package_root. join ( & path) . exists ( ) {
1440
+ return path. to_path_buf ( )
1426
1441
}
1427
1442
1428
- // here we have multiple bins, so they are expected to be located inside src/bin
1429
- Path :: new ( "src" ) . join ( "bin" ) . join ( & format ! ( "{}.rs" , bin. name( ) ) ) . to_path_buf ( )
1443
+ return Path :: new ( "src" ) . join ( & format ! ( "main.rs" ) ) . to_path_buf ( )
1430
1444
}
1431
1445
1432
1446
fn build_profiles ( profiles : & Option < TomlProfiles > ) -> Profiles {
Original file line number Diff line number Diff line change @@ -3010,6 +3010,68 @@ fn run_proper_binary_main_rs() {
3010
3010
execs ( ) . with_status ( 0 ) ) ;
3011
3011
}
3012
3012
3013
+ #[ test]
3014
+ fn run_proper_alias_binary_from_src ( ) {
3015
+ let p = project ( "foo" )
3016
+ . file ( "Cargo.toml" , r#"
3017
+ [package]
3018
+ name = "foo"
3019
+ authors = []
3020
+ version = "0.0.0"
3021
+ [[bin]]
3022
+ name = "foo"
3023
+ [[bin]]
3024
+ name = "bar"
3025
+ "# )
3026
+ . file ( "src/foo.rs" , r#"
3027
+ fn main() {
3028
+ println!("foo");
3029
+ }
3030
+ "# ) . file ( "src/bar.rs" , r#"
3031
+ fn main() {
3032
+ println!("bar");
3033
+ }
3034
+ "# ) ;
3035
+
3036
+ assert_that ( p. cargo_process ( "build" )
3037
+ . arg ( "--all" ) ,
3038
+ execs ( ) . with_status ( 0 )
3039
+ ) ;
3040
+ assert_that ( process ( & p. bin ( "foo" ) ) ,
3041
+ execs ( ) . with_status ( 0 ) . with_stdout ( "foo\n " ) ) ;
3042
+ assert_that ( process ( & p. bin ( "bar" ) ) ,
3043
+ execs ( ) . with_status ( 0 ) . with_stdout ( "bar\n " ) ) ;
3044
+ }
3045
+
3046
+ #[ test]
3047
+ fn run_proper_alias_binary_main_rs ( ) {
3048
+ let p = project ( "foo" )
3049
+ . file ( "Cargo.toml" , r#"
3050
+ [package]
3051
+ name = "foo"
3052
+ authors = []
3053
+ version = "0.0.0"
3054
+ [[bin]]
3055
+ name = "foo"
3056
+ [[bin]]
3057
+ name = "bar"
3058
+ "# )
3059
+ . file ( "src/main.rs" , r#"
3060
+ fn main() {
3061
+ println!("main");
3062
+ }
3063
+ "# ) ;
3064
+
3065
+ assert_that ( p. cargo_process ( "build" )
3066
+ . arg ( "--all" ) ,
3067
+ execs ( ) . with_status ( 0 )
3068
+ ) ;
3069
+ assert_that ( process ( & p. bin ( "foo" ) ) ,
3070
+ execs ( ) . with_status ( 0 ) . with_stdout ( "main\n " ) ) ;
3071
+ assert_that ( process ( & p. bin ( "bar" ) ) ,
3072
+ execs ( ) . with_status ( 0 ) . with_stdout ( "main\n " ) ) ;
3073
+ }
3074
+
3013
3075
#[ test]
3014
3076
fn run_proper_binary_main_rs_as_foo ( ) {
3015
3077
let p = project ( "foo" )
You can’t perform that action at this time.
0 commit comments