11use crate :: common:: os:: PATH_SEPARATOR ;
22use assert_cmd:: Command ;
3+ use camino:: { Utf8Path , Utf8PathBuf } ;
4+ use camino_tempfile:: Utf8TempDir ;
35use std:: env;
46use std:: ffi:: OsString ;
57use std:: fs;
68use std:: fs:: create_dir_all;
7- use std:: path:: { Path , PathBuf } ;
8- use tempfile:: TempDir ;
99
1010pub struct TestEnv {
11- home_dir : TempDir ,
12- bin_dir : PathBuf ,
13- asset_dir : PathBuf ,
14- dfx_path : Option < PathBuf > ,
11+ home_dir : Utf8TempDir ,
12+ bin_dir : Utf8PathBuf ,
13+ asset_dir : Utf8PathBuf ,
14+ dfx_path : Option < Utf8PathBuf > ,
1515 os_path : OsString ,
1616}
1717
1818impl TestEnv {
1919 pub fn new ( ) -> Self {
20- let home_dir = tempfile :: tempdir ( ) . expect ( "failed to create temp home dir" ) ;
20+ let home_dir = camino_tempfile :: tempdir ( ) . expect ( "failed to create temp home dir" ) ;
2121 let bin_dir = home_dir. path ( ) . join ( "bin" ) ;
2222 let asset_dir = home_dir. path ( ) . join ( "share" ) ;
2323 fs:: create_dir ( & bin_dir) . expect ( "failed to create bin dir" ) ;
2424 fs:: create_dir ( & asset_dir) . expect ( "failed to create asset dir" ) ;
2525 let os_path = Self :: build_os_path ( & bin_dir) ;
26- eprintln ! (
27- "Test environment home directory: {}" ,
28- home_dir. path( ) . display( )
29- ) ;
26+ eprintln ! ( "Test environment home directory: {}" , home_dir. path( ) ) ;
3027
3128 Self {
3229 home_dir,
@@ -39,13 +36,12 @@ impl TestEnv {
3936
4037 /// Sets up `dfx` in the test environment by copying the binary from $ICPTEST_DFX_PATH
4138 pub fn with_dfx ( mut self ) -> Self {
42- let dfx_path = std:: env:: var_os ( "ICPTEST_DFX_PATH" )
39+ let dfx_path = std:: env:: var ( "ICPTEST_DFX_PATH" )
4340 . expect ( "ICPTEST_DFX_PATH must be set to use with_dfx()" ) ;
44- let src = PathBuf :: from ( dfx_path) ;
41+ let src = Utf8PathBuf :: from ( dfx_path) ;
4542 assert ! (
4643 src. exists( ) ,
47- "ICPTEST_DFX_PATH points to non-existent file: {}" ,
48- src. display( )
44+ "ICPTEST_DFX_PATH points to non-existent file: {src}" ,
4945 ) ;
5046
5147 let dest = self . bin_dir . join ( "dfx" ) ;
@@ -55,7 +51,7 @@ impl TestEnv {
5551 {
5652 use std:: os:: unix:: fs:: PermissionsExt ;
5753 let mut perms = fs:: metadata ( & dest)
58- . unwrap_or_else ( |e| panic ! ( "Failed to read metadata for {}: {}" , dest . display ( ) , e ) )
54+ . unwrap_or_else ( |e| panic ! ( "Failed to read metadata for {dest }: {e}" ) )
5955 . permissions ( ) ;
6056 perms. set_mode ( 0o500 ) ;
6157 fs:: set_permissions ( & dest, perms) . unwrap ( ) ;
@@ -65,7 +61,7 @@ impl TestEnv {
6561 self
6662 }
6763
68- pub fn home_path ( & self ) -> & Path {
64+ pub fn home_path ( & self ) -> & Utf8Path {
6965 self . home_dir . path ( )
7066 }
7167
@@ -93,11 +89,11 @@ impl TestEnv {
9389 cmd. env_remove ( "ICP_HOME" ) ;
9490 }
9591
96- fn build_os_path ( bin_dir : & Path ) -> OsString {
92+ fn build_os_path ( bin_dir : & Utf8Path ) -> OsString {
9793 let old_path = env:: var_os ( "PATH" ) . unwrap_or_default ( ) ;
98- let mut new_path = bin_dir. as_os_str ( ) . to_os_string ( ) ;
94+ let mut new_path = bin_dir. as_os_str ( ) . to_owned ( ) ;
9995 new_path. push ( PATH_SEPARATOR ) ;
100- new_path. push ( old_path) ;
96+ new_path. push ( & old_path) ;
10197 new_path
10298 }
10399
@@ -111,11 +107,11 @@ impl TestEnv {
111107 fs:: write ( & networks_json_path, networks) . unwrap ( ) ;
112108 }
113109
114- pub fn pkg_dir ( & self ) -> PathBuf {
110+ pub fn pkg_dir ( & self ) -> Utf8PathBuf {
115111 env ! ( "CARGO_MANIFEST_DIR" ) . into ( )
116112 }
117113
118- pub fn make_asset ( & self , name : & str ) -> PathBuf {
114+ pub fn make_asset ( & self , name : & str ) -> Utf8PathBuf {
119115 let target = self . asset_dir . join ( name) ;
120116 fs:: copy ( self . pkg_dir ( ) . join ( format ! ( "tests/assets/{name}" ) ) , & target)
121117 . expect ( "failed to copy asset" ) ;
0 commit comments