@@ -3154,42 +3154,40 @@ impl<'test> TestCx<'test> {
31543154 }
31553155
31563156 fn normalize_output ( & self , output : & str , custom_rules : & [ ( String , String ) ] ) -> String {
3157- let parent_dir = self . testpaths . file . parent ( ) . unwrap ( ) ;
31583157 let cflags = self . props . compile_flags . join ( " " ) ;
31593158 let json = cflags. contains ( "--error-format json" )
31603159 || cflags. contains ( "--error-format pretty-json" )
31613160 || cflags. contains ( "--error-format=json" )
31623161 || cflags. contains ( "--error-format=pretty-json" ) ;
3163- let parent_dir_str = if json {
3164- parent_dir. display ( ) . to_string ( ) . replace ( "\\ " , "\\ \\ " )
3165- } else {
3166- parent_dir. display ( ) . to_string ( )
3162+
3163+ let mut normalized = output. to_string ( ) ;
3164+
3165+ let mut normalize_path = |from : & Path , to : & str | {
3166+ let mut from = from. display ( ) . to_string ( ) ;
3167+ if json {
3168+ from = from. replace ( "\\ " , "\\ \\ " ) ;
3169+ }
3170+ normalized = normalized. replace ( & from, to) ;
31673171 } ;
31683172
3169- let mut normalized = output. replace ( & parent_dir_str, "$DIR" ) ;
3173+ let parent_dir = self . testpaths . file . parent ( ) . unwrap ( ) ;
3174+ normalize_path ( parent_dir, "$DIR" ) ;
31703175
31713176 // Paths into the libstd/libcore
31723177 let src_dir = self . config . src_base . parent ( ) . unwrap ( ) . parent ( ) . unwrap ( ) ;
3173- let src_dir_str = if json {
3174- src_dir. display ( ) . to_string ( ) . replace ( "\\ " , "\\ \\ " )
3175- } else {
3176- src_dir. display ( ) . to_string ( )
3177- } ;
3178- normalized = normalized. replace ( & src_dir_str, "$SRC_DIR" ) ;
3178+ normalize_path ( src_dir, "$SRC_DIR" ) ;
31793179
31803180 // Paths into the build directory
31813181 let test_build_dir = & self . config . build_base ;
31823182 let parent_build_dir = test_build_dir. parent ( ) . unwrap ( ) . parent ( ) . unwrap ( ) . parent ( ) . unwrap ( ) ;
31833183
31843184 // eg. /home/user/rust/build/x86_64-unknown-linux-gnu/test/ui
3185- normalized = normalized . replace ( test_build_dir. to_str ( ) . unwrap ( ) , "$TEST_BUILD_DIR" ) ;
3185+ normalize_path ( test_build_dir, "$TEST_BUILD_DIR" ) ;
31863186 // eg. /home/user/rust/build
3187- normalized = normalized . replace ( & parent_build_dir. to_str ( ) . unwrap ( ) , "$BUILD_DIR" ) ;
3187+ normalize_path ( parent_build_dir, "$BUILD_DIR" ) ;
31883188
31893189 // Paths into lib directory.
3190- let mut lib_dir = parent_build_dir. parent ( ) . unwrap ( ) . to_path_buf ( ) ;
3191- lib_dir. push ( "lib" ) ;
3192- normalized = normalized. replace ( & lib_dir. to_str ( ) . unwrap ( ) , "$LIB_DIR" ) ;
3190+ normalize_path ( & parent_build_dir. parent ( ) . unwrap ( ) . join ( "lib" ) , "$LIB_DIR" ) ;
31933191
31943192 if json {
31953193 // escaped newlines in json strings should be readable
0 commit comments