@@ -13,7 +13,7 @@ use std::collections::BTreeMap;
13
13
use std:: env:: { self , remove_var, set_var, var_os} ;
14
14
use std:: ffi:: { OsStr , OsString } ;
15
15
use std:: fs;
16
- use std:: path:: Path ;
16
+ use std:: path:: { Path , PathBuf } ;
17
17
use std:: sync:: LazyLock ;
18
18
use test_utils:: IS_RUSTC_TEST_SUITE ;
19
19
@@ -110,6 +110,11 @@ 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:: canonicalize ( path) . unwrap_or_else ( |err| panic ! ( "{} cannot be canonicalized: {err}" , path. display( ) ) )
116
+ }
117
+
113
118
fn base_config ( test_dir : & str ) -> ( compiletest:: Config , Args ) {
114
119
let args = Args :: test ( ) ;
115
120
let mut config = compiletest:: Config {
@@ -124,9 +129,7 @@ fn base_config(test_dir: &str) -> (compiletest::Config, Args) {
124
129
OutputConflictHandling :: Error ( "cargo uibless" . into ( ) )
125
130
} ,
126
131
target : None ,
127
- out_dir : fs:: canonicalize ( std:: env:: var_os ( "CARGO_TARGET_DIR" ) . unwrap_or ( "target" . into ( ) ) )
128
- . unwrap ( )
129
- . join ( "ui_test" ) ,
132
+ out_dir : canonicalize ( std:: env:: var_os ( "CARGO_TARGET_DIR" ) . unwrap_or ( "target" . into ( ) ) ) . join ( "ui_test" ) ,
130
133
..compiletest:: Config :: rustc ( Path :: new ( "tests" ) . join ( test_dir) )
131
134
} ;
132
135
@@ -182,7 +185,7 @@ fn run_ui() {
182
185
let ( config, args) = base_config ( "ui" ) ;
183
186
//config.rustfix_coverage = true;
184
187
// use tests/clippy.toml
185
- let _g = VarGuard :: set ( "CARGO_MANIFEST_DIR" , fs :: canonicalize ( "tests" ) . unwrap ( ) ) ;
188
+ let _g = VarGuard :: set ( "CARGO_MANIFEST_DIR" , canonicalize ( "tests" ) ) ;
186
189
let _threads = VarGuard :: set (
187
190
"RUST_TEST_THREADS" ,
188
191
// if RUST_TEST_THREADS is set, adhere to it, otherwise override it
@@ -242,8 +245,7 @@ fn run_ui_toml() {
242
245
243
246
config. stderr_filter (
244
247
& regex:: escape (
245
- & fs:: canonicalize ( "tests" )
246
- . unwrap ( )
248
+ & canonicalize ( "tests" )
247
249
. parent ( )
248
250
. unwrap ( )
249
251
. display ( )
@@ -302,8 +304,7 @@ fn run_ui_cargo() {
302
304
303
305
config. stderr_filter (
304
306
& regex:: escape (
305
- & fs:: canonicalize ( "tests" )
306
- . unwrap ( )
307
+ & canonicalize ( "tests" )
307
308
. parent ( )
308
309
. unwrap ( )
309
310
. display ( )
@@ -322,9 +323,7 @@ fn run_ui_cargo() {
322
323
|path, _args| test_filter ( path) && path. ends_with ( "Cargo.toml" ) ,
323
324
|config, path| {
324
325
let mut config = config. clone ( ) ;
325
- config. out_dir = fs:: canonicalize ( "target/ui_test_cargo/" )
326
- . unwrap ( )
327
- . join ( path. parent ( ) . unwrap ( ) ) ;
326
+ config. out_dir = canonicalize ( "target/ui_test_cargo/" ) . join ( path. parent ( ) . unwrap ( ) ) ;
328
327
Some ( config)
329
328
} ,
330
329
if quiet {
0 commit comments