Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions cli/tests/common/test_environment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -36,7 +37,7 @@ pub struct TestEnvironment {
env_root: PathBuf,
home_dir: PathBuf,
config_path: PathBuf,
env_vars: HashMap<String, String>,
env_vars: HashMap<OsString, OsString>,
config_file_number: RefCell<i64>,
command_number: RefCell<i64>,
}
Expand Down Expand Up @@ -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", "[email protected]");
cmd.env("JJ_OP_HOSTNAME", "host.example.com");
Expand Down Expand Up @@ -202,7 +203,7 @@ impl TestEnvironment {
.unwrap();
}

pub fn add_env_var(&mut self, key: impl Into<String>, val: impl Into<String>) {
pub fn add_env_var(&mut self, key: impl Into<OsString>, val: impl Into<OsString>) {
self.env_vars.insert(key.into(), val.into());
}

Expand All @@ -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
}

Expand All @@ -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
}

Expand All @@ -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
}

Expand Down
5 changes: 1 addition & 4 deletions cli/tests/test_git_clone.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
5 changes: 1 addition & 4 deletions cli/tests/test_git_remotes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down