@@ -317,7 +317,7 @@ fn well_known_names_values_doctest() {
317317 . run ( ) ;
318318}
319319
320- #[ cargo_test]
320+ #[ cargo_test( nightly , reason = "warning currently only on nightly" ) ]
321321fn test_false_lib ( ) {
322322 let p = project ( )
323323 . file (
@@ -332,26 +332,57 @@ fn test_false_lib() {
332332 test = false
333333 "# ,
334334 )
335- . file ( "src/lib.rs" , "" )
335+ . file ( "src/lib.rs" , "#[cfg(test)] mod tests {} " )
336336 . build ( ) ;
337337
338338 p. cargo ( "check -v" )
339339 . with_stderr_does_not_contain ( x ! ( "rustc" => "cfg" of "docsrs,test" ) )
340340 . 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+ "# ] ] )
341350 . run ( ) ;
342351
343352 p. cargo ( "clean" ) . run ( ) ;
344353 p. cargo ( "test -v" )
345354 . 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+ "# ] ] )
346366 . run ( ) ;
347367
348368 p. cargo ( "clean" ) . run ( ) ;
349369 p. cargo ( "test --lib -v" )
350370 . 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+ "# ] ] )
351382 . run ( ) ;
352383}
353384
354- #[ cargo_test]
385+ #[ cargo_test( nightly , reason = "warning currently only on nightly" ) ]
355386fn test_false_bins ( ) {
356387 let p = project ( )
357388 . file (
@@ -368,17 +399,26 @@ fn test_false_bins() {
368399 path = "src/deamon.rs"
369400 "# ,
370401 )
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 {} " )
373404 . build ( ) ;
374405
375406 p. cargo ( "check -v" )
376407 . with_stderr_contains ( x ! ( "rustc" => "cfg" of "docsrs,test" ) ) // for foo
377408 . 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+ "# ] ] )
378418 . run ( ) ;
379419}
380420
381- #[ cargo_test]
421+ #[ cargo_test( nightly , reason = "warning currently only on nightly" ) ]
382422fn test_false_examples ( ) {
383423 let p = project ( )
384424 . file (
@@ -398,17 +438,34 @@ fn test_false_examples() {
398438 path = "src/deamon.rs"
399439 "# ,
400440 )
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 {} " )
403443 . build ( ) ;
404444
405445 p. cargo ( "check --examples -v" )
406446 . with_stderr_does_not_contain ( x ! ( "rustc" => "cfg" of "docsrs,test" ) )
407447 . 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+ "# ] ] )
408462 . run ( ) ;
409463}
410464
411- #[ cargo_test( nightly, reason = "bench is nightly" ) ]
465+ #[ cargo_test(
466+ nightly,
467+ reason = "bench is nightly & warning currently only on nightly"
468+ ) ]
412469fn test_false_benches ( ) {
413470 let p = project ( )
414471 . file (
@@ -436,8 +493,14 @@ fn test_false_benches() {
436493 )
437494 . build ( ) ;
438495
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+ "# ] ] )
441504 . run ( ) ;
442505}
443506
0 commit comments