@@ -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 ( ) ;
@@ -178,7 +185,7 @@ fn run_ui() {
178
185
let ( config, args) = base_config ( "ui" ) ;
179
186
//config.rustfix_coverage = true;
180
187
// use tests/clippy.toml
181
- let _g = VarGuard :: set ( "CARGO_MANIFEST_DIR" , fs :: canonicalize ( "tests" ) . unwrap ( ) ) ;
188
+ let _g = VarGuard :: set ( "CARGO_MANIFEST_DIR" , canonicalize ( "tests" ) ) ;
182
189
let _threads = VarGuard :: set (
183
190
"RUST_TEST_THREADS" ,
184
191
// if RUST_TEST_THREADS is set, adhere to it, otherwise override it
@@ -238,8 +245,7 @@ fn run_ui_toml() {
238
245
239
246
config. stderr_filter (
240
247
& regex:: escape (
241
- & fs:: canonicalize ( "tests" )
242
- . unwrap ( )
248
+ & canonicalize ( "tests" )
243
249
. parent ( )
244
250
. unwrap ( )
245
251
. display ( )
@@ -298,8 +304,7 @@ fn run_ui_cargo() {
298
304
299
305
config. stderr_filter (
300
306
& regex:: escape (
301
- & fs:: canonicalize ( "tests" )
302
- . unwrap ( )
307
+ & canonicalize ( "tests" )
303
308
. parent ( )
304
309
. unwrap ( )
305
310
. display ( )
@@ -318,7 +323,13 @@ fn run_ui_cargo() {
318
323
|path, _args| test_filter ( path) && path. ends_with ( "Cargo.toml" ) ,
319
324
|config, path| {
320
325
let mut config = config. clone ( ) ;
321
- config. out_dir = PathBuf :: from ( "target/ui_test_cargo/" ) . join ( path. parent ( ) . unwrap ( ) ) ;
326
+ config. out_dir = canonicalize (
327
+ std:: env:: current_dir ( )
328
+ . unwrap ( )
329
+ . join ( "target" )
330
+ . join ( "ui_test_cargo/" )
331
+ . join ( path. parent ( ) . unwrap ( ) ) ,
332
+ ) ;
322
333
Some ( config)
323
334
} ,
324
335
if quiet {
0 commit comments