21
21
#![ feature( test) ]
22
22
#![ feature( unicode) ]
23
23
#![ feature( core) ]
24
+ #![ feature( path) ]
25
+ #![ feature( os) ]
26
+ #![ feature( io) ]
27
+ #![ feature( fs) ]
28
+ #![ feature( net) ]
24
29
25
30
#![ deny( warnings) ]
26
31
@@ -31,8 +36,9 @@ extern crate getopts;
31
36
extern crate log;
32
37
33
38
use std:: env;
39
+ use std:: fs;
34
40
use std:: old_io;
35
- use std:: old_io :: fs ;
41
+ use std:: path :: { Path , PathBuf } ;
36
42
use std:: thunk:: Thunk ;
37
43
use getopts:: { optopt, optflag, reqopt} ;
38
44
use common:: Config ;
@@ -114,9 +120,9 @@ pub fn parse_config(args: Vec<String> ) -> Config {
114
120
panic ! ( )
115
121
}
116
122
117
- fn opt_path ( m : & getopts:: Matches , nm : & str ) -> Path {
123
+ fn opt_path ( m : & getopts:: Matches , nm : & str ) -> PathBuf {
118
124
match m. opt_str ( nm) {
119
- Some ( s) => Path :: new ( s) ,
125
+ Some ( s) => PathBuf :: new ( & s) ,
120
126
None => panic ! ( "no option (=path) found for {}" , nm) ,
121
127
}
122
128
}
@@ -131,18 +137,18 @@ pub fn parse_config(args: Vec<String> ) -> Config {
131
137
compile_lib_path : matches. opt_str ( "compile-lib-path" ) . unwrap ( ) ,
132
138
run_lib_path : matches. opt_str ( "run-lib-path" ) . unwrap ( ) ,
133
139
rustc_path : opt_path ( matches, "rustc-path" ) ,
134
- clang_path : matches. opt_str ( "clang-path" ) . map ( |s| Path :: new ( s) ) ,
140
+ clang_path : matches. opt_str ( "clang-path" ) . map ( |s| PathBuf :: new ( & s) ) ,
135
141
valgrind_path : matches. opt_str ( "valgrind-path" ) ,
136
142
force_valgrind : matches. opt_present ( "force-valgrind" ) ,
137
- llvm_bin_path : matches. opt_str ( "llvm-bin-path" ) . map ( |s| Path :: new ( s) ) ,
143
+ llvm_bin_path : matches. opt_str ( "llvm-bin-path" ) . map ( |s| PathBuf :: new ( & s) ) ,
138
144
src_base : opt_path ( matches, "src-base" ) ,
139
145
build_base : opt_path ( matches, "build-base" ) ,
140
146
aux_base : opt_path ( matches, "aux-base" ) ,
141
147
stage_id : matches. opt_str ( "stage-id" ) . unwrap ( ) ,
142
148
mode : matches. opt_str ( "mode" ) . unwrap ( ) . parse ( ) . ok ( ) . expect ( "invalid mode" ) ,
143
149
run_ignored : matches. opt_present ( "ignored" ) ,
144
150
filter : filter,
145
- logfile : matches. opt_str ( "logfile" ) . map ( |s| Path :: new ( s) ) ,
151
+ logfile : matches. opt_str ( "logfile" ) . map ( |s| PathBuf :: new ( & s) ) ,
146
152
runtool : matches. opt_str ( "runtool" ) ,
147
153
host_rustcflags : matches. opt_str ( "host-rustcflags" ) ,
148
154
target_rustcflags : matches. opt_str ( "target-rustcflags" ) ,
@@ -276,9 +282,9 @@ pub fn make_tests(config: &Config) -> Vec<test::TestDescAndFn> {
276
282
debug ! ( "making tests from {:?}" ,
277
283
config. src_base. display( ) ) ;
278
284
let mut tests = Vec :: new ( ) ;
279
- let dirs = fs:: readdir ( & config. src_base ) . unwrap ( ) ;
280
- for file in & dirs {
281
- let file = file. clone ( ) ;
285
+ let dirs = fs:: read_dir ( & config. src_base ) . unwrap ( ) ;
286
+ for file in dirs {
287
+ let file = file. unwrap ( ) . path ( ) ;
282
288
debug ! ( "inspecting file {:?}" , file. display( ) ) ;
283
289
if is_test ( config, & file) {
284
290
let t = make_test ( config, & file, || {
@@ -301,7 +307,7 @@ pub fn is_test(config: &Config, testfile: &Path) -> bool {
301
307
_ => vec ! ( ".rc" . to_string( ) , ".rs" . to_string( ) )
302
308
} ;
303
309
let invalid_prefixes = vec ! ( "." . to_string( ) , "#" . to_string( ) , "~" . to_string( ) ) ;
304
- let name = testfile. filename_str ( ) . unwrap ( ) ;
310
+ let name = testfile. file_name ( ) . unwrap ( ) . to_str ( ) . unwrap ( ) ;
305
311
306
312
let mut valid = false ;
307
313
@@ -337,9 +343,9 @@ pub fn make_test_name(config: &Config, testfile: &Path) -> test::TestName {
337
343
338
344
// Try to elide redundant long paths
339
345
fn shorten ( path : & Path ) -> String {
340
- let filename = path. filename_str ( ) ;
341
- let p = path. dir_path ( ) ;
342
- let dir = p. filename_str ( ) ;
346
+ let filename = path. file_name ( ) . unwrap ( ) . to_str ( ) ;
347
+ let p = path. parent ( ) . unwrap ( ) ;
348
+ let dir = p. file_name ( ) . unwrap ( ) . to_str ( ) ;
343
349
format ! ( "{}/{}" , dir. unwrap_or( "" ) , filename. unwrap_or( "" ) )
344
350
}
345
351
@@ -348,19 +354,17 @@ pub fn make_test_name(config: &Config, testfile: &Path) -> test::TestName {
348
354
349
355
pub fn make_test_closure ( config : & Config , testfile : & Path ) -> test:: TestFn {
350
356
let config = ( * config) . clone ( ) ;
351
- // FIXME (#9639): This needs to handle non-utf8 paths
352
- let testfile = testfile. as_str ( ) . unwrap ( ) . to_string ( ) ;
357
+ let testfile = testfile. to_path_buf ( ) ;
353
358
test:: DynTestFn ( Thunk :: new ( move || {
354
- runtest:: run ( config, testfile)
359
+ runtest:: run ( config, & testfile)
355
360
} ) )
356
361
}
357
362
358
363
pub fn make_metrics_test_closure ( config : & Config , testfile : & Path ) -> test:: TestFn {
359
364
let config = ( * config) . clone ( ) ;
360
- // FIXME (#9639): This needs to handle non-utf8 paths
361
- let testfile = testfile. as_str ( ) . unwrap ( ) . to_string ( ) ;
365
+ let testfile = testfile. to_path_buf ( ) ;
362
366
test:: DynMetricFn ( box move |mm : & mut test:: MetricMap | {
363
- runtest:: run_metrics ( config, testfile, mm)
367
+ runtest:: run_metrics ( config, & testfile, mm)
364
368
} )
365
369
}
366
370
0 commit comments