@@ -1899,6 +1899,40 @@ fn explicit_examples() {
1899
1899
. run ( ) ;
1900
1900
}
1901
1901
1902
+ #[ cargo_test]
1903
+ fn non_existing_test ( ) {
1904
+ let p = project ( )
1905
+ . file (
1906
+ "Cargo.toml" ,
1907
+ r#"
1908
+ [package]
1909
+ name = "foo"
1910
+ version = "1.0.0"
1911
+
1912
+ [lib]
1913
+ name = "foo"
1914
+ path = "src/lib.rs"
1915
+
1916
+ [[test]]
1917
+ name = "hello"
1918
+ "# ,
1919
+ )
1920
+ . file ( "src/lib.rs" , "" )
1921
+ . build ( ) ;
1922
+
1923
+ p. cargo ( "build --tests -v" )
1924
+ . with_status ( 101 )
1925
+ . with_stderr (
1926
+ "\
1927
+ [ERROR] failed to parse manifest at `[..]`
1928
+
1929
+ Caused by:
1930
+ can't find `hello` test at `tests/hello.rs` or `tests/hello/main.rs`. \
1931
+ Please specify test.path if you want to use a non-default path.",
1932
+ )
1933
+ . run ( ) ;
1934
+ }
1935
+
1902
1936
#[ cargo_test]
1903
1937
fn non_existing_example ( ) {
1904
1938
let p = project ( )
@@ -1908,7 +1942,6 @@ fn non_existing_example() {
1908
1942
[package]
1909
1943
name = "foo"
1910
1944
version = "1.0.0"
1911
- authors = []
1912
1945
1913
1946
[lib]
1914
1947
name = "foo"
@@ -1921,14 +1954,49 @@ fn non_existing_example() {
1921
1954
. file ( "src/lib.rs" , "" )
1922
1955
. build ( ) ;
1923
1956
1924
- p. cargo ( "test -v" )
1957
+ p. cargo ( "build --examples -v" )
1925
1958
. with_status ( 101 )
1926
1959
. with_stderr (
1927
1960
"\
1928
1961
[ERROR] failed to parse manifest at `[..]`
1929
1962
1930
1963
Caused by:
1931
- can't find `hello` example, specify example.path" ,
1964
+ can't find `hello` example at `examples/hello.rs` or `examples/hello/main.rs`. \
1965
+ Please specify example.path if you want to use a non-default path.",
1966
+ )
1967
+ . run ( ) ;
1968
+ }
1969
+
1970
+ #[ cargo_test]
1971
+ fn non_existing_benchmark ( ) {
1972
+ let p = project ( )
1973
+ . file (
1974
+ "Cargo.toml" ,
1975
+ r#"
1976
+ [package]
1977
+ name = "foo"
1978
+ version = "1.0.0"
1979
+
1980
+ [lib]
1981
+ name = "foo"
1982
+ path = "src/lib.rs"
1983
+
1984
+ [[bench]]
1985
+ name = "hello"
1986
+ "# ,
1987
+ )
1988
+ . file ( "src/lib.rs" , "" )
1989
+ . build ( ) ;
1990
+
1991
+ p. cargo ( "build --benches -v" )
1992
+ . with_status ( 101 )
1993
+ . with_stderr (
1994
+ "\
1995
+ [ERROR] failed to parse manifest at `[..]`
1996
+
1997
+ Caused by:
1998
+ can't find `hello` bench at `benches/hello.rs` or `benches/hello/main.rs`. \
1999
+ Please specify bench.path if you want to use a non-default path.",
1932
2000
)
1933
2001
. run ( ) ;
1934
2002
}
@@ -1948,7 +2016,184 @@ fn non_existing_binary() {
1948
2016
[ERROR] failed to parse manifest at `[..]`
1949
2017
1950
2018
Caused by:
1951
- can't find `foo` bin, specify bin.path" ,
2019
+ can't find `foo` bin at `src/bin/foo.rs` or `src/bin/foo/main.rs`. \
2020
+ Please specify bin.path if you want to use a non-default path.",
2021
+ )
2022
+ . run ( ) ;
2023
+ }
2024
+
2025
+ #[ cargo_test]
2026
+ fn commonly_wrong_path_of_test ( ) {
2027
+ let p = project ( )
2028
+ . file (
2029
+ "Cargo.toml" ,
2030
+ r#"
2031
+ [package]
2032
+ name = "foo"
2033
+ version = "1.0.0"
2034
+
2035
+ [lib]
2036
+ name = "foo"
2037
+ path = "src/lib.rs"
2038
+
2039
+ [[test]]
2040
+ name = "foo"
2041
+ "# ,
2042
+ )
2043
+ . file ( "src/lib.rs" , "" )
2044
+ . file ( "test/foo.rs" , "" )
2045
+ . build ( ) ;
2046
+
2047
+ p. cargo ( "build --tests -v" )
2048
+ . with_status ( 101 )
2049
+ . with_stderr (
2050
+ "\
2051
+ [ERROR] failed to parse manifest at `[..]`
2052
+
2053
+ Caused by:
2054
+ can't find `foo` test at default paths, but found a file at `test/foo.rs`.
2055
+ Perhaps rename the file to `tests/foo.rs` for target auto-discovery, \
2056
+ or specify test.path if you want to use a non-default path.",
2057
+ )
2058
+ . run ( ) ;
2059
+ }
2060
+
2061
+ #[ cargo_test]
2062
+ fn commonly_wrong_path_of_example ( ) {
2063
+ let p = project ( )
2064
+ . file (
2065
+ "Cargo.toml" ,
2066
+ r#"
2067
+ [package]
2068
+ name = "foo"
2069
+ version = "1.0.0"
2070
+
2071
+ [lib]
2072
+ name = "foo"
2073
+ path = "src/lib.rs"
2074
+
2075
+ [[example]]
2076
+ name = "foo"
2077
+ "# ,
2078
+ )
2079
+ . file ( "src/lib.rs" , "" )
2080
+ . file ( "example/foo.rs" , "" )
2081
+ . build ( ) ;
2082
+
2083
+ p. cargo ( "build --examples -v" )
2084
+ . with_status ( 101 )
2085
+ . with_stderr (
2086
+ "\
2087
+ [ERROR] failed to parse manifest at `[..]`
2088
+
2089
+ Caused by:
2090
+ can't find `foo` example at default paths, but found a file at `example/foo.rs`.
2091
+ Perhaps rename the file to `examples/foo.rs` for target auto-discovery, \
2092
+ or specify example.path if you want to use a non-default path.",
2093
+ )
2094
+ . run ( ) ;
2095
+ }
2096
+
2097
+ #[ cargo_test]
2098
+ fn commonly_wrong_path_of_benchmark ( ) {
2099
+ let p = project ( )
2100
+ . file (
2101
+ "Cargo.toml" ,
2102
+ r#"
2103
+ [package]
2104
+ name = "foo"
2105
+ version = "1.0.0"
2106
+
2107
+ [lib]
2108
+ name = "foo"
2109
+ path = "src/lib.rs"
2110
+
2111
+ [[bench]]
2112
+ name = "foo"
2113
+ "# ,
2114
+ )
2115
+ . file ( "src/lib.rs" , "" )
2116
+ . file ( "bench/foo.rs" , "" )
2117
+ . build ( ) ;
2118
+
2119
+ p. cargo ( "build --benches -v" )
2120
+ . with_status ( 101 )
2121
+ . with_stderr (
2122
+ "\
2123
+ [ERROR] failed to parse manifest at `[..]`
2124
+
2125
+ Caused by:
2126
+ can't find `foo` bench at default paths, but found a file at `bench/foo.rs`.
2127
+ Perhaps rename the file to `benches/foo.rs` for target auto-discovery, \
2128
+ or specify bench.path if you want to use a non-default path.",
2129
+ )
2130
+ . run ( ) ;
2131
+ }
2132
+
2133
+ #[ cargo_test]
2134
+ fn commonly_wrong_path_binary ( ) {
2135
+ let p = project ( )
2136
+ . file ( "Cargo.toml" , & basic_bin_manifest ( "foo" ) )
2137
+ . file ( "src/lib.rs" , "" )
2138
+ . file ( "src/bins/foo.rs" , "" )
2139
+ . build ( ) ;
2140
+
2141
+ p. cargo ( "build -v" )
2142
+ . with_status ( 101 )
2143
+ . with_stderr (
2144
+ "\
2145
+ [ERROR] failed to parse manifest at `[..]`
2146
+
2147
+ Caused by:
2148
+ can't find `foo` bin at default paths, but found a file at `src/bins/foo.rs`.
2149
+ Perhaps rename the file to `src/bin/foo.rs` for target auto-discovery, \
2150
+ or specify bin.path if you want to use a non-default path.",
2151
+ )
2152
+ . run ( ) ;
2153
+ }
2154
+
2155
+ #[ cargo_test]
2156
+ fn commonly_wrong_path_subdir_binary ( ) {
2157
+ let p = project ( )
2158
+ . file ( "Cargo.toml" , & basic_bin_manifest ( "foo" ) )
2159
+ . file ( "src/lib.rs" , "" )
2160
+ . file ( "src/bins/foo/main.rs" , "" )
2161
+ . build ( ) ;
2162
+
2163
+ p. cargo ( "build -v" )
2164
+ . with_status ( 101 )
2165
+ . with_stderr (
2166
+ "\
2167
+ [ERROR] failed to parse manifest at `[..]`
2168
+
2169
+ Caused by:
2170
+ can't find `foo` bin at default paths, but found a file at `src/bins/foo/main.rs`.
2171
+ Perhaps rename the file to `src/bin/foo/main.rs` for target auto-discovery, \
2172
+ or specify bin.path if you want to use a non-default path.",
2173
+ )
2174
+ . run ( ) ;
2175
+ }
2176
+
2177
+ #[ cargo_test]
2178
+ fn found_multiple_target_files ( ) {
2179
+ let p = project ( )
2180
+ . file ( "Cargo.toml" , & basic_bin_manifest ( "foo" ) )
2181
+ . file ( "src/lib.rs" , "" )
2182
+ . file ( "src/bin/foo.rs" , "" )
2183
+ . file ( "src/bin/foo/main.rs" , "" )
2184
+ . build ( ) ;
2185
+
2186
+ p. cargo ( "build -v" )
2187
+ . with_status ( 101 )
2188
+ // Don't assert the inferred pathes since the order is non-deterministic.
2189
+ . with_stderr (
2190
+ "\
2191
+ [ERROR] failed to parse manifest at `[..]`
2192
+
2193
+ Caused by:
2194
+ cannot infer path for `foo` bin
2195
+ Cargo doesn't know which to use because multiple target files found \
2196
+ at `src/bin/foo[..].rs` and `src/bin/foo[..].rs`.",
1952
2197
)
1953
2198
. run ( ) ;
1954
2199
}
@@ -4319,7 +4564,7 @@ fn no_bin_in_src_with_lib() {
4319
4564
[ERROR] failed to parse manifest at `[..]`
4320
4565
4321
4566
Caused by:
4322
- can't find `foo` bin, specify bin.path " ,
4567
+ can't find `foo` bin at `src/ bin/foo.rs` or `src/bin/foo/main.rs`. [..] " ,
4323
4568
)
4324
4569
. run ( ) ;
4325
4570
}
@@ -4529,7 +4774,9 @@ fn building_a_dependent_crate_witout_bin_should_fail() {
4529
4774
4530
4775
p. cargo ( "build" )
4531
4776
. with_status ( 101 )
4532
- . with_stderr_contains ( "[..]can't find `a_bin` bin, specify bin.path" )
4777
+ . with_stderr_contains (
4778
+ "[..]can't find `a_bin` bin at `src/bin/a_bin.rs` or `src/bin/a_bin/main.rs`[..]" ,
4779
+ )
4533
4780
. run ( ) ;
4534
4781
}
4535
4782
0 commit comments