Skip to content

Commit

Permalink
Also set BRZ_HOME
Browse files Browse the repository at this point in the history
  • Loading branch information
jelmer committed Jul 29, 2024
1 parent 0f2171d commit 108122a
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ pub struct TestEnv {
pub old_cwd: PathBuf,
pub old_home: Option<String>,
pub old_email: Option<String>,
pub old_brz_home: Option<String>,
}

impl TestEnv {
Expand All @@ -22,19 +23,23 @@ impl TestEnv {
let old_cwd = std::env::current_dir().unwrap();
let old_home = std::env::var("HOME").ok();
let old_email = std::env::var("BRZ_EMAIL").ok();
let old_brz_home = std::env::var("BRZ_HOME").ok();
let brz_email = "Joe Tester <joe@example.com>";
let breezy_home = home_dir.join(".config/breezy");
std::env::set_current_dir(&working_dir).unwrap();
std::env::set_var("HOME", &home_dir);
let brz_email = "Joe Tester <joe@example.com>";
std::env::set_var("BRZ_EMAIL", brz_email);
std::env::set_var("BRZ_HOME", &breezy_home);
pyo3::Python::with_gil(|py| {
let os = py.import_bound("os").unwrap();
os.call_method1("chdir", (working_dir.to_str().unwrap(),))
.unwrap();
os.call_method1("putenv", ("HOME", home_dir.to_str().unwrap()))
.unwrap();
os.call_method1("putenv", ("BRZ_EMAIL", brz_email)).unwrap();
os.call_method1("putenv", ("BRZ_HOME", breezy_home.to_str().unwrap()))
.unwrap();
});
let breezy_home = home_dir.join(".config/breezy");
fs::create_dir_all(&breezy_home).unwrap();
fs::write(
breezy_home.join("breezy.conf"),
Expand All @@ -51,6 +56,7 @@ email = Joe Tester <joe@example.com>
old_cwd,
old_home,
old_email,
old_brz_home,
}
}
}
Expand All @@ -67,6 +73,11 @@ impl Drop for TestEnv {
} else {
std::env::remove_var("BRZ_EMAIL");
}
if let Some(dir) = self.old_brz_home.as_ref() {
std::env::set_var("BRZ_HOME", dir);
} else {
std::env::remove_var("BRZ_HOME");
}
let _ = std::env::set_current_dir(&self.old_cwd);
pyo3::Python::with_gil(|py| {
let os = py.import_bound("os").unwrap();
Expand All @@ -82,6 +93,11 @@ impl Drop for TestEnv {
} else {
os.call_method1("unsetenv", ("BRZ_EMAIL",)).unwrap();
}
if let Some(dir) = self.old_brz_home.as_ref() {
os.call_method1("putenv", ("BRZ_HOME", dir)).unwrap();
} else {
os.call_method1("unsetenv", ("BRZ_HOME",)).unwrap();
}
});
}
}
Expand Down

0 comments on commit 108122a

Please sign in to comment.