aboutsummaryrefslogtreecommitdiffstats
path: root/src/files.rs
diff options
context:
space:
mode:
authortv <tv@krebsco.de>2026-11-18 12:38:19 +0100
committertv <tv@krebsco.de>2026-11-18 12:38:19 +0100
commit257ad0391ff8eba437108e1885c45314e9fd5833 (patch)
tree3098609e38125c0afb326efeb41a08d0045da3d4 /src/files.rs
parentcfe3dbaff24b5ae433b3203d69c7e9bceb4e1ccc (diff)
parent55f36a960a90aedcb6e899ea963cc642fd630a82 (diff)
Merge branch 'ecdsa'
Diffstat (limited to 'src/files.rs')
-rw-r--r--src/files.rs29
1 files changed, 24 insertions, 5 deletions
diff --git a/src/files.rs b/src/files.rs
index 3e27066..320543f 100644
--- a/src/files.rs
+++ b/src/files.rs
@@ -261,13 +261,34 @@ fn with_suffix(path: &Path, suffix: &str) -> PathBuf {
}
/// An empty directory for the test `name`: `continuum-<name>-<process ID>` in the
-/// temporary directory, emptied first.
+/// temporary directory, emptied first, and removed with all it holds once dropped, the
+/// test passing or failing.
#[cfg(test)]
-pub(crate) fn scratch_dir(name: &str) -> PathBuf {
+pub(crate) fn scratch_dir(name: &str) -> Scratch {
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
+ Scratch(dir)
+}
+
+/// A test's directory (`scratch_dir`), removed when dropped.
+#[cfg(test)]
+pub(crate) struct Scratch(PathBuf);
+
+#[cfg(test)]
+impl std::ops::Deref for Scratch {
+ type Target = Path;
+
+ fn deref(&self) -> &Path {
+ &self.0
+ }
+}
+
+#[cfg(test)]
+impl Drop for Scratch {
+ fn drop(&mut self) {
+ let _ = std::fs::remove_dir_all(&self.0);
+ }
}
#[cfg(test)]
@@ -302,7 +323,5 @@ mod tests {
);
assert_eq!(files.counts()[0].1.appended_bytes, 1);
assert_eq!(files.counts()[1].1.reads, 0);
-
- std::fs::remove_dir_all(&dir).unwrap();
}
}