use std::path::PathBuf;
pub(crate) struct TestFileGuard {
pub(crate) path: PathBuf,
}
impl Drop for TestFileGuard {
fn drop(&mut self) {
let _ = std::fs::remove_file(&self.path);
}
}
pub(crate) struct TestDirGuard {
pub(crate) path: PathBuf,
}
impl Drop for TestDirGuard {
fn drop(&mut self) {
let _ = std::fs::remove_dir_all(&self.path);
}
}
pub(crate) fn temp_config_path(tag: &str) -> (PathBuf, TestDirGuard) {
let dir = std::env::temp_dir().join(format!("gitwig_test_cfg_{}_{}", tag, std::process::id()));
let _ = std::fs::remove_dir_all(&dir);
std::fs::create_dir_all(&dir).expect("scratch config dir should be creatable");
(dir.join("config.toml"), TestDirGuard { path: dir })
}