@@ -8,61 +8,70 @@ use std::ops::Deref;
88
99use run_make_support:: rustc;
1010
11+ struct CheckCfg {
12+ args : & ' static [ & ' static str ] ,
13+ contains : Contains ,
14+ }
15+
16+ enum Contains {
17+ Some { contains : & ' static [ & ' static str ] , doesnt_contain : & ' static [ & ' static str ] } ,
18+ Only ( & ' static str ) ,
19+ }
20+
1121fn main ( ) {
12- check (
13- /*args*/ & [ ] ,
14- /*has_any*/ false ,
15- /*has_any_any*/ true ,
16- /*contains*/ & [ ] ,
17- ) ;
18- check (
19- /*args*/ & [ "--check-cfg=cfg()" ] ,
20- /*has_any*/ false ,
21- /*has_any_any*/ false ,
22- /*contains*/ & [ "unix" , "miri" ] ,
23- ) ;
24- check (
25- /*args*/ & [ "--check-cfg=cfg(any())" ] ,
26- /*has_any*/ true ,
27- /*has_any_any*/ false ,
28- /*contains*/ & [ "windows" , "test" ] ,
29- ) ;
30- check (
31- /*args*/ & [ "--check-cfg=cfg(feature)" ] ,
32- /*has_any*/ false ,
33- /*has_any_any*/ false ,
34- /*contains*/ & [ "unix" , "miri" , "feature" ] ,
35- ) ;
36- check (
37- /*args*/ & [ r#"--check-cfg=cfg(feature, values(none(), "", "test", "lol"))"# ] ,
38- /*has_any*/ false ,
39- /*has_any_any*/ false ,
40- /*contains*/ & [ "feature" , "feature=\" \" " , "feature=\" test\" " , "feature=\" lol\" " ] ,
41- ) ;
42- check (
43- /*args*/
44- & [
22+ check ( CheckCfg { args : & [ ] , contains : Contains :: Only ( "any()=any()" ) } ) ;
23+ check ( CheckCfg {
24+ args : & [ "--check-cfg=cfg()" ] ,
25+ contains : Contains :: Some {
26+ contains : & [ "unix" , "miri" ] ,
27+ doesnt_contain : & [ "any()" , "any()=any()" ] ,
28+ } ,
29+ } ) ;
30+ check ( CheckCfg {
31+ args : & [ "--check-cfg=cfg(any())" ] ,
32+ contains : Contains :: Some {
33+ contains : & [ "any()" , "unix" , r#"target_feature="crt-static""# ] ,
34+ doesnt_contain : & [ "any()=any()" ] ,
35+ } ,
36+ } ) ;
37+ check ( CheckCfg {
38+ args : & [ "--check-cfg=cfg(feature)" ] ,
39+ contains : Contains :: Some {
40+ contains : & [ "unix" , "miri" , "feature" ] ,
41+ doesnt_contain : & [ "any()" , "any()=any()" , "feature=none()" , "feature=" ] ,
42+ } ,
43+ } ) ;
44+ check ( CheckCfg {
45+ args : & [ r#"--check-cfg=cfg(feature, values(none(), "", "test", "lol"))"# ] ,
46+ contains : Contains :: Some {
47+ contains : & [ "feature" , "feature=\" \" " , "feature=\" test\" " , "feature=\" lol\" " ] ,
48+ doesnt_contain : & [ "any()" , "any()=any()" , "feature=none()" , "feature=" ] ,
49+ } ,
50+ } ) ;
51+ check ( CheckCfg {
52+ args : & [
4553 r#"--check-cfg=cfg(feature, values(any()))"# ,
4654 r#"--check-cfg=cfg(feature, values("tmp"))"# ,
4755 ] ,
48- /*has_any*/ false ,
49- /*has_any_any*/ false ,
50- /*contains*/ & [ "unix " , "miri " , "feature=any() " ] ,
51- ) ;
52- check (
53- /*args*/
54- & [
56+ contains : Contains :: Some {
57+ contains : & [ "unix" , "miri" , "feature=any()" ] ,
58+ doesnt_contain : & [ "any() " , "any()=any() " , "feature" , "feature=" , "feature= \" tmp \" "] ,
59+ } ,
60+ } ) ;
61+ check ( CheckCfg {
62+ args : & [
5563 r#"--check-cfg=cfg(has_foo, has_bar)"# ,
5664 r#"--check-cfg=cfg(feature, values("tmp"))"# ,
5765 r#"--check-cfg=cfg(feature, values("tmp"))"# ,
5866 ] ,
59- /*has_any*/ false ,
60- /*has_any_any*/ false ,
61- /*contains*/ & [ "has_foo" , "has_bar" , "feature=\" tmp\" " ] ,
62- ) ;
67+ contains : Contains :: Some {
68+ contains : & [ "has_foo" , "has_bar" , "feature=\" tmp\" " ] ,
69+ doesnt_contain : & [ "any()" , "any()=any()" , "feature" ] ,
70+ } ,
71+ } ) ;
6372}
6473
65- fn check ( args : & [ & str ] , has_any : bool , has_any_any : bool , contains : & [ & str ] ) {
74+ fn check ( CheckCfg { args , contains } : CheckCfg ) {
6675 let output = rustc ( )
6776 . input ( "lib.rs" )
6877 . arg ( "-Zunstable-options" )
@@ -72,18 +81,11 @@ fn check(args: &[&str], has_any: bool, has_any_any: bool, contains: &[&str]) {
7281
7382 let stdout = String :: from_utf8 ( output. stdout ) . unwrap ( ) ;
7483
75- let mut found_any = false ;
76- let mut found_any_any = false ;
7784 let mut found = HashSet :: < String > :: new ( ) ;
78- let mut recorded = HashSet :: < String > :: new ( ) ;
7985
8086 for l in stdout. lines ( ) {
8187 assert ! ( l == l. trim( ) ) ;
82- if l == "any()" {
83- found_any = true ;
84- } else if l == "any()=any()" {
85- found_any_any = true ;
86- } else if let Some ( ( left, right) ) = l. split_once ( '=' ) {
88+ if let Some ( ( left, right) ) = l. split_once ( '=' ) {
8789 if right != "any()" && right != "" {
8890 assert ! ( right. starts_with( "\" " ) ) ;
8991 assert ! ( right. ends_with( "\" " ) ) ;
@@ -92,17 +94,37 @@ fn check(args: &[&str], has_any: bool, has_any_any: bool, contains: &[&str]) {
9294 } else {
9395 assert ! ( !l. contains( "\" " ) ) ;
9496 }
95- assert ! ( recorded. insert( l. to_string( ) ) , "{}" , & l) ;
96- if contains. contains ( & l) {
97- assert ! ( found. insert( l. to_string( ) ) , "{}" , & l) ;
98- }
97+ assert ! ( found. insert( l. to_string( ) ) , "{}" , & l) ;
9998 }
10099
101- let should_found = HashSet :: < String > :: from_iter ( contains. iter ( ) . map ( |s| s. to_string ( ) ) ) ;
102- let diff: Vec < _ > = should_found. difference ( & found) . collect ( ) ;
103-
104- assert_eq ! ( found_any, has_any) ;
105- assert_eq ! ( found_any_any, has_any_any) ;
106- assert_eq ! ( found_any_any, recorded. len( ) == 1 ) ;
107- assert ! ( diff. is_empty( ) , "{:?} != {:?} (~ {:?})" , & should_found, & found, & diff) ;
100+ match contains {
101+ Contains :: Some { contains, doesnt_contain } => {
102+ {
103+ let should_found =
104+ HashSet :: < String > :: from_iter ( contains. iter ( ) . map ( |s| s. to_string ( ) ) ) ;
105+ let diff: Vec < _ > = should_found. difference ( & found) . collect ( ) ;
106+ assert ! (
107+ diff. is_empty( ) ,
108+ "should found: {:?}, didn't found {:?}" ,
109+ & should_found,
110+ & diff
111+ ) ;
112+ }
113+ {
114+ let should_not_find =
115+ HashSet :: < String > :: from_iter ( doesnt_contain. iter ( ) . map ( |s| s. to_string ( ) ) ) ;
116+ let diff: Vec < _ > = should_not_find. intersection ( & found) . collect ( ) ;
117+ assert ! (
118+ diff. is_empty( ) ,
119+ "should not find {:?}, did found {:?}" ,
120+ & should_not_find,
121+ & diff
122+ ) ;
123+ }
124+ }
125+ Contains :: Only ( only) => {
126+ assert ! ( found. contains( & only. to_string( ) ) , "{:?} != {:?}" , & only, & found) ;
127+ assert ! ( found. len( ) == 1 , "len: {}, instead of 1" , found. len( ) ) ;
128+ }
129+ }
108130}
0 commit comments