diff options
Diffstat (limited to 'src/files.rs')
| -rw-r--r-- | src/files.rs | 13 |
1 files changed, 11 insertions, 2 deletions
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-<name>-<process ID>` 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(); |
