@@ -164,8 +164,6 @@ pub fn load_props_into(props: &mut TestProps, testfile: &Path, cfg: Option<&str>
164
164
if let Some ( of) = parse_forbid_output ( ln) {
165
165
props. forbid_output . push ( of) ;
166
166
}
167
-
168
- true
169
167
} ) ;
170
168
171
169
for key in vec ! [ "RUST_TEST_NOCAPTURE" , "RUST_TEST_THREADS" ] {
@@ -179,7 +177,42 @@ pub fn load_props_into(props: &mut TestProps, testfile: &Path, cfg: Option<&str>
179
177
}
180
178
}
181
179
182
- pub fn is_test_ignored ( config : & Config , testfile : & Path ) -> bool {
180
+ pub struct EarlyProps {
181
+ pub ignore : bool ,
182
+ pub should_panic : bool ,
183
+ }
184
+
185
+ // scan the file to detect whether the test should be ignored and
186
+ // whether it should panic; these are two things the test runner needs
187
+ // to know early, before actually running the test
188
+ pub fn early_props ( config : & Config , testfile : & Path ) -> EarlyProps {
189
+ let mut props = EarlyProps {
190
+ ignore : false ,
191
+ should_panic : false ,
192
+ } ;
193
+
194
+ iter_header ( testfile, None , & mut |ln| {
195
+ props. ignore =
196
+ props. ignore ||
197
+ parse_name_directive ( ln, "ignore-test" ) ||
198
+ parse_name_directive ( ln, & ignore_target ( config) ) ||
199
+ parse_name_directive ( ln, & ignore_architecture ( config) ) ||
200
+ parse_name_directive ( ln, & ignore_stage ( config) ) ||
201
+ parse_name_directive ( ln, & ignore_env ( config) ) ||
202
+ ( config. mode == common:: Pretty &&
203
+ parse_name_directive ( ln, "ignore-pretty" ) ) ||
204
+ ( config. target != config. host &&
205
+ parse_name_directive ( ln, "ignore-cross-compile" ) ) ||
206
+ ignore_gdb ( config, ln) ||
207
+ ignore_lldb ( config, ln) ;
208
+
209
+ props. should_panic =
210
+ props. should_panic ||
211
+ parse_name_directive ( ln, "should-panic" ) ;
212
+ } ) ;
213
+
214
+ return props;
215
+
183
216
fn ignore_target ( config : & Config ) -> String {
184
217
format ! ( "ignore-{}" , util:: get_os( & config. target) )
185
218
}
@@ -246,26 +279,11 @@ pub fn is_test_ignored(config: &Config, testfile: &Path) -> bool {
246
279
false
247
280
}
248
281
}
249
-
250
- let val = iter_header ( testfile, None , & mut |ln| {
251
- !parse_name_directive ( ln, "ignore-test" ) &&
252
- !parse_name_directive ( ln, & ignore_target ( config) ) &&
253
- !parse_name_directive ( ln, & ignore_architecture ( config) ) &&
254
- !parse_name_directive ( ln, & ignore_stage ( config) ) &&
255
- !parse_name_directive ( ln, & ignore_env ( config) ) &&
256
- !( config. mode == common:: Pretty && parse_name_directive ( ln, "ignore-pretty" ) ) &&
257
- !( config. target != config. host && parse_name_directive ( ln, "ignore-cross-compile" ) ) &&
258
- !ignore_gdb ( config, ln) &&
259
- !ignore_lldb ( config, ln)
260
- } ) ;
261
-
262
- !val
263
282
}
264
283
265
284
fn iter_header ( testfile : & Path ,
266
285
cfg : Option < & str > ,
267
- it : & mut FnMut ( & str ) -> bool )
268
- -> bool {
286
+ it : & mut FnMut ( & str ) ) {
269
287
let rdr = BufReader :: new ( File :: open ( testfile) . unwrap ( ) ) ;
270
288
for ln in rdr. lines ( ) {
271
289
// Assume that any directives will be found before the first
@@ -274,7 +292,7 @@ fn iter_header(testfile: &Path,
274
292
let ln = ln. unwrap ( ) ;
275
293
let ln = ln. trim ( ) ;
276
294
if ln. starts_with ( "fn" ) || ln. starts_with ( "mod" ) {
277
- return true ;
295
+ return ;
278
296
} else if ln. starts_with ( "//[" ) {
279
297
// A comment like `//[foo]` is specific to revision `foo`
280
298
if let Some ( close_brace) = ln. find ( "]" ) {
@@ -283,20 +301,18 @@ fn iter_header(testfile: &Path,
283
301
Some ( s) => s == & lncfg[ ..] ,
284
302
None => false ,
285
303
} ;
286
- if matches && ! it ( & ln [ close_brace+ 1 .. ] ) {
287
- return false ;
304
+ if matches {
305
+ it ( & ln [ close_brace+ 1 .. ] ) ;
288
306
}
289
307
} else {
290
308
panic ! ( "malformed condition directive: expected `//[foo]`, found `{}`" ,
291
309
ln)
292
310
}
293
311
} else if ln. starts_with ( "//" ) {
294
- if !it ( & ln[ 2 ..] ) {
295
- return false ;
296
- }
312
+ it ( & ln[ 2 ..] ) ;
297
313
}
298
314
}
299
- return true ;
315
+ return ;
300
316
}
301
317
302
318
fn parse_error_pattern ( line : & str ) -> Option < String > {
0 commit comments