From 4a42f2791292104059fc5daf9c9fddc5d9b249d3 Mon Sep 17 00:00:00 2001 From: tv Date: Sat, 31 Oct 2026 05:25:54 +0100 Subject: tests: unify scratch dir logic --- src/files.rs | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'src/files.rs') diff --git a/src/files.rs b/src/files.rs index 0ec741e..e27bde6 100644 --- a/src/files.rs +++ b/src/files.rs @@ -173,14 +173,23 @@ fn with_suffix(path: &Path, suffix: &str) -> PathBuf { PathBuf::from(name) } +/// An empty directory for the test `name`: `continuum--` in the +/// temporary directory, emptied first. +#[cfg(test)] +pub(crate) fn scratch_dir(name: &str) -> PathBuf { + let dir = std::env::temp_dir().join(format!("continuum-{name}-{}", std::process::id())); + let _ = std::fs::remove_dir_all(&dir); + std::fs::create_dir_all(&dir).unwrap(); + dir +} + #[cfg(test)] mod tests { use super::*; #[test] fn writes_reads_and_counts() { - let dir = std::env::temp_dir().join(format!("continuum-files-{}", std::process::id())); - std::fs::create_dir_all(&dir).unwrap(); + let dir = scratch_dir("files"); let path = dir.join("state.json"); let files = Files::default(); -- cgit v1.3.1