@@ -44,6 +44,8 @@ use debugger::{check_debugger_output, DebuggerCommands};
4444#[ cfg( test) ]
4545mod tests;
4646
47+ const FAKE_SRC_BASE : & str = "fake-test-src-base" ;
48+
4749#[ cfg( windows) ]
4850fn disable_error_reporting < F : FnOnce ( ) -> R , R > ( f : F ) -> R {
4951 use std:: sync:: Mutex ;
@@ -1328,12 +1330,19 @@ impl<'test> TestCx<'test> {
13281330 return ;
13291331 }
13301332
1333+ // On Windows, translate all '\' path separators to '/'
1334+ let file_name = format ! ( "{}" , self . testpaths. file. display( ) ) . replace ( r"\" , "/" ) ;
1335+
13311336 // On Windows, keep all '\' path separators to match the paths reported in the JSON output
13321337 // from the compiler
1333- let os_file_name = self . testpaths . file . display ( ) . to_string ( ) ;
1334-
1335- // on windows, translate all '\' path separators to '/'
1336- let file_name = format ! ( "{}" , self . testpaths. file. display( ) ) . replace ( r"\" , "/" ) ;
1338+ let diagnostic_file_name = if self . props . remap_src_base {
1339+ let mut p = PathBuf :: from ( FAKE_SRC_BASE ) ;
1340+ p. push ( & self . testpaths . relative_dir ) ;
1341+ p. push ( self . testpaths . file . file_name ( ) . unwrap ( ) ) ;
1342+ p. display ( ) . to_string ( )
1343+ } else {
1344+ self . testpaths . file . display ( ) . to_string ( )
1345+ } ;
13371346
13381347 // If the testcase being checked contains at least one expected "help"
13391348 // message, then we'll ensure that all "help" messages are expected.
@@ -1343,7 +1352,7 @@ impl<'test> TestCx<'test> {
13431352 let expect_note = expected_errors. iter ( ) . any ( |ee| ee. kind == Some ( ErrorKind :: Note ) ) ;
13441353
13451354 // Parse the JSON output from the compiler and extract out the messages.
1346- let actual_errors = json:: parse_output ( & os_file_name , & proc_res. stderr , proc_res) ;
1355+ let actual_errors = json:: parse_output ( & diagnostic_file_name , & proc_res. stderr , proc_res) ;
13471356 let mut unexpected = Vec :: new ( ) ;
13481357 let mut found = vec ! [ false ; expected_errors. len( ) ] ;
13491358 for actual_error in & actual_errors {
@@ -1970,6 +1979,14 @@ impl<'test> TestCx<'test> {
19701979 }
19711980 }
19721981
1982+ if self . props . remap_src_base {
1983+ rustc. arg ( format ! (
1984+ "--remap-path-prefix={}={}" ,
1985+ self . config. src_base. display( ) ,
1986+ FAKE_SRC_BASE ,
1987+ ) ) ;
1988+ }
1989+
19731990 match emit {
19741991 Emit :: None => { }
19751992 Emit :: Metadata if is_rustdoc => { }
@@ -3545,6 +3562,14 @@ impl<'test> TestCx<'test> {
35453562 let parent_dir = self . testpaths . file . parent ( ) . unwrap ( ) ;
35463563 normalize_path ( parent_dir, "$DIR" ) ;
35473564
3565+ if self . props . remap_src_base {
3566+ let mut remapped_parent_dir = PathBuf :: from ( FAKE_SRC_BASE ) ;
3567+ if self . testpaths . relative_dir != Path :: new ( "" ) {
3568+ remapped_parent_dir. push ( & self . testpaths . relative_dir ) ;
3569+ }
3570+ normalize_path ( & remapped_parent_dir, "$DIR" ) ;
3571+ }
3572+
35483573 let source_bases = & [
35493574 // Source base on the current filesystem (calculated as parent of `tests/$suite`):
35503575 Some ( self . config . src_base . parent ( ) . unwrap ( ) . parent ( ) . unwrap ( ) . into ( ) ) ,
0 commit comments