diff --git a/cli/tests/common/test_environment.rs b/cli/tests/common/test_environment.rs index b08aee8cf4..6a7bbffb02 100644 --- a/cli/tests/common/test_environment.rs +++ b/cli/tests/common/test_environment.rs @@ -15,6 +15,7 @@ use std::cell::RefCell; use std::collections::HashMap; use std::ffi::OsStr; +use std::ffi::OsString; use std::path::Path; use std::path::PathBuf; @@ -36,7 +37,7 @@ pub struct TestEnvironment { env_root: PathBuf, home_dir: PathBuf, config_path: PathBuf, - env_vars: HashMap, + env_vars: HashMap, config_file_number: RefCell, command_number: RefCell, } @@ -120,11 +121,11 @@ impl TestEnvironment { // We want to keep the "PATH" environment variable to allow accessing // executables like `git` from the PATH. cmd.env("PATH", std::env::var_os("PATH").unwrap_or_default()); - cmd.env("HOME", self.home_dir.to_str().unwrap()); + cmd.env("HOME", &self.home_dir); // Prevent git.subprocess from reading outside git config cmd.env("GIT_CONFIG_SYSTEM", "/dev/null"); cmd.env("GIT_CONFIG_GLOBAL", "/dev/null"); - cmd.env("JJ_CONFIG", self.config_path.to_str().unwrap()); + cmd.env("JJ_CONFIG", &self.config_path); cmd.env("JJ_USER", "Test User"); cmd.env("JJ_EMAIL", "test.user@example.com"); cmd.env("JJ_OP_HOSTNAME", "host.example.com"); @@ -202,7 +203,7 @@ impl TestEnvironment { .unwrap(); } - pub fn add_env_var(&mut self, key: impl Into, val: impl Into) { + pub fn add_env_var(&mut self, key: impl Into, val: impl Into) { self.env_vars.insert(key.into(), val.into()); } @@ -211,7 +212,7 @@ impl TestEnvironment { pub fn set_up_fake_bisector(&mut self) -> PathBuf { let bisection_script = self.env_root().join("bisection_script"); std::fs::write(&bisection_script, "").unwrap(); - self.add_env_var("BISECTION_SCRIPT", bisection_script.to_str().unwrap()); + self.add_env_var("BISECTION_SCRIPT", &bisection_script); bisection_script } @@ -230,7 +231,7 @@ impl TestEnvironment { "#}); let edit_script = self.env_root().join("edit_script"); std::fs::write(&edit_script, "").unwrap(); - self.add_env_var("EDIT_SCRIPT", edit_script.to_str().unwrap()); + self.add_env_var("EDIT_SCRIPT", &edit_script); edit_script } @@ -244,7 +245,7 @@ impl TestEnvironment { "#}); let edit_script = self.env_root().join("diff_edit_script"); std::fs::write(&edit_script, "").unwrap(); - self.add_env_var("DIFF_EDIT_SCRIPT", edit_script.to_str().unwrap()); + self.add_env_var("DIFF_EDIT_SCRIPT", &edit_script); edit_script } diff --git a/cli/tests/test_git_clone.rs b/cli/tests/test_git_clone.rs index fce9729134..c85befced2 100644 --- a/cli/tests/test_git_clone.rs +++ b/cli/tests/test_git_clone.rs @@ -1107,10 +1107,7 @@ fn test_git_clone_with_global_git_remote_config() { prune = true "#}, ); - test_env.add_env_var( - "GIT_CONFIG_GLOBAL", - test_env.env_root().join("git-config").to_str().unwrap(), - ); + test_env.add_env_var("GIT_CONFIG_GLOBAL", test_env.env_root().join("git-config")); let root_dir = test_env.work_dir(""); let git_repo_path = root_dir.root().join("source"); diff --git a/cli/tests/test_git_remotes.rs b/cli/tests/test_git_remotes.rs index e713af69d8..f43d84e8db 100644 --- a/cli/tests/test_git_remotes.rs +++ b/cli/tests/test_git_remotes.rs @@ -544,10 +544,7 @@ fn test_git_remote_with_global_git_remote_config() { fetch = +refs/heads/*:refs/remotes/foo/* "#}, ); - test_env.add_env_var( - "GIT_CONFIG_GLOBAL", - test_env.env_root().join("git-config").to_str().unwrap(), - ); + test_env.add_env_var("GIT_CONFIG_GLOBAL", test_env.env_root().join("git-config")); test_env.run_jj_in(".", ["git", "init", "repo"]).success(); let work_dir = test_env.work_dir("repo");