@@ -317,7 +317,7 @@ fn well_known_names_values_doctest() {
317
317
. run ( ) ;
318
318
}
319
319
320
- #[ cargo_test]
320
+ #[ cargo_test( nightly , reason = "warning currently only on nightly" ) ]
321
321
fn test_false_lib ( ) {
322
322
let p = project ( )
323
323
. file (
@@ -332,26 +332,57 @@ fn test_false_lib() {
332
332
test = false
333
333
"# ,
334
334
)
335
- . file ( "src/lib.rs" , "" )
335
+ . file ( "src/lib.rs" , "#[cfg(test)] mod tests {} " )
336
336
. build ( ) ;
337
337
338
338
p. cargo ( "check -v" )
339
339
. with_stderr_does_not_contain ( x ! ( "rustc" => "cfg" of "docsrs,test" ) )
340
340
. with_stderr_contains ( x ! ( "rustc" => "cfg" of "docsrs" ) )
341
+ . with_stderr_data ( str![ [ r#"
342
+ ...
343
+ [WARNING] unexpected `cfg` condition name: `test`
344
+ ...
345
+
346
+ [WARNING] `foo` (lib) generated 1 warning
347
+ [FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
348
+
349
+ "# ] ] )
341
350
. run ( ) ;
342
351
343
352
p. cargo ( "clean" ) . run ( ) ;
344
353
p. cargo ( "test -v" )
345
354
. with_stderr_contains ( x ! ( "rustc" => "cfg" of "docsrs" ) )
355
+ . with_stderr_data ( str![ [ r#"
356
+ ...
357
+ [WARNING] unexpected `cfg` condition name: `test`
358
+ ...
359
+
360
+ [WARNING] `foo` (lib) generated 1 warning
361
+ [FINISHED] `test` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
362
+ [DOCTEST] foo
363
+ [RUNNING] [..]
364
+
365
+ "# ] ] )
346
366
. run ( ) ;
347
367
348
368
p. cargo ( "clean" ) . run ( ) ;
349
369
p. cargo ( "test --lib -v" )
350
370
. with_stderr_contains ( x ! ( "rustc" => "cfg" of "docsrs" ) )
371
+ . with_stderr_data ( str![ [ r#"
372
+ ...
373
+ [WARNING] unexpected `cfg` condition name: `test`
374
+ --> src/lib.rs:1:7
375
+ ...
376
+
377
+ [WARNING] `foo` (lib test) generated 1 warning
378
+ [FINISHED] `test` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
379
+ [RUNNING] `[ROOT]/foo/target/debug/deps/foo-[HASH][EXE]`
380
+
381
+ "# ] ] )
351
382
. run ( ) ;
352
383
}
353
384
354
- #[ cargo_test]
385
+ #[ cargo_test( nightly , reason = "warning currently only on nightly" ) ]
355
386
fn test_false_bins ( ) {
356
387
let p = project ( )
357
388
. file (
@@ -368,17 +399,26 @@ fn test_false_bins() {
368
399
path = "src/deamon.rs"
369
400
"# ,
370
401
)
371
- . file ( "src/main.rs" , "fn main() {}" )
372
- . file ( "src/deamon.rs" , "fn main() {}" )
402
+ . file ( "src/main.rs" , "fn main() {}\n #[cfg(test)] mod tests {} " )
403
+ . file ( "src/deamon.rs" , "fn main() {}\n #[cfg(test)] mod tests {} " )
373
404
. build ( ) ;
374
405
375
406
p. cargo ( "check -v" )
376
407
. with_stderr_contains ( x ! ( "rustc" => "cfg" of "docsrs,test" ) ) // for foo
377
408
. with_stderr_contains ( x ! ( "rustc" => "cfg" of "docsrs" ) ) // for deamon
409
+ . with_stderr_data ( str![ [ r#"
410
+ ...
411
+ [WARNING] unexpected `cfg` condition name: `test`
412
+ ...
413
+
414
+ [WARNING] `foo` (bin "daemon") generated 1 warning
415
+ [FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
416
+
417
+ "# ] ] )
378
418
. run ( ) ;
379
419
}
380
420
381
- #[ cargo_test]
421
+ #[ cargo_test( nightly , reason = "warning currently only on nightly" ) ]
382
422
fn test_false_examples ( ) {
383
423
let p = project ( )
384
424
. file (
@@ -398,17 +438,34 @@ fn test_false_examples() {
398
438
path = "src/deamon.rs"
399
439
"# ,
400
440
)
401
- . file ( "src/lib.rs" , "" )
402
- . file ( "src/deamon.rs" , "fn main() {}" )
441
+ . file ( "src/lib.rs" , "#[cfg(test)] mod tests {} " )
442
+ . file ( "src/deamon.rs" , "fn main() {}\n #[cfg(test)] mod tests {} " )
403
443
. build ( ) ;
404
444
405
445
p. cargo ( "check --examples -v" )
406
446
. with_stderr_does_not_contain ( x ! ( "rustc" => "cfg" of "docsrs,test" ) )
407
447
. with_stderr_contains ( x ! ( "rustc" => "cfg" of "docsrs" ) )
448
+ . with_stderr_data ( str![ [ r#"
449
+ ...
450
+ [WARNING] unexpected `cfg` condition name: `test`
451
+ ...
452
+
453
+ [WARNING] `foo` (lib) generated 1 warning
454
+ ...
455
+ [WARNING] unexpected `cfg` condition name: `test`
456
+ ...
457
+
458
+ [WARNING] `foo` (example "daemon") generated 1 warning
459
+ [FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
460
+
461
+ "# ] ] )
408
462
. run ( ) ;
409
463
}
410
464
411
- #[ cargo_test( nightly, reason = "bench is nightly" ) ]
465
+ #[ cargo_test(
466
+ nightly,
467
+ reason = "bench is nightly & warning currently only on nightly"
468
+ ) ]
412
469
fn test_false_benches ( ) {
413
470
let p = project ( )
414
471
. file (
@@ -436,8 +493,14 @@ fn test_false_benches() {
436
493
)
437
494
. build ( ) ;
438
495
439
- p. cargo ( "bench --bench ben1 -v" )
440
- . with_stderr_contains ( x ! ( "rustc" => "cfg" of "docsrs,test" ) )
496
+ // Benches always require the `test` cfg, there should be no warning.
497
+ p. cargo ( "bench --bench ben1" )
498
+ . with_stderr_data ( str![ [ r#"
499
+ [COMPILING] foo v0.0.0 ([ROOT]/foo)
500
+ [FINISHED] `bench` profile [optimized] target(s) in [ELAPSED]s
501
+ [RUNNING] benches/ben1.rs (target/release/deps/ben1-[HASH][EXE])
502
+
503
+ "# ] ] )
441
504
. run ( ) ;
442
505
}
443
506
0 commit comments