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:
swaitsandClaude Opus 5.5 committed 2026-10-17 20:47:44 -06:00
1 parent c587593d78
commit 6c04342427
44 files changed
+952 -163

No files matched your search

+4 -4
View File
@@ -670,16 +670,16 @@ mod tests {
let dir =
std::env::temp_dir().join(format!("ledger-gui-attention-{}-{tag}", std::process::id()));
let _ = std::fs::remove_dir_all(&dir);
// Loaded books need no files: removed once loaded, pass or panic.
let _cleanup = crate::test_support::TempDir(dir.clone());
let data_dir = dir.join("books-data");
ledger_store::Store::create(&data_dir, ledger_core::Currency::USD).unwrap();
let b = crate::data::load_once(&crate::data::Source {
crate::data::load_once(&crate::data::Source {
data_dir,
books_toml: None,
today: Some(today),
})
.unwrap();
let _ = std::fs::remove_dir_all(&dir);
b
.unwrap()
}
/// INVARIANTS 2 and 4: a dated rule past its review is one Todo item
+11 -2
View File
@@ -2169,6 +2169,15 @@ mod tests {
}
use super::*;
/// A test's dir, removed when the test ends, pass or panic.
struct TestDir(std::path::PathBuf);
impl Drop for TestDir {
fn drop(&mut self) {
let _ = std::fs::remove_dir_all(&self.0);
}
}
/// The fixed asset register report's tax columns are the register's:
/// each held asset's contributor's basis, tax basis, and built-in gain
/// (ledger-core's Asset::tax_basis and built_in_gain), the total its
@@ -2178,6 +2187,7 @@ mod tests {
let today = NaiveDate::from_ymd_opt(2026, 10, 12).unwrap();
let dir = std::env::temp_dir().join(format!("ledger-gui-tax-{}", std::process::id()));
let _ = std::fs::remove_dir_all(&dir);
let _cleanup = TestDir(dir.clone());
crate::demo::build(&dir, today).unwrap();
let b = crate::data::load_once(&crate::data::Source {
data_dir: dir.join("books-data"),
@@ -2234,7 +2244,6 @@ mod tests {
.iter()
.any(|row| row.kind == Kind::Note && row.label.contains("fair market value"))
);
let _ = std::fs::remove_dir_all(&dir);
}
/// Every table-backed report typesets as a PDF, in its plain, by-month,
@@ -2244,6 +2253,7 @@ mod tests {
let today = NaiveDate::from_ymd_opt(2026, 10, 12).unwrap();
let dir = std::env::temp_dir().join(format!("ledger-gui-pdf-{}", std::process::id()));
let _ = std::fs::remove_dir_all(&dir);
let _cleanup = TestDir(dir.clone());
crate::demo::build(&dir, today).unwrap();
let b = crate::data::load_once(&crate::data::Source {
data_dir: dir.join("books-data"),
@@ -2296,6 +2306,5 @@ mod tests {
std::fs::write(d.join(format!("{name}.pdf")), bytes).unwrap();
}
}
let _ = std::fs::remove_dir_all(&dir);
}
}