@@ -134,6 +134,228 @@ fn fails_with_args_to_all_binaries() {
134
134
. run ( ) ;
135
135
}
136
136
137
+ #[ cargo_test]
138
+ fn fails_with_crate_type_and_without_unstable_options ( ) {
139
+ let p = project ( ) . file ( "src/lib.rs" , r#" "# ) . build ( ) ;
140
+
141
+ p. cargo ( "rustc --crate-type lib" )
142
+ . masquerade_as_nightly_cargo ( )
143
+ . with_status ( 101 )
144
+ . with_stderr (
145
+ "[ERROR] the `crate-type` flag is unstable, pass `-Z unstable-options` to enable it
146
+ See https://github.com/rust-lang/cargo/issues/10083 for more information about the `crate-type` flag." ,
147
+ )
148
+ . run ( ) ;
149
+ }
150
+
151
+ #[ cargo_test]
152
+ fn fails_with_crate_type_to_multi_binaries ( ) {
153
+ let p = project ( )
154
+ . file ( "src/bin/foo.rs" , "fn main() {}" )
155
+ . file ( "src/bin/bar.rs" , "fn main() {}" )
156
+ . file ( "src/bin/baz.rs" , "fn main() {}" )
157
+ . file ( "src/lib.rs" , r#" "# )
158
+ . build ( ) ;
159
+
160
+ p. cargo ( "rustc --crate-type lib -Zunstable-options" )
161
+ . masquerade_as_nightly_cargo ( )
162
+ . with_status ( 101 )
163
+ . with_stderr (
164
+ "[ERROR] crate types to rustc can only be passed to one target, consider filtering
165
+ the package by passing, e.g., `--lib` or `--example` to specify a single target" ,
166
+ )
167
+ . run ( ) ;
168
+ }
169
+
170
+ #[ cargo_test]
171
+ fn fails_with_crate_type_to_multi_examples ( ) {
172
+ let p = project ( )
173
+ . file (
174
+ "Cargo.toml" ,
175
+ r#"
176
+ [package]
177
+ name = "foo"
178
+ version = "0.0.1"
179
+ authors = []
180
+
181
+ [[example]]
182
+ name = "ex1"
183
+ crate-type = ["rlib"]
184
+ [[example]]
185
+ name = "ex2"
186
+ crate-type = ["rlib"]
187
+ "# ,
188
+ )
189
+ . file ( "src/lib.rs" , "" )
190
+ . file ( "examples/ex1.rs" , "" )
191
+ . file ( "examples/ex2.rs" , "" )
192
+ . build ( ) ;
193
+
194
+ p. cargo ( "rustc -v --example ex1 --example ex2 --crate-type lib,cdylib -Zunstable-options" )
195
+ . masquerade_as_nightly_cargo ( )
196
+ . with_status ( 101 )
197
+ . with_stderr (
198
+ "[ERROR] crate types to rustc can only be passed to one target, consider filtering
199
+ the package by passing, e.g., `--lib` or `--example` to specify a single target" ,
200
+ )
201
+ . run ( ) ;
202
+ }
203
+
204
+ #[ cargo_test]
205
+ fn fails_with_crate_type_to_binary ( ) {
206
+ let p = project ( ) . file ( "src/bin/foo.rs" , "fn main() {}" ) . build ( ) ;
207
+
208
+ p. cargo ( "rustc --crate-type lib -Zunstable-options" )
209
+ . masquerade_as_nightly_cargo ( )
210
+ . with_status ( 101 )
211
+ . with_stderr (
212
+ "[ERROR] crate types can only be specified for libraries and example libraries.
213
+ Binaries, tests, and benchmarks are always the `bin` crate type" ,
214
+ )
215
+ . run ( ) ;
216
+ }
217
+
218
+ #[ cargo_test]
219
+ fn build_with_crate_type_for_foo ( ) {
220
+ let p = project ( )
221
+ . file ( "src/main.rs" , "fn main() {}" )
222
+ . file ( "src/lib.rs" , r#" "# )
223
+ . build ( ) ;
224
+
225
+ p. cargo ( "rustc -v --lib --crate-type lib -Zunstable-options" )
226
+ . masquerade_as_nightly_cargo ( )
227
+ . with_stderr (
228
+ "\
229
+ [COMPILING] foo v0.0.1 ([CWD])
230
+ [RUNNING] `rustc --crate-name foo src/lib.rs [..]--crate-type lib [..]
231
+ [FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
232
+ " ,
233
+ )
234
+ . run ( ) ;
235
+ }
236
+
237
+ #[ cargo_test]
238
+ fn build_with_crate_types_for_foo ( ) {
239
+ let p = project ( )
240
+ . file ( "src/main.rs" , "fn main() {}" )
241
+ . file ( "src/lib.rs" , r#" "# )
242
+ . build ( ) ;
243
+
244
+ p. cargo ( "rustc -v --lib --crate-type lib,cdylib -Zunstable-options" )
245
+ . masquerade_as_nightly_cargo ( )
246
+ . with_stderr (
247
+ "\
248
+ [COMPILING] foo v0.0.1 ([CWD])
249
+ [RUNNING] `rustc --crate-name foo src/lib.rs [..]--crate-type lib,cdylib [..]
250
+ [FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
251
+ " ,
252
+ )
253
+ . run ( ) ;
254
+ }
255
+
256
+ #[ cargo_test]
257
+ fn build_with_crate_type_to_example ( ) {
258
+ let p = project ( )
259
+ . file (
260
+ "Cargo.toml" ,
261
+ r#"
262
+ [package]
263
+ name = "foo"
264
+ version = "0.0.1"
265
+ authors = []
266
+
267
+ [[example]]
268
+ name = "ex"
269
+ crate-type = ["rlib"]
270
+ "# ,
271
+ )
272
+ . file ( "src/lib.rs" , "" )
273
+ . file ( "examples/ex.rs" , "" )
274
+ . build ( ) ;
275
+
276
+ p. cargo ( "rustc -v --example ex --crate-type cdylib -Zunstable-options" )
277
+ . masquerade_as_nightly_cargo ( )
278
+ . with_stderr (
279
+ "\
280
+ [COMPILING] foo v0.0.1 ([CWD])
281
+ [RUNNING] `rustc --crate-name foo src/lib.rs [..]--crate-type lib [..]
282
+ [RUNNING] `rustc --crate-name ex examples/ex.rs [..]--crate-type cdylib [..]
283
+ [FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
284
+ " ,
285
+ )
286
+ . run ( ) ;
287
+ }
288
+
289
+ #[ cargo_test]
290
+ fn build_with_crate_types_to_example ( ) {
291
+ let p = project ( )
292
+ . file (
293
+ "Cargo.toml" ,
294
+ r#"
295
+ [package]
296
+ name = "foo"
297
+ version = "0.0.1"
298
+ authors = []
299
+
300
+ [[example]]
301
+ name = "ex"
302
+ crate-type = ["rlib"]
303
+ "# ,
304
+ )
305
+ . file ( "src/lib.rs" , "" )
306
+ . file ( "examples/ex.rs" , "" )
307
+ . build ( ) ;
308
+
309
+ p. cargo ( "rustc -v --example ex --crate-type lib,cdylib -Zunstable-options" )
310
+ . masquerade_as_nightly_cargo ( )
311
+ . with_stderr (
312
+ "\
313
+ [COMPILING] foo v0.0.1 ([CWD])
314
+ [RUNNING] `rustc --crate-name foo src/lib.rs [..]--crate-type lib [..]
315
+ [RUNNING] `rustc --crate-name ex examples/ex.rs [..]--crate-type lib,cdylib [..]
316
+ [FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
317
+ " ,
318
+ )
319
+ . run ( ) ;
320
+ }
321
+
322
+ #[ cargo_test]
323
+ fn build_with_crate_types_to_one_of_multi_examples ( ) {
324
+ let p = project ( )
325
+ . file (
326
+ "Cargo.toml" ,
327
+ r#"
328
+ [package]
329
+ name = "foo"
330
+ version = "0.0.1"
331
+ authors = []
332
+
333
+ [[example]]
334
+ name = "ex1"
335
+ crate-type = ["rlib"]
336
+ [[example]]
337
+ name = "ex2"
338
+ crate-type = ["rlib"]
339
+ "# ,
340
+ )
341
+ . file ( "src/lib.rs" , "" )
342
+ . file ( "examples/ex1.rs" , "" )
343
+ . file ( "examples/ex2.rs" , "" )
344
+ . build ( ) ;
345
+
346
+ p. cargo ( "rustc -v --example ex1 --crate-type lib,cdylib -Zunstable-options" )
347
+ . masquerade_as_nightly_cargo ( )
348
+ . with_stderr (
349
+ "\
350
+ [COMPILING] foo v0.0.1 ([CWD])
351
+ [RUNNING] `rustc --crate-name foo src/lib.rs [..]--crate-type lib [..]
352
+ [RUNNING] `rustc --crate-name ex1 examples/ex1.rs [..]--crate-type lib,cdylib [..]
353
+ [FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
354
+ " ,
355
+ )
356
+ . run ( ) ;
357
+ }
358
+
137
359
#[ cargo_test]
138
360
fn build_with_args_to_one_of_multiple_tests ( ) {
139
361
let p = project ( )
0 commit comments