@@ -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,61 @@ 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 < ( ) > {
287
+ // Ignore directories that contain a file
288
+ // `compiletest-ignore-dir`.
289
+ for file in try!( fs:: read_dir ( dir) ) {
290
+ let file = try!( file) ;
291
+ if file. file_name ( ) == * "compiletest-ignore-dir" {
292
+ return Ok ( ( ) ) ;
293
+ }
294
+ }
295
+
296
+ let dirs = try!( fs:: read_dir ( dir) ) ;
271
297
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) )
298
+ let file = try!( file) ;
299
+ let file_path = file. path ( ) ;
300
+ debug ! ( "inspecting file {:?}" , file_path. display( ) ) ;
301
+ if is_test ( config, & file_path) {
302
+ // If we find a test foo/bar.rs, we have to build the
303
+ // output directory `$build/foo` so we can write
304
+ // `$build/foo/bar` into it. We do this *now* in this
305
+ // sequential loop because otherwise, if we do it in the
306
+ // tests themselves, they race for the privilege of
307
+ // creating the directories and sometimes fail randomly.
308
+ let build_dir = config. build_base . join ( & relative_dir_path) ;
309
+ fs:: create_dir_all ( & build_dir) . unwrap ( ) ;
310
+
311
+ let paths = TestPaths {
312
+ file : file_path,
313
+ base : base. to_path_buf ( ) ,
314
+ relative_dir : relative_dir_path. to_path_buf ( ) ,
315
+ } ;
316
+ tests. push ( make_test ( config, & paths) )
317
+ } else if file_path. is_dir ( ) {
318
+ let relative_file_path = relative_dir_path. join ( file. file_name ( ) ) ;
319
+ try!( collect_tests_from_dir ( config,
320
+ base,
321
+ & file_path,
322
+ & relative_file_path,
323
+ tests) ) ;
276
324
}
277
325
}
278
- tests
326
+ Ok ( ( ) )
279
327
}
280
328
281
329
pub fn is_test ( config : & Config , testfile : & Path ) -> bool {
@@ -305,36 +353,33 @@ pub fn is_test(config: &Config, testfile: &Path) -> bool {
305
353
return valid;
306
354
}
307
355
308
- pub fn make_test ( config : & Config , testfile : & Path ) -> test:: TestDescAndFn
309
- {
356
+ pub fn make_test ( config : & Config , testpaths : & TestPaths ) -> test:: TestDescAndFn {
310
357
test:: TestDescAndFn {
311
358
desc : test:: TestDesc {
312
- name : make_test_name ( config, testfile ) ,
313
- ignore : header:: is_test_ignored ( config, testfile ) ,
359
+ name : make_test_name ( config, testpaths ) ,
360
+ ignore : header:: is_test_ignored ( config, & testpaths . file ) ,
314
361
should_panic : test:: ShouldPanic :: No ,
315
362
} ,
316
- testfn : make_test_closure ( config, & testfile ) ,
363
+ testfn : make_test_closure ( config, testpaths ) ,
317
364
}
318
365
}
319
366
320
- pub fn make_test_name ( config : & Config , testfile : & Path ) -> test:: TestName {
321
-
322
- // Try to elide redundant long paths
323
- fn shorten ( path : & Path ) -> String {
324
- let filename = path. file_name ( ) . unwrap ( ) . to_str ( ) ;
325
- let p = path. parent ( ) . unwrap ( ) ;
326
- let dir = p. file_name ( ) . unwrap ( ) . to_str ( ) ;
327
- format ! ( "{}/{}" , dir. unwrap_or( "" ) , filename. unwrap_or( "" ) )
328
- }
329
-
330
- test:: DynTestName ( format ! ( "[{}] {}" , config. mode, shorten( testfile) ) )
367
+ pub fn make_test_name ( config : & Config , testpaths : & TestPaths ) -> test:: TestName {
368
+ // Convert a complete path to something like
369
+ //
370
+ // run-pass/foo/bar/baz.rs
371
+ let path =
372
+ PathBuf :: from ( config. mode . to_string ( ) )
373
+ . join ( & testpaths. relative_dir )
374
+ . join ( & testpaths. file . file_name ( ) . unwrap ( ) ) ;
375
+ test:: DynTestName ( format ! ( "[{}] {}" , config. mode, path. display( ) ) )
331
376
}
332
377
333
- pub fn make_test_closure ( config : & Config , testfile : & Path ) -> test:: TestFn {
334
- let config = ( * config) . clone ( ) ;
335
- let testfile = testfile . to_path_buf ( ) ;
378
+ pub fn make_test_closure ( config : & Config , testpaths : & TestPaths ) -> test:: TestFn {
379
+ let config = config. clone ( ) ;
380
+ let testpaths = testpaths . clone ( ) ;
336
381
test:: DynTestFn ( Box :: new ( move || {
337
- runtest:: run ( config, & testfile )
382
+ runtest:: run ( config, & testpaths )
338
383
} ) )
339
384
}
340
385
0 commit comments