@@ -110,6 +110,12 @@ mod test_utils;
110
110
// whether to run internal tests or not
111
111
const RUN_INTERNAL_TESTS : bool = cfg ! ( feature = "internal" ) ;
112
112
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
+
113
119
fn base_config ( test_dir : & str ) -> ( compiletest:: Config , Args ) {
114
120
let args = Args :: test ( ) ;
115
121
let mut config = compiletest:: Config {
@@ -124,10 +130,11 @@ fn base_config(test_dir: &str) -> (compiletest::Config, Args) {
124
130
OutputConflictHandling :: Error ( "cargo uibless" . into ( ) )
125
131
} ,
126
132
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" ) ,
131
138
..compiletest:: Config :: rustc ( Path :: new ( "tests" ) . join ( test_dir) )
132
139
} ;
133
140
let current_exe_path = env:: current_exe ( ) . unwrap ( ) ;
@@ -177,7 +184,7 @@ fn run_ui() {
177
184
let ( config, args) = base_config ( "ui" ) ;
178
185
//config.rustfix_coverage = true;
179
186
// 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" ) ) ;
181
188
let _threads = VarGuard :: set (
182
189
"RUST_TEST_THREADS" ,
183
190
// if RUST_TEST_THREADS is set, adhere to it, otherwise override it
@@ -237,8 +244,7 @@ fn run_ui_toml() {
237
244
238
245
config. stderr_filter (
239
246
& regex:: escape (
240
- & fs:: canonicalize ( "tests" )
241
- . unwrap ( )
247
+ & canonicalize ( "tests" )
242
248
. parent ( )
243
249
. unwrap ( )
244
250
. display ( )
@@ -297,8 +303,7 @@ fn run_ui_cargo() {
297
303
298
304
config. stderr_filter (
299
305
& regex:: escape (
300
- & fs:: canonicalize ( "tests" )
301
- . unwrap ( )
306
+ & canonicalize ( "tests" )
302
307
. parent ( )
303
308
. unwrap ( )
304
309
. display ( )
@@ -317,7 +322,13 @@ fn run_ui_cargo() {
317
322
|path, _args| test_filter ( path) && path. ends_with ( "Cargo.toml" ) ,
318
323
|config, path| {
319
324
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
+ ) ;
321
332
Some ( config)
322
333
} ,
323
334
if quiet {
0 commit comments