@@ -317,6 +317,193 @@ fn well_known_names_values_doctest() {
317317 . run ( ) ;
318318}
319319
320+ #[ cargo_test( nightly, reason = "warning currently only on nightly" ) ]
321+ fn test_false_lib ( ) {
322+ let p = project ( )
323+ . file (
324+ "Cargo.toml" ,
325+ r#"
326+ [package]
327+ name = "foo"
328+ version = "0.1.0"
329+ edition = "2018"
330+
331+ [lib]
332+ test = false
333+ "# ,
334+ )
335+ . file ( "src/lib.rs" , "#[cfg(test)] mod tests {}" )
336+ . build ( ) ;
337+
338+ p. cargo ( "check -v" )
339+ . with_stderr_does_not_contain ( x ! ( "rustc" => "cfg" of "docsrs,test" ) )
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+ "# ] ] )
350+ . run ( ) ;
351+
352+ p. cargo ( "clean" ) . run ( ) ;
353+ p. cargo ( "test -v" )
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+ "# ] ] )
366+ . run ( ) ;
367+
368+ p. cargo ( "clean" ) . run ( ) ;
369+ p. cargo ( "test --lib -v" )
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+ "# ] ] )
382+ . run ( ) ;
383+ }
384+
385+ #[ cargo_test( nightly, reason = "warning currently only on nightly" ) ]
386+ fn test_false_bins ( ) {
387+ let p = project ( )
388+ . file (
389+ "Cargo.toml" ,
390+ r#"
391+ [package]
392+ name = "foo"
393+ version = "0.1.0"
394+ edition = "2018"
395+
396+ [[bin]]
397+ name = "daemon"
398+ test = false
399+ path = "src/deamon.rs"
400+ "# ,
401+ )
402+ . file ( "src/main.rs" , "fn main() {}\n #[cfg(test)] mod tests {}" )
403+ . file ( "src/deamon.rs" , "fn main() {}\n #[cfg(test)] mod tests {}" )
404+ . build ( ) ;
405+
406+ p. cargo ( "check -v" )
407+ . with_stderr_contains ( x ! ( "rustc" => "cfg" of "docsrs,test" ) ) // for foo
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+ "# ] ] )
418+ . run ( ) ;
419+ }
420+
421+ #[ cargo_test( nightly, reason = "warning currently only on nightly" ) ]
422+ fn test_false_examples ( ) {
423+ let p = project ( )
424+ . file (
425+ "Cargo.toml" ,
426+ r#"
427+ [package]
428+ name = "foo"
429+ version = "0.1.0"
430+ edition = "2018"
431+
432+ [lib]
433+ test = false
434+
435+ [[example]]
436+ name = "daemon"
437+ test = false
438+ path = "src/deamon.rs"
439+ "# ,
440+ )
441+ . file ( "src/lib.rs" , "#[cfg(test)] mod tests {}" )
442+ . file ( "src/deamon.rs" , "fn main() {}\n #[cfg(test)] mod tests {}" )
443+ . build ( ) ;
444+
445+ p. cargo ( "check --examples -v" )
446+ . with_stderr_does_not_contain ( x ! ( "rustc" => "cfg" of "docsrs,test" ) )
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+ "# ] ] )
462+ . run ( ) ;
463+ }
464+
465+ #[ cargo_test(
466+ nightly,
467+ reason = "bench is nightly & warning currently only on nightly"
468+ ) ]
469+ fn test_false_benches ( ) {
470+ let p = project ( )
471+ . file (
472+ "Cargo.toml" ,
473+ r#"
474+ [package]
475+ name = "foo"
476+ version = "0.0.0"
477+ edition = "2018"
478+
479+ [[bench]]
480+ name = "ben1"
481+ test = false
482+ path = "benches/ben1.rs"
483+ "# ,
484+ )
485+ . file ( "src/lib.rs" , "" )
486+ . file (
487+ "benches/ben1.rs" ,
488+ r#"
489+ #![feature(test)]
490+ extern crate test;
491+ #[bench] fn run1(_ben: &mut test::Bencher) { }
492+ "# ,
493+ )
494+ . build ( ) ;
495+
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+ "# ] ] )
504+ . run ( ) ;
505+ }
506+
320507#[ cargo_test]
321508fn features_doc ( ) {
322509 let p = project ( )
0 commit comments