Repository navigation
test: add a self-removing TestDir helper for the test suites - #789
Merged
Merged
Conversation
Refs #781. Adds TestDir (unique scratch directory removed on drop, also on panic, robust to read-only trees, TOLE_KEEP_TEST_DIRS=1 and keep() escape hatches) and ChildGuard (kill and reap a child before its directory goes) to tole-core and tole-cli, for integration tests and unit tests. No test is converted yet.
🔍 Cora AI Code Review✅ No issues found. Code looks good! Review powered by cora-code · BYOK · MIT |
Refs #781. WorkDir creates <root>/w inside a TestDir, so work.with_extension("home") lands in the same removed root.
This was referenced Nov 15, 2026
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Adds
TestDir,WorkDirandChildGuard, a small std-only RAII helper for test scratch directories, totole-coreandtole-cli. No existing test is converted in this PR; the conversions follow in separate PRs, one crate or family of tests each.Why
Refs #781: the suites leaked about 175 000
tole-*/cora-*directories (17 GB) in one day because every test buildsstd::env::temp_dir().join(..)by hand and never removes it. Neither crate hastempfileor any dev-dependency and the owner decision is no new dependency, so the guard is written by hand.Changes
crates/tole-core/tests/support/test_dir.rsand an identicalcrates/tole-cli/tests/common/test_dir.rs:TestDir::new(prefix): unique directory (prefix-pid-counter-clock), canonical path, underCARGO_TARGET_TMPDIRin integration tests (cargo owns it,cargo cleanremoves it) and the system temp dir in unit tests. Derefs toPath, so call sites keep working.Drop, also during a panic; retries after making the tree writable (read-only files and directories, Unix permissions behindcfg(unix)) and after a short wait (a child or scanner still holding a file). Never panics.TOLE_KEEP_TEST_DIRS=1keeps every directory and prints its path;TestDir::keep()keeps one.WorkDir::new(prefix):<root>/winside aTestDir, for tests that put aCODECORA_HOMEnext to the workdir withwork.with_extension("home"); the twin lands in the same removed root.ChildGuard(Child): kills and reaps the child on drop, so a guard declared after theTestDirstops the child before the directory is removed.support/mod.rs/common/mod.rs(or#[path]for tests that do not pull those in) and to unit tests through a#[cfg(test)] #[path]module in eachlib.rs. No production code changes.tests/test_dir_helper.rsin both crates: removal on drop, on panic, read-only tree (Unix), uniqueness,keep(),WorkDirtwin,ChildGuard(Unix).Testing
cargo fmt --all,cargo clippy --workspace --all-targets -- -D warnings: clean.cargo test -p tole-core --test test_dir_helperandcargo test -p tole-cli --test test_dir_helper: 7 passed each.TMPDIR: onecargo test --workspacerun leaves 1385 entries (148 MB) inTMPDIRplus one intarget/tmp. After the whole series: none (see the conversion PRs and the CI guard PR).Merge order: this PR first; the conversion PRs and the CI guard branch from it.
Refs #781