@@ -28,10 +28,12 @@ extern crate log;
28
28
29
29
use std:: env;
30
30
use std:: fs;
31
+ use std:: io;
31
32
use std:: path:: { Path , PathBuf } ;
32
33
use getopts:: { optopt, optflag, reqopt} ;
33
34
use common:: Config ;
34
35
use common:: { Pretty , DebugInfoGdb , DebugInfoLldb } ;
36
+ use test:: TestPaths ;
35
37
use util:: logv;
36
38
37
39
pub mod procsrv;
@@ -267,15 +269,35 @@ pub fn make_tests(config: &Config) -> Vec<test::TestDescAndFn> {
267
269
debug ! ( "making tests from {:?}" ,
268
270
config. src_base. display( ) ) ;
269
271
let mut tests = Vec :: new ( ) ;
270
- let dirs = fs:: read_dir ( & config. src_base ) . unwrap ( ) ;
272
+ collect_tests_from_dir ( config,
273
+ & config. src_base ,
274
+ & config. src_base ,
275
+ & PathBuf :: new ( ) ,
276
+ & mut tests)
277
+ . unwrap ( ) ;
278
+ tests
279
+ }
280
+
281
+ fn collect_tests_from_dir ( config : & Config ,
282
+ base : & Path ,
283
+ dir : & Path ,
284
+ relative_dir_path : & Path ,
285
+ tests : & mut Vec < test:: TestDescAndFn > )
286
+ -> io:: Result < ( ) > {
271
287
for file in dirs {
272
- let file = file. unwrap ( ) . path ( ) ;
273
- debug ! ( "inspecting file {:?}" , file. display( ) ) ;
274
- if is_test ( config, & file) {
275
- tests. push ( make_test ( config, & file) )
288
+ let file = try!( file) ;
289
+ let file_path = file. path ( ) ;
290
+ debug ! ( "inspecting file {:?}" , file_path. display( ) ) ;
291
+ if is_test ( config, & file_path) {
292
+ let paths = TestPaths {
293
+ file : file_path,
294
+ base : base. to_path_buf ( ) ,
295
+ relative_dir : relative_dir_path. to_path_buf ( ) ,
296
+ } ;
297
+ tests. push ( make_test ( config, & paths) )
276
298
}
277
299
}
278
- tests
300
+ Ok ( ( ) )
279
301
}
280
302
281
303
pub fn is_test ( config : & Config , testfile : & Path ) -> bool {
@@ -305,15 +327,14 @@ pub fn is_test(config: &Config, testfile: &Path) -> bool {
305
327
return valid;
306
328
}
307
329
308
- pub fn make_test ( config : & Config , testfile : & Path ) -> test:: TestDescAndFn
309
- {
330
+ pub fn make_test ( config : & Config , testpaths : & TestPaths ) -> test:: TestDescAndFn {
310
331
test:: TestDescAndFn {
311
332
desc : test:: TestDesc {
312
- name : make_test_name ( config, testfile ) ,
313
- ignore : header:: is_test_ignored ( config, testfile ) ,
333
+ name : make_test_name ( config, testpaths ) ,
334
+ ignore : header:: is_test_ignored ( config, & testpaths . file ) ,
314
335
should_panic : test:: ShouldPanic :: No ,
315
336
} ,
316
- testfn : make_test_closure ( config, & testfile ) ,
337
+ testfn : make_test_closure ( config, testpaths ) ,
317
338
}
318
339
}
319
340
@@ -330,11 +351,11 @@ pub fn make_test_name(config: &Config, testfile: &Path) -> test::TestName {
330
351
test:: DynTestName ( format ! ( "[{}] {}" , config. mode, shorten( testfile) ) )
331
352
}
332
353
333
- pub fn make_test_closure ( config : & Config , testfile : & Path ) -> test:: TestFn {
334
- let config = ( * config) . clone ( ) ;
335
- let testfile = testfile . to_path_buf ( ) ;
354
+ pub fn make_test_closure ( config : & Config , testpaths : & TestPaths ) -> test:: TestFn {
355
+ let config = config. clone ( ) ;
356
+ let testpaths = testpaths . clone ( ) ;
336
357
test:: DynTestFn ( Box :: new ( move || {
337
- runtest:: run ( config, & testfile )
358
+ runtest:: run ( config, & testpaths )
338
359
} ) )
339
360
}
340
361
0 commit comments