diff --git a/test/wcc/993_ww_ww.c b/test/wcc/993_ww_ww.c index fccb0581..66998769 100644 --- a/test/wcc/993_ww_ww.c +++ b/test/wcc/993_ww_ww.c @@ -134,6 +134,28 @@ run_exit_code(const char *bin, const char *driver, int code) 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 main(void) { @@ -196,9 +218,10 @@ main(void) /* #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). * Table-driven; the non-zero rows fail under the old collapse-to-1. - * The C ww driver is the reference (do_run -> WEXITSTATUS); assert - * ww_ww matches it row-for-row. */ - static const int exit_codes[] = { 0, 7, 42 }; + * 255 is the single-byte boundary (WEXITSTATUS max). The C ww driver + * is the reference (do_run -> WEXITSTATUS); assert ww_ww matches it + * row-for-row. */ + static const int exit_codes[] = { 0, 7, 42, 255 }; int nrc = (int)(sizeof exit_codes / sizeof exit_codes[0]); int rcfail = 0; 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) { fprintf(stderr, "ww_ww: %d/%d diff(s) failed, %d exit-code " "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 " "(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; }