fabrilis/tools/limits/tests/tree/mod.rs
loki5512344 878d144b77 Initial commit: Fabrilis docs, rules and deterministic core
Docs (architecture, decisions, coupling, determinism, UI, references), code rules enforced by tools/limits, deterministic core with units, time, math, sched, snapshot, vec and rng, plus smoke tests. ref/ stays out of git.
2026-11-16 23:06:29 +01:00

37 lines
785 B
Rust

//! 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);
}
}