//! What the crate's tests share. use std::path::PathBuf; /// A directory of a test's files, removed with it. pub(crate) struct Scratch(pub(crate) PathBuf); impl Scratch { pub(crate) fn new(name: &str) -> Scratch { let dir = std::env::temp_dir().join(format!("config-{name}-{}", std::process::id())); let _ = std::fs::remove_dir_all(&dir); std::fs::create_dir_all(&dir).unwrap(); Scratch(dir) } /// A file holding `content`: its name. pub(crate) fn file(&self, name: &str, content: &str) -> String { std::fs::write(self.0.join(name), content).unwrap(); name.to_owned() } } impl Drop for Scratch { fn drop(&mut self) { let _ = std::fs::remove_dir_all(&self.0); } }