11//! Tests for Cargo usage of rustc `--check-cfg`.
22
3- #![ allow( deprecated) ]
4-
5- use cargo_test_support:: { basic_manifest, project} ;
3+ use cargo_test_support:: prelude:: * ;
4+ use cargo_test_support:: { basic_manifest, project, str} ;
65
76macro_rules! x {
87 ( $tool: tt => $what: tt $( of $who: tt) ?) => { {
@@ -31,6 +30,7 @@ macro_rules! x {
3130 } } ;
3231}
3332
33+ #[ allow( deprecated) ]
3434#[ cargo_test]
3535fn features ( ) {
3636 let p = project ( )
@@ -53,10 +53,10 @@ fn features() {
5353 p. cargo ( "check -v" )
5454 . with_stderr_contains ( x ! ( "rustc" => "cfg" of "feature" with "f_a" "f_b" ) )
5555 . with_stderr_contains ( x ! ( "rustc" => "cfg" of "docsrs" ) )
56- . with_stderr_does_not_contain ( "[..]-Zunstable-options[..]" )
5756 . run ( ) ;
5857}
5958
59+ #[ allow( deprecated) ]
6060#[ cargo_test]
6161fn features_with_deps ( ) {
6262 let p = project ( )
@@ -87,6 +87,7 @@ fn features_with_deps() {
8787 . run ( ) ;
8888}
8989
90+ #[ allow( deprecated) ]
9091#[ cargo_test]
9192fn features_with_opt_deps ( ) {
9293 let p = project ( )
@@ -118,6 +119,7 @@ fn features_with_opt_deps() {
118119 . run ( ) ;
119120}
120121
122+ #[ allow( deprecated) ]
121123#[ cargo_test]
122124fn features_with_namespaced_features ( ) {
123125 let p = project ( )
@@ -148,6 +150,7 @@ fn features_with_namespaced_features() {
148150 . run ( ) ;
149151}
150152
153+ #[ allow( deprecated) ]
151154#[ cargo_test]
152155fn features_fingerprint ( ) {
153156 let p = project ( )
@@ -210,14 +213,22 @@ fn features_fingerprint() {
210213
211214 p. cargo ( "check -v" )
212215 // we check that the fingerprint is indeed dirty
213- . with_stderr_contains ( "[..]Dirty[..]the list of declared features changed" )
214216 // that is cause rustc to be called again with the new check-cfg args
215- . with_stderr_contains ( x ! ( "rustc" => "cfg" of "feature" with "f_a" ) )
216217 // and that we indeed found a new warning from the unexpected_cfgs lint
217- . with_stderr_contains ( "[..]unexpected_cfgs[..]" )
218+ . with_stderr_data ( format ! (
219+ "\
220+ [DIRTY] foo v0.1.0 ([ROOT]/foo): the list of declared features changed
221+ [CHECKING] foo v0.1.0 ([ROOT]/foo)
222+ {running_rustc}
223+ [WARNING] unexpected `cfg` condition value: `f_b`
224+ ...
225+ " ,
226+ running_rustc = x!( "rustc" => "cfg" of "feature" with "f_a" )
227+ ) )
218228 . run ( ) ;
219229}
220230
231+ #[ allow( deprecated) ]
221232#[ cargo_test]
222233fn well_known_names_values ( ) {
223234 let p = project ( )
@@ -231,6 +242,7 @@ fn well_known_names_values() {
231242 . run ( ) ;
232243}
233244
245+ #[ allow( deprecated) ]
234246#[ cargo_test]
235247fn features_test ( ) {
236248 let p = project ( )
@@ -256,6 +268,7 @@ fn features_test() {
256268 . run ( ) ;
257269}
258270
271+ #[ allow( deprecated) ]
259272#[ cargo_test]
260273fn features_doctest ( ) {
261274 let p = project ( )
@@ -281,10 +294,10 @@ fn features_doctest() {
281294 . with_stderr_contains ( x ! ( "rustdoc" => "cfg" of "feature" with "default" "f_a" "f_b" ) )
282295 . with_stderr_contains ( x ! ( "rustc" => "cfg" of "docsrs" ) )
283296 . with_stderr_contains ( x ! ( "rustdoc" => "cfg" of "docsrs" ) )
284- . with_stderr_does_not_contain ( "[..]-Zunstable-options[..]" )
285297 . run ( ) ;
286298}
287299
300+ #[ allow( deprecated) ]
288301#[ cargo_test]
289302fn well_known_names_values_test ( ) {
290303 let p = project ( )
@@ -298,6 +311,7 @@ fn well_known_names_values_test() {
298311 . run ( ) ;
299312}
300313
314+ #[ allow( deprecated) ]
301315#[ cargo_test]
302316fn well_known_names_values_doctest ( ) {
303317 let p = project ( )
@@ -313,6 +327,7 @@ fn well_known_names_values_doctest() {
313327 . run ( ) ;
314328}
315329
330+ #[ allow( deprecated) ]
316331#[ cargo_test]
317332fn features_doc ( ) {
318333 let p = project ( )
@@ -336,10 +351,10 @@ fn features_doc() {
336351 p. cargo ( "doc -v" )
337352 . with_stderr_contains ( x ! ( "rustdoc" => "cfg" of "feature" with "default" "f_a" "f_b" ) )
338353 . with_stderr_contains ( x ! ( "rustdoc" => "cfg" of "docsrs" ) )
339- . with_stderr_does_not_contain ( "[..]-Zunstable-options[..]" )
340354 . run ( ) ;
341355}
342356
357+ #[ allow( deprecated) ]
343358#[ cargo_test]
344359fn build_script_feedback ( ) {
345360 let p = project ( )
@@ -364,10 +379,10 @@ fn build_script_feedback() {
364379 p. cargo ( "check -v" )
365380 . with_stderr_contains ( x ! ( "rustc" => "cfg" of "foo" ) )
366381 . with_stderr_contains ( x ! ( "rustc" => "cfg" of "docsrs" ) )
367- . with_stderr_does_not_contain ( "[..]-Zunstable-options[..]" )
368382 . run ( ) ;
369383}
370384
385+ #[ allow( deprecated) ]
371386#[ cargo_test]
372387fn build_script_doc ( ) {
373388 let p = project ( )
@@ -391,21 +406,22 @@ fn build_script_doc() {
391406
392407 p. cargo ( "doc -v" )
393408 . with_stderr_does_not_contain ( "rustc [..] --check-cfg [..]" )
394- . with_stderr_contains ( x ! ( "rustdoc" => "cfg" of "foo" ) )
395- . with_stderr (
409+ . with_stderr_data ( format ! (
396410 "\
397- [COMPILING] foo v0.0.1 ([CWD] )
411+ [COMPILING] foo v0.0.1 ([ROOT]/foo )
398412[RUNNING] `rustc [..] build.rs [..]`
399- [RUNNING] `[.. ]/build-script-build`
400- [DOCUMENTING] foo [..]
401- [RUNNING] `rustdoc [..] src/main.rs [..]
402- [FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [..]
403- [GENERATED] [CWD] /target/doc/foo/index.html
413+ [RUNNING] `[ROOT]/foo/target/debug/build/foo-[HASH ]/build-script-build`
414+ [DOCUMENTING] foo v0.0.1 ([ROOT]/foo)
415+ {running_rustdoc}
416+ [FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
417+ [GENERATED] [ROOT]/foo /target/doc/foo/index.html
404418" ,
405- )
419+ running_rustdoc = x!( "rustdoc" => "cfg" of "foo" )
420+ ) )
406421 . run ( ) ;
407422}
408423
424+ #[ allow( deprecated) ]
409425#[ cargo_test]
410426fn build_script_override ( ) {
411427 let target = cargo_test_support:: rustc_host ( ) ;
@@ -491,14 +507,31 @@ fn build_script_test() {
491507 . build ( ) ;
492508
493509 p. cargo ( "test -v" )
494- . with_stderr_contains ( x ! ( "rustc" => "cfg" of "foo" ) )
495- . with_stderr_contains ( x ! ( "rustdoc" => "cfg" of "foo" ) )
496- . with_stdout_contains ( "test test_foo ... ok" )
497- . with_stdout_contains ( "test test_bar ... ok" )
498- . with_stdout_contains_n ( "test [..] ... ok" , 3 )
510+ . with_stderr_data (
511+ format ! (
512+ "\
513+ {running_rustc}
514+ {running_rustdoc}
515+ ...
516+ " ,
517+ running_rustc = x!( "rustc" => "cfg" of "foo" ) ,
518+ running_rustdoc = x!( "rustdoc" => "cfg" of "foo" )
519+ )
520+ . unordered ( ) ,
521+ )
522+ . with_stdout_data (
523+ str![ [ r#"
524+ test test_foo ... ok
525+ test test_bar ... ok
526+ test [..] ... ok
527+ ...
528+ "# ] ]
529+ . unordered ( ) ,
530+ )
499531 . run ( ) ;
500532}
501533
534+ #[ allow( deprecated) ]
502535#[ cargo_test]
503536fn config_simple ( ) {
504537 let p = project ( )
@@ -524,6 +557,7 @@ fn config_simple() {
524557 . run ( ) ;
525558}
526559
560+ #[ allow( deprecated) ]
527561#[ cargo_test]
528562fn config_workspace ( ) {
529563 let p = project ( )
@@ -553,11 +587,19 @@ fn config_workspace() {
553587 . build ( ) ;
554588
555589 p. cargo ( "check -v" )
556- . with_stderr_contains ( x ! ( "rustc" => "cfg" of "has_foo" ) )
590+ . with_stderr_data ( format ! (
591+ "\
592+ ...
593+ {running_rustc}
594+ ...
595+ " ,
596+ running_rustc = x!( "rustc" => "cfg" of "has_foo" )
597+ ) )
557598 . with_stderr_does_not_contain ( "unexpected_cfgs" )
558599 . run ( ) ;
559600}
560601
602+ #[ allow( deprecated) ]
561603#[ cargo_test]
562604fn config_workspace_not_inherited ( ) {
563605 let p = project ( )
@@ -589,6 +631,7 @@ fn config_workspace_not_inherited() {
589631 . run ( ) ;
590632}
591633
634+ #[ allow( deprecated) ]
592635#[ cargo_test]
593636fn config_invalid_position ( ) {
594637 let p = project ( )
@@ -608,7 +651,10 @@ fn config_invalid_position() {
608651 . build ( ) ;
609652
610653 p. cargo ( "check -v" )
611- . with_stderr_contains ( "[..]unused manifest key: `lints.rust.use_bracket.check-cfg`[..]" )
654+ . with_stderr_data ( str![ [ r#"
655+ [WARNING] unused manifest key: `lints.rust.use_bracket.check-cfg`
656+ ...
657+ "# ] ] )
612658 . with_stderr_does_not_contain ( x ! ( "rustc" => "cfg" of "has_foo" ) )
613659 . run ( ) ;
614660}
@@ -633,7 +679,10 @@ fn config_invalid_empty() {
633679
634680 p. cargo ( "check" )
635681 . with_status ( 101 )
636- . with_stderr_contains ( "[..]missing field `level`[..]" )
682+ . with_stderr_data ( str![ [ r#"
683+ [ERROR] missing field `level`
684+ ...
685+ "# ] ] )
637686 . run ( ) ;
638687}
639688
@@ -657,9 +706,10 @@ fn config_invalid_not_list() {
657706
658707 p. cargo ( "check" )
659708 . with_status ( 101 )
660- . with_stderr_contains (
661- "[ERROR] `lints.rust.unexpected_cfgs.check-cfg` must be a list of string" ,
662- )
709+ . with_stderr_data ( str![ [ r#"
710+ [ERROR] `lints.rust.unexpected_cfgs.check-cfg` must be a list of string
711+ ...
712+ "# ] ] )
663713 . run ( ) ;
664714}
665715
@@ -683,12 +733,14 @@ fn config_invalid_not_list_string() {
683733
684734 p. cargo ( "check" )
685735 . with_status ( 101 )
686- . with_stderr_contains (
687- "[ERROR] `lints.rust.unexpected_cfgs.check-cfg` must be a list of string" ,
688- )
736+ . with_stderr_data ( str![ [ r#"
737+ [ERROR] `lints.rust.unexpected_cfgs.check-cfg` must be a list of string
738+ ...
739+ "# ] ] )
689740 . run ( ) ;
690741}
691742
743+ #[ allow( deprecated) ]
692744#[ cargo_test]
693745fn config_and_features ( ) {
694746 let p = project ( )
@@ -737,7 +789,14 @@ fn config_with_cargo_doc() {
737789 . build ( ) ;
738790
739791 p. cargo ( "doc -v" )
740- . with_stderr_contains ( x ! ( "rustdoc" => "cfg" of "has_foo" ) )
792+ . with_stderr_data ( format ! (
793+ "\
794+ ...
795+ {running_rustdoc}
796+ ...
797+ " ,
798+ running_rustdoc = x!( "rustdoc" => "cfg" of "has_foo" )
799+ ) )
741800 . run ( ) ;
742801}
743802
@@ -760,10 +819,18 @@ fn config_with_cargo_test() {
760819 . build ( ) ;
761820
762821 p. cargo ( "test -v" )
763- . with_stderr_contains ( x ! ( "rustc" => "cfg" of "has_foo" ) )
822+ . with_stderr_data ( format ! (
823+ "\
824+ ...
825+ {running_rustc}
826+ ...
827+ " ,
828+ running_rustc = x!( "rustc" => "cfg" of "has_foo" )
829+ ) )
764830 . run ( ) ;
765831}
766832
833+ #[ allow( deprecated) ]
767834#[ cargo_test]
768835fn config_and_build_script ( ) {
769836 let p = project ( )
@@ -793,6 +860,7 @@ fn config_and_build_script() {
793860 . run ( ) ;
794861}
795862
863+ #[ allow( deprecated) ]
796864#[ cargo_test]
797865fn config_features_and_build_script ( ) {
798866 let p = project ( )
@@ -828,6 +896,7 @@ fn config_features_and_build_script() {
828896 . run ( ) ;
829897}
830898
899+ #[ allow( deprecated) ]
831900#[ cargo_test]
832901fn config_fingerprint ( ) {
833902 let p = project ( )
0 commit comments