@@ -155,16 +155,6 @@ fn bad_target_name() {
155
155
"failed to parse `!foo` as a cfg expression: \
156
156
invalid target specifier: unexpected character ! in target name",
157
157
) ;
158
- bad :: < Platform > (
159
- "cfg(debug_assertions)" ,
160
- "failed to parse `debug_assertions` as a cfg expression: \
161
- invalid name in target cfg: debug_assertions",
162
- ) ;
163
- bad :: < Platform > (
164
- "cfg(feature = \" abc\" )" ,
165
- "failed to parse `feature = \" abc\" ` as a cfg expression: \
166
- invalid key in target cfg: feature",
167
- ) ;
168
158
}
169
159
170
160
#[ test]
@@ -186,3 +176,76 @@ fn round_trip_platform() {
186
176
all(target_os = \" freebsd\" , target_arch = \" x86_64\" )))",
187
177
) ;
188
178
}
179
+
180
+ #[ test]
181
+ fn check_cfg_attributes ( ) {
182
+ fn ok ( s : & str ) {
183
+ let p = Platform :: Cfg ( s. parse ( ) . unwrap ( ) ) ;
184
+ let mut warnings = Vec :: new ( ) ;
185
+ p. check_cfg_attributes ( & mut warnings) ;
186
+ assert ! (
187
+ warnings. is_empty( ) ,
188
+ "Expected no warnings but got: {:?}" ,
189
+ warnings,
190
+ ) ;
191
+ }
192
+
193
+ fn warn ( s : & str , names : & [ & str ] ) {
194
+ let p = Platform :: Cfg ( s. parse ( ) . unwrap ( ) ) ;
195
+ let mut warnings = Vec :: new ( ) ;
196
+ p. check_cfg_attributes ( & mut warnings) ;
197
+ assert_eq ! (
198
+ warnings. len( ) ,
199
+ names. len( ) ,
200
+ "Expecter warnings about {:?} but got {:?}" ,
201
+ names,
202
+ warnings,
203
+ ) ;
204
+ for ( name, warning) in names. iter ( ) . zip ( warnings. iter ( ) ) {
205
+ assert ! (
206
+ warning. contains( name) ,
207
+ "Expected warning about '{}' but got: {}" ,
208
+ name,
209
+ warning,
210
+ ) ;
211
+ }
212
+ }
213
+
214
+ ok ( "unix" ) ;
215
+ ok ( "windows" ) ;
216
+ ok ( "any(not(unix), windows)" ) ;
217
+ ok ( "foo" ) ;
218
+
219
+ ok ( "target_arch = \" abc\" " ) ;
220
+ ok ( "target_feature = \" abc\" " ) ;
221
+ ok ( "target_os = \" abc\" " ) ;
222
+ ok ( "target_family = \" abc\" " ) ;
223
+ ok ( "target_env = \" abc\" " ) ;
224
+ ok ( "target_endian = \" abc\" " ) ;
225
+ ok ( "target_pointer_width = \" abc\" " ) ;
226
+ ok ( "target_vendor = \" abc\" " ) ;
227
+ ok ( "bar = \" def\" " ) ;
228
+
229
+ warn ( "test" , & [ "test" ] ) ;
230
+ warn ( "debug_assertions" , & [ "debug_assertions" ] ) ;
231
+ warn ( "proc_macro" , & [ "proc_macro" ] ) ;
232
+ warn ( "feature = \" abc\" " , & [ "feature" ] ) ;
233
+
234
+ warn ( "any(not(debug_assertions), windows)" , & [ "debug_assertions" ] ) ;
235
+ warn (
236
+ "any(not(feature = \" def\" ), target_arch = \" abc\" )" ,
237
+ & [ "feature" ] ,
238
+ ) ;
239
+ warn (
240
+ "any(not(target_os = \" windows\" ), proc_macro)" ,
241
+ & [ "proc_macro" ] ,
242
+ ) ;
243
+ warn (
244
+ "any(not(feature = \" windows\" ), proc_macro)" ,
245
+ & [ "feature" , "proc_macro" ] ,
246
+ ) ;
247
+ warn (
248
+ "all(not(debug_assertions), any(windows, proc_macro))" ,
249
+ & [ "debug_assertions" , "proc_macro" ] ,
250
+ ) ;
251
+ }
0 commit comments