//! A temporary directory tree for rule tests. #![allow( clippy::unwrap_used, reason = "test helper: a failure should abort the test" )] use std::fs; use std::path::{Path, PathBuf}; pub struct TempTree(PathBuf); impl TempTree { pub fn new(name: &str) -> Self { let root = std::env::temp_dir().join(format!("fabrilis-limits-{}-{name}", std::process::id())); let _ = fs::remove_dir_all(&root); fs::create_dir_all(&root).unwrap(); Self(root) } pub fn path(&self) -> &Path { &self.0 } pub fn write(&self, relative: &str, content: &str) { let path = self.0.join(relative); fs::create_dir_all(path.parent().unwrap()).unwrap(); fs::write(path, content).unwrap(); } } impl Drop for TempTree { fn drop(&mut self) { let _ = fs::remove_dir_all(&self.0); } }