test/993: add 255 boundary + build-fail parity to run exit-code rows

Round-2 hardening of the #16 exit-code coverage. 255 is the single-byte
WEXITSTATUS boundary; the build-fail row pins the build-step caller
contract (a failing build must still report non-zero, both drivers
agreeing) so the procrun change that returns the real code can't silently
regress the w6c/w6a/w6l `!= 0` callers.
This commit is contained in:
2026-06-03 19:20:57 +09:00
parent 0f0f2f4aa1
commit 3f04ea15ef

View File

@@ -134,6 +134,28 @@ run_exit_code(const char *bin, const char *driver, int code)
return rc; return rc;
} }
/* Stage a program that fails to compile, run it via the named driver,
* and return the exit code. Pins the build-step caller contract: a
* failing build must still report failure (non-zero) — the #16 fix that
* lets procrun return the real exit code must not regress this, since the
* w6c/w6a/w6l callers only test `!= 0`. */
static int
run_build_fail(const char *bin, const char *driver)
{
char src[64];
snprintf(src, sizeof src, "/tmp/ww_badbuild_%d.ww", getpid());
FILE *f = fopen(src, "w");
if (!f) return -1;
fputs("export fn main() i32 = {\n\treturn 1\n", f); /* no ; no } */
fclose(f);
char cmd[256];
snprintf(cmd, sizeof cmd, "%s/%s run %s 2>/dev/null", bin, driver, src);
int rc = runwait(cmd);
unlink(src);
return rc;
}
int int
main(void) main(void)
{ {
@@ -196,9 +218,10 @@ main(void)
/* #16: `ww_ww run` must propagate the child program's real exit code /* #16: `ww_ww run` must propagate the child program's real exit code
* (the shared procrun helper was collapsing every non-zero exit to 1). * (the shared procrun helper was collapsing every non-zero exit to 1).
* Table-driven; the non-zero rows fail under the old collapse-to-1. * Table-driven; the non-zero rows fail under the old collapse-to-1.
* The C ww driver is the reference (do_run -> WEXITSTATUS); assert * 255 is the single-byte boundary (WEXITSTATUS max). The C ww driver
* ww_ww matches it row-for-row. */ * is the reference (do_run -> WEXITSTATUS); assert ww_ww matches it
static const int exit_codes[] = { 0, 7, 42 }; * row-for-row. */
static const int exit_codes[] = { 0, 7, 42, 255 };
int nrc = (int)(sizeof exit_codes / sizeof exit_codes[0]); int nrc = (int)(sizeof exit_codes / sizeof exit_codes[0]);
int rcfail = 0; int rcfail = 0;
for (int i = 0; i < nrc; i++) { for (int i = 0; i < nrc; i++) {
@@ -217,6 +240,16 @@ main(void)
} }
} }
/* Build-step caller contract: a failing build must still report
* failure (non-zero), and both drivers must agree. */
int cbad = run_build_fail(bin, "ww");
int wbad = run_build_fail(bin, "ww_ww");
if (cbad == 0 || wbad == 0 || cbad != wbad) {
fprintf(stderr, "ww_ww FAIL: build-fail exit C ww=%d ww_ww=%d "
"(want equal and non-zero)\n", cbad, wbad);
rcfail++;
}
if (fail || rcfail) { if (fail || rcfail) {
fprintf(stderr, "ww_ww: %d/%d diff(s) failed, %d exit-code " fprintf(stderr, "ww_ww: %d/%d diff(s) failed, %d exit-code "
"row(s) failed\n", fail, n, rcfail); "row(s) failed\n", fail, n, rcfail);
@@ -224,6 +257,7 @@ main(void)
} }
printf("ww_ww: byte-identical to C ww on %d corpus builds " printf("ww_ww: byte-identical to C ww on %d corpus builds "
"(single-file + selfhost/wwdump multi-import); " "(single-file + selfhost/wwdump multi-import); "
"run exit-code propagated on %d rows (#16)\n", n, nrc); "run exit-code propagated on %d rows + build-fail parity (#16)\n",
n, nrc);
return 0; return 0;
} }