tests: every test dir is removed when its test ends, pass or panic
Many test helpers removed their temp dir only before the test, or only on pass, so runs left them behind: 117,000 filled /tmp (RAM here) and stopped a mutation run. Each now holds a guard that removes the dir on drop, unwind included; servers started on a test dir hold its guard until they stop. A full cargo test --workspace leaves 0 dirs (859 before). just sweep-test-tmp stays for runs killed mid-test. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01T3gXMVt7XJPi6ens1or9Dj
This commit is contained in:
44 files changed
+952
-163
No files matched your search
@@ -67,13 +67,15 @@ fn set_read_only(root: &Path, read_only: bool) {
|
||||
walk(root, read_only);
|
||||
}
|
||||
|
||||
/// Makes the books writable again when dropped, so a failing or
|
||||
/// interrupted run never leaves a folder no one can delete.
|
||||
/// Makes the books writable again and removes them when dropped, so a
|
||||
/// run that passes or fails never leaves a folder behind, let alone one no
|
||||
/// one can delete.
|
||||
struct Writable(PathBuf);
|
||||
impl Drop for Writable {
|
||||
fn drop(&mut self) {
|
||||
if self.0.exists() {
|
||||
set_read_only(&self.0, false);
|
||||
let _ = std::fs::remove_dir_all(&self.0);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -105,6 +107,7 @@ fn the_viewer_never_writes_into_the_books() {
|
||||
set_read_only(&dir, false);
|
||||
std::fs::remove_dir_all(&dir).unwrap();
|
||||
}
|
||||
let _restore = Writable(dir.clone());
|
||||
let today = chrono::NaiveDate::from_ymd_opt(2026, 10, 12).unwrap();
|
||||
ledger_gui::demo::build(&dir, today).unwrap();
|
||||
let source = Source {
|
||||
@@ -112,7 +115,6 @@ fn the_viewer_never_writes_into_the_books() {
|
||||
books_toml: Some(dir.join("wanderbooks.toml")),
|
||||
today: Some(today),
|
||||
};
|
||||
let _restore = Writable(dir.clone());
|
||||
set_read_only(&dir, true);
|
||||
let before = tree(&dir);
|
||||
|
||||
@@ -219,5 +221,4 @@ fn the_viewer_never_writes_into_the_books() {
|
||||
"the viewer created or removed files in writable books"
|
||||
);
|
||||
assert!(before == after, "the viewer changed writable books");
|
||||
let _ = std::fs::remove_dir_all(&dir);
|
||||
}
|
||||
Reference in new issue
Block a user