@@ -3154,42 +3154,40 @@ impl<'test> TestCx<'test> {
3154
3154
}
3155
3155
3156
3156
fn normalize_output ( & self , output : & str , custom_rules : & [ ( String , String ) ] ) -> String {
3157
- let parent_dir = self . testpaths . file . parent ( ) . unwrap ( ) ;
3158
3157
let cflags = self . props . compile_flags . join ( " " ) ;
3159
3158
let json = cflags. contains ( "--error-format json" )
3160
3159
|| cflags. contains ( "--error-format pretty-json" )
3161
3160
|| cflags. contains ( "--error-format=json" )
3162
3161
|| 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) ;
3167
3171
} ;
3168
3172
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" ) ;
3170
3175
3171
3176
// Paths into the libstd/libcore
3172
3177
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" ) ;
3179
3179
3180
3180
// Paths into the build directory
3181
3181
let test_build_dir = & self . config . build_base ;
3182
3182
let parent_build_dir = test_build_dir. parent ( ) . unwrap ( ) . parent ( ) . unwrap ( ) . parent ( ) . unwrap ( ) ;
3183
3183
3184
3184
// 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" ) ;
3186
3186
// 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" ) ;
3188
3188
3189
3189
// 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" ) ;
3193
3191
3194
3192
if json {
3195
3193
// escaped newlines in json strings should be readable
0 commit comments