2121#![ feature( test) ]
2222#![ feature( unicode) ]
2323#![ feature( core) ]
24+ #![ feature( path) ]
25+ #![ feature( os) ]
26+ #![ feature( io) ]
27+ #![ feature( fs) ]
28+ #![ feature( net) ]
2429
2530#![ deny( warnings) ]
2631
@@ -31,8 +36,9 @@ extern crate getopts;
3136extern crate log;
3237
3338use std:: env;
39+ use std:: fs;
3440use std:: old_io;
35- use std:: old_io :: fs ;
41+ use std:: path :: { Path , PathBuf } ;
3642use std:: thunk:: Thunk ;
3743use getopts:: { optopt, optflag, reqopt} ;
3844use common:: Config ;
@@ -114,9 +120,9 @@ pub fn parse_config(args: Vec<String> ) -> Config {
114120 panic ! ( )
115121 }
116122
117- fn opt_path ( m : & getopts:: Matches , nm : & str ) -> Path {
123+ fn opt_path ( m : & getopts:: Matches , nm : & str ) -> PathBuf {
118124 match m. opt_str ( nm) {
119- Some ( s) => Path :: new ( s) ,
125+ Some ( s) => PathBuf :: new ( & s) ,
120126 None => panic ! ( "no option (=path) found for {}" , nm) ,
121127 }
122128 }
@@ -131,18 +137,18 @@ pub fn parse_config(args: Vec<String> ) -> Config {
131137 compile_lib_path : matches. opt_str ( "compile-lib-path" ) . unwrap ( ) ,
132138 run_lib_path : matches. opt_str ( "run-lib-path" ) . unwrap ( ) ,
133139 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) ) ,
135141 valgrind_path : matches. opt_str ( "valgrind-path" ) ,
136142 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) ) ,
138144 src_base : opt_path ( matches, "src-base" ) ,
139145 build_base : opt_path ( matches, "build-base" ) ,
140146 aux_base : opt_path ( matches, "aux-base" ) ,
141147 stage_id : matches. opt_str ( "stage-id" ) . unwrap ( ) ,
142148 mode : matches. opt_str ( "mode" ) . unwrap ( ) . parse ( ) . ok ( ) . expect ( "invalid mode" ) ,
143149 run_ignored : matches. opt_present ( "ignored" ) ,
144150 filter : filter,
145- logfile : matches. opt_str ( "logfile" ) . map ( |s| Path :: new ( s) ) ,
151+ logfile : matches. opt_str ( "logfile" ) . map ( |s| PathBuf :: new ( & s) ) ,
146152 runtool : matches. opt_str ( "runtool" ) ,
147153 host_rustcflags : matches. opt_str ( "host-rustcflags" ) ,
148154 target_rustcflags : matches. opt_str ( "target-rustcflags" ) ,
@@ -276,9 +282,9 @@ pub fn make_tests(config: &Config) -> Vec<test::TestDescAndFn> {
276282 debug ! ( "making tests from {:?}" ,
277283 config. src_base. display( ) ) ;
278284 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 ( ) ;
282288 debug ! ( "inspecting file {:?}" , file. display( ) ) ;
283289 if is_test ( config, & file) {
284290 let t = make_test ( config, & file, || {
@@ -301,7 +307,7 @@ pub fn is_test(config: &Config, testfile: &Path) -> bool {
301307 _ => vec ! ( ".rc" . to_string( ) , ".rs" . to_string( ) )
302308 } ;
303309 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 ( ) ;
305311
306312 let mut valid = false ;
307313
@@ -337,9 +343,9 @@ pub fn make_test_name(config: &Config, testfile: &Path) -> test::TestName {
337343
338344 // Try to elide redundant long paths
339345 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 ( ) ;
343349 format ! ( "{}/{}" , dir. unwrap_or( "" ) , filename. unwrap_or( "" ) )
344350 }
345351
@@ -348,19 +354,17 @@ pub fn make_test_name(config: &Config, testfile: &Path) -> test::TestName {
348354
349355pub fn make_test_closure ( config : & Config , testfile : & Path ) -> test:: TestFn {
350356 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 ( ) ;
353358 test:: DynTestFn ( Thunk :: new ( move || {
354- runtest:: run ( config, testfile)
359+ runtest:: run ( config, & testfile)
355360 } ) )
356361}
357362
358363pub fn make_metrics_test_closure ( config : & Config , testfile : & Path ) -> test:: TestFn {
359364 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 ( ) ;
362366 test:: DynMetricFn ( box move |mm : & mut test:: MetricMap | {
363- runtest:: run_metrics ( config, testfile, mm)
367+ runtest:: run_metrics ( config, & testfile, mm)
364368 } )
365369}
366370
0 commit comments