@@ -28,10 +28,12 @@ extern crate log;
2828
2929use std:: env;
3030use std:: fs;
31+ use std:: io;
3132use std:: path:: { Path , PathBuf } ;
3233use getopts:: { optopt, optflag, reqopt} ;
3334use common:: Config ;
3435use common:: { Pretty , DebugInfoGdb , DebugInfoLldb } ;
36+ use test:: TestPaths ;
3537use util:: logv;
3638
3739pub mod procsrv;
@@ -267,15 +269,35 @@ pub fn make_tests(config: &Config) -> Vec<test::TestDescAndFn> {
267269 debug ! ( "making tests from {:?}" ,
268270 config. src_base. display( ) ) ;
269271 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 < ( ) > {
271287 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) )
276298 }
277299 }
278- tests
300+ Ok ( ( ) )
279301}
280302
281303pub fn is_test ( config : & Config , testfile : & Path ) -> bool {
@@ -305,15 +327,14 @@ pub fn is_test(config: &Config, testfile: &Path) -> bool {
305327 return valid;
306328}
307329
308- pub fn make_test ( config : & Config , testfile : & Path ) -> test:: TestDescAndFn
309- {
330+ pub fn make_test ( config : & Config , testpaths : & TestPaths ) -> test:: TestDescAndFn {
310331 test:: TestDescAndFn {
311332 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 ) ,
314335 should_panic : test:: ShouldPanic :: No ,
315336 } ,
316- testfn : make_test_closure ( config, & testfile ) ,
337+ testfn : make_test_closure ( config, testpaths ) ,
317338 }
318339}
319340
@@ -330,11 +351,11 @@ pub fn make_test_name(config: &Config, testfile: &Path) -> test::TestName {
330351 test:: DynTestName ( format ! ( "[{}] {}" , config. mode, shorten( testfile) ) )
331352}
332353
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 ( ) ;
336357 test:: DynTestFn ( Box :: new ( move || {
337- runtest:: run ( config, & testfile )
358+ runtest:: run ( config, & testpaths )
338359 } ) )
339360}
340361
0 commit comments