test: contain sepwork scratch per-driver tmpdir, fix /tmp+in-repo leak (#8)

The wcc test drivers ran `ww build <bare-/tmp src>` with no -o, so the
compiler's <stem>.sepwork scratch landed beside the source and was never
cleaned: unbounded /tmp growth (2195 stale dirs observed) that fills tmpfs
and fabricates phantom test failures + silent harness aborts, and for
in-repo fixture builds leaked .sepwork into the tracked tree.

Each leaking build now writes its source + output inside a per-invocation
tmpdir, passes -o <tmpdir>/<stem> so the .sepwork lands inside it, and
rm -rf's the tmpdir on every exit path -- including fopen-fail and the
expected-fail reject builds (scratch is mkdir'd before the build can fail).
`ww run` and explicit-`-o`/byte-id helpers are left as-is; the 990/993
byte-id comparison logic is byte-for-byte unchanged.

Two items filed separately (this commit holds the no-Makefile / no-main.c
rail):
- #13: a stale <src>.s byte-id readback (749) silently no-ops since
  separate-compile emits .s to <ostem>.sepwork/__root.s; documented inline.
- #14: build-system Makefile recipes build selfhost/cmd/*/main.ww with no
  -o and leak main.sepwork in-tree (bounded, gitignored; own commit).

One concern -- sepwork leak hygiene -- across 228 drivers; uniform
transform applied per-file and two-round reviewed. make test: all 402
passed, zero net-new /tmp scratch, zero test-driven in-repo .sepwork.
This commit is contained in:
2026-06-22 23:29:39 +09:00
parent 6525e137ae
commit ce3a25a0b4
228 changed files with 3387 additions and 4484 deletions

View File

@@ -53,23 +53,33 @@ runwait(const char *cmd)
static int
run_row(const char *driver, const char *fixdir, const char *tag)
{
/* Scratch dir OUT of the repo: the driver's sep `<stem>.sepwork/`
* follows the build output stem, so point -o into /tmp so both the
* binary and its .sepwork land there and die with rm -rf. */
char td[64];
snprintf(td, sizeof td, "/tmp/usepr_%d_%s", getpid(), tag);
mkdir(td, 0755);
char rmcmd[128];
snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", td);
char src[64];
snprintf(src, sizeof src, "pos_%s.ww", tag);
char bin[2048];
snprintf(bin, sizeof bin, "%s/out", td);
char cmd[2048];
/* cd into the fixture dir so the driver's source-dir-first
* import search resolves `use <tag>mod;`. */
* import search resolves `use <tag>mod;`; -o points OUT of the repo. */
snprintf(cmd, sizeof cmd,
"cd %s && %s build %s >/dev/null 2>&1", fixdir, driver, src);
"cd %s && %s build -o %s %s >/dev/null 2>&1", fixdir, driver, bin, src);
if (runwait(cmd) != 0) {
fprintf(stderr,
"use_promote_alias[%s]: build failed — SK_USE→SK_X "
"promotion likely dropped use_alias\n", tag);
runwait(rmcmd);
return 1;
}
char bin[2048];
snprintf(bin, sizeof bin, "%s/pos_%s", fixdir, tag);
int got = runwait(bin);
unlink(bin);
runwait(rmcmd);
if (got != 42) {
fprintf(stderr,
"use_promote_alias[%s]: exit=%d want=42\n", tag, got);