@@ -13,7 +13,7 @@ use std::collections::BTreeMap;
1313use std:: env:: { self , remove_var, set_var, var_os} ;
1414use std:: ffi:: { OsStr , OsString } ;
1515use std:: fs;
16- use std:: path:: Path ;
16+ use std:: path:: { Path , PathBuf } ;
1717use std:: sync:: LazyLock ;
1818use test_utils:: IS_RUSTC_TEST_SUITE ;
1919
@@ -110,6 +110,11 @@ 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:: canonicalize ( path) . unwrap_or_else ( |err| panic ! ( "{} cannot be canonicalized: {err}" , path. display( ) ) )
116+ }
117+
113118fn base_config ( test_dir : & str ) -> ( compiletest:: Config , Args ) {
114119 let args = Args :: test ( ) ;
115120 let mut config = compiletest:: Config {
@@ -124,9 +129,7 @@ fn base_config(test_dir: &str) -> (compiletest::Config, Args) {
124129 OutputConflictHandling :: Error ( "cargo uibless" . into ( ) )
125130 } ,
126131 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" ) ,
130133 ..compiletest:: Config :: rustc ( Path :: new ( "tests" ) . join ( test_dir) )
131134 } ;
132135
@@ -182,7 +185,7 @@ fn run_ui() {
182185 let ( config, args) = base_config ( "ui" ) ;
183186 //config.rustfix_coverage = true;
184187 // 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" ) ) ;
186189 let _threads = VarGuard :: set (
187190 "RUST_TEST_THREADS" ,
188191 // if RUST_TEST_THREADS is set, adhere to it, otherwise override it
@@ -242,8 +245,7 @@ fn run_ui_toml() {
242245
243246 config. stderr_filter (
244247 & regex:: escape (
245- & fs:: canonicalize ( "tests" )
246- . unwrap ( )
248+ & canonicalize ( "tests" )
247249 . parent ( )
248250 . unwrap ( )
249251 . display ( )
@@ -302,8 +304,7 @@ fn run_ui_cargo() {
302304
303305 config. stderr_filter (
304306 & regex:: escape (
305- & fs:: canonicalize ( "tests" )
306- . unwrap ( )
307+ & canonicalize ( "tests" )
307308 . parent ( )
308309 . unwrap ( )
309310 . display ( )
@@ -322,9 +323,7 @@ fn run_ui_cargo() {
322323 |path, _args| test_filter ( path) && path. ends_with ( "Cargo.toml" ) ,
323324 |config, path| {
324325 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 ( ) ) ;
328327 Some ( config)
329328 } ,
330329 if quiet {
0 commit comments