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 @@ -1431,11 +1431,25 @@ fn inferred_bin_path(bin: &TomlBinTarget,
1431
1431
}
1432
1432
1433
1433
return Path :: new ( "src" ) . join ( "bin" ) . join ( & format ! ( "main.rs" ) ) . to_path_buf ( )
1434
+ }
1435
+
1436
+ // bin_len > 1
1437
+ let path = Path :: new ( "src" ) . join ( "bin" ) . join ( & format ! ( "{}.rs" , bin. name( ) ) ) ;
1438
+ if package_root. join ( & path) . exists ( ) {
1439
+ return path. to_path_buf ( )
1440
+ }
1441
+
1442
+ let path = Path :: new ( "src" ) . join ( & format ! ( "{}.rs" , bin. name( ) ) ) ;
1443
+ if package_root. join ( & path) . exists ( ) {
1444
+ return path. to_path_buf ( )
1445
+ }
1434
1446
1447
+ let path = Path :: new ( "src" ) . join ( "bin" ) . join ( & format ! ( "main.rs" ) ) ;
1448
+ if package_root. join ( & path) . exists ( ) {
1449
+ return path. to_path_buf ( )
1435
1450
}
1436
1451
1437
- // here we have multiple bins, so they are expected to be located inside src/bin
1438
- Path :: new ( "src" ) . join ( "bin" ) . join ( & format ! ( "{}.rs" , bin. name( ) ) ) . to_path_buf ( )
1452
+ return Path :: new ( "src" ) . join ( & format ! ( "main.rs" ) ) . to_path_buf ( )
1439
1453
}
1440
1454
1441
1455
fn build_profiles ( profiles : & Option < TomlProfiles > ) -> Profiles {
Original file line number Diff line number Diff line change @@ -2870,6 +2870,68 @@ fn run_proper_binary_main_rs() {
2870
2870
execs ( ) . with_status ( 0 ) ) ;
2871
2871
}
2872
2872
2873
+ #[ test]
2874
+ fn run_proper_alias_binary_from_src ( ) {
2875
+ let p = project ( "foo" )
2876
+ . file ( "Cargo.toml" , r#"
2877
+ [package]
2878
+ name = "foo"
2879
+ authors = []
2880
+ version = "0.0.0"
2881
+ [[bin]]
2882
+ name = "foo"
2883
+ [[bin]]
2884
+ name = "bar"
2885
+ "# )
2886
+ . file ( "src/foo.rs" , r#"
2887
+ fn main() {
2888
+ println!("foo");
2889
+ }
2890
+ "# ) . file ( "src/bar.rs" , r#"
2891
+ fn main() {
2892
+ println!("bar");
2893
+ }
2894
+ "# ) ;
2895
+
2896
+ assert_that ( p. cargo_process ( "build" )
2897
+ . arg ( "--all" ) ,
2898
+ execs ( ) . with_status ( 0 )
2899
+ ) ;
2900
+ assert_that ( process ( & p. bin ( "foo" ) ) ,
2901
+ execs ( ) . with_status ( 0 ) . with_stdout ( "foo\n " ) ) ;
2902
+ assert_that ( process ( & p. bin ( "bar" ) ) ,
2903
+ execs ( ) . with_status ( 0 ) . with_stdout ( "bar\n " ) ) ;
2904
+ }
2905
+
2906
+ #[ test]
2907
+ fn run_proper_alias_binary_main_rs ( ) {
2908
+ let p = project ( "foo" )
2909
+ . file ( "Cargo.toml" , r#"
2910
+ [package]
2911
+ name = "foo"
2912
+ authors = []
2913
+ version = "0.0.0"
2914
+ [[bin]]
2915
+ name = "foo"
2916
+ [[bin]]
2917
+ name = "bar"
2918
+ "# )
2919
+ . file ( "src/main.rs" , r#"
2920
+ fn main() {
2921
+ println!("main");
2922
+ }
2923
+ "# ) ;
2924
+
2925
+ assert_that ( p. cargo_process ( "build" )
2926
+ . arg ( "--all" ) ,
2927
+ execs ( ) . with_status ( 0 )
2928
+ ) ;
2929
+ assert_that ( process ( & p. bin ( "foo" ) ) ,
2930
+ execs ( ) . with_status ( 0 ) . with_stdout ( "main\n " ) ) ;
2931
+ assert_that ( process ( & p. bin ( "bar" ) ) ,
2932
+ execs ( ) . with_status ( 0 ) . with_stdout ( "main\n " ) ) ;
2933
+ }
2934
+
2873
2935
#[ test]
2874
2936
fn run_proper_binary_main_rs_as_foo ( ) {
2875
2937
let p = project ( "foo" )
You can’t perform that action at this time.
0 commit comments