diff options
| author | tv <tv@krebsco.de> | 2026-10-31 05:25:54 +0100 |
|---|---|---|
| committer | tv <tv@krebsco.de> | 2026-10-31 05:25:54 +0100 |
| commit | 1e7207b0575f59dc16a4b2fd9a92b793ff3541f8 (patch) | |
| tree | 33230652742f9fa33b96a165e0a7ffb6773233e5 /src/files.rs | |
| parent | 766640539b76f8d7dbbc76a8a0cd1686aa3f255b (diff) | |
tests: unify scratch dir logic
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(); |
