@@ -110,6 +110,12 @@ mod test_utils;
110110// whether to run internal tests or not
111111const RUN_INTERNAL_TESTS : bool = cfg ! ( feature = "internal" ) ;
112112
113+ fn canonicalize ( path : impl AsRef < Path > ) -> PathBuf {
114+ let path = path. as_ref ( ) ;
115+ fs:: create_dir_all ( path) . unwrap ( ) ;
116+ fs:: canonicalize ( path) . unwrap_or_else ( |err| panic ! ( "{} cannot be canonicalized: {err}" , path. display( ) ) )
117+ }
118+
113119fn base_config ( test_dir : & str ) -> ( compiletest:: Config , Args ) {
114120 let args = Args :: test ( ) ;
115121 let mut config = compiletest:: Config {
@@ -124,10 +130,11 @@ fn base_config(test_dir: &str) -> (compiletest::Config, Args) {
124130 OutputConflictHandling :: Error ( "cargo uibless" . into ( ) )
125131 } ,
126132 target : None ,
127- out_dir : PathBuf :: from ( std:: env:: var_os ( "CARGO_TARGET_DIR" ) . unwrap_or ( "target" . into ( ) ) )
128- . join ( "ui_test" )
129- . canonicalize ( )
130- . unwrap ( ) ,
133+ out_dir : canonicalize (
134+ std:: env:: var_os ( "CARGO_TARGET_DIR" )
135+ . map_or_else ( || std:: env:: current_dir ( ) . unwrap ( ) . join ( "target" ) , PathBuf :: from) ,
136+ )
137+ . join ( "ui_test" ) ,
131138 ..compiletest:: Config :: rustc ( Path :: new ( "tests" ) . join ( test_dir) )
132139 } ;
133140 let current_exe_path = env:: current_exe ( ) . unwrap ( ) ;
@@ -177,7 +184,7 @@ fn run_ui() {
177184 let ( config, args) = base_config ( "ui" ) ;
178185 //config.rustfix_coverage = true;
179186 // use tests/clippy.toml
180- let _g = VarGuard :: set ( "CARGO_MANIFEST_DIR" , fs :: canonicalize ( "tests" ) . unwrap ( ) ) ;
187+ let _g = VarGuard :: set ( "CARGO_MANIFEST_DIR" , canonicalize ( "tests" ) ) ;
181188 let _threads = VarGuard :: set (
182189 "RUST_TEST_THREADS" ,
183190 // if RUST_TEST_THREADS is set, adhere to it, otherwise override it
@@ -237,8 +244,7 @@ fn run_ui_toml() {
237244
238245 config. stderr_filter (
239246 & regex:: escape (
240- & fs:: canonicalize ( "tests" )
241- . unwrap ( )
247+ & canonicalize ( "tests" )
242248 . parent ( )
243249 . unwrap ( )
244250 . display ( )
@@ -297,8 +303,7 @@ fn run_ui_cargo() {
297303
298304 config. stderr_filter (
299305 & regex:: escape (
300- & fs:: canonicalize ( "tests" )
301- . unwrap ( )
306+ & canonicalize ( "tests" )
302307 . parent ( )
303308 . unwrap ( )
304309 . display ( )
@@ -317,7 +322,13 @@ fn run_ui_cargo() {
317322 |path, _args| test_filter ( path) && path. ends_with ( "Cargo.toml" ) ,
318323 |config, path| {
319324 let mut config = config. clone ( ) ;
320- config. out_dir = PathBuf :: from ( "target/ui_test_cargo/" ) . join ( path. parent ( ) . unwrap ( ) ) ;
325+ config. out_dir = canonicalize (
326+ std:: env:: current_dir ( )
327+ . unwrap ( )
328+ . join ( "target" )
329+ . join ( "ui_test_cargo/" )
330+ . join ( path. parent ( ) . unwrap ( ) ) ,
331+ ) ;
321332 Some ( config)
322333 } ,
323334 if quiet {
0 commit comments