test: require diagnostic on reject rows, close crash-vacuity (#20)

Reject helpers checked only rc!=0, so a SEGFAULT (exit 139, or the
driver's "w6c failed" exit 1) counted as a clean reject -- a wwstage
crash could pass vacuously (it did, latently, on bodied bare-... pre
#11). Every reject row now captures stderr and requires the actual
diagnostic substring (rc!=0 AND strstr) across all 16 reject tests; a
crash emits no diagnostic, so it now fails. This is the
differential-reject backstop (#15): both stages must cleanly reject
with the expected message.

Two genuine cstage/wwstage diagnostic-body divergences are documented
inline via per-stage substrings, not papered over (845 tuple parse,
catA_f2 tuple arity); catalogued in #21.
This commit is contained in:
2026-06-21 13:04:59 +09:00
parent 1f1efb273a
commit e8ef1e061c
16 changed files with 631 additions and 179 deletions

View File

@@ -39,6 +39,7 @@ struct row {
const char *src;
int expect_build; /* 1 = build+run to want_exit; 0 = must FAIL */
int want_exit;
const char *diag; /* expected reject diagnostic (NULL for build rows) */
};
static const struct row rows[] = {
@@ -49,7 +50,7 @@ static const struct row rows[] = {
" let x: u64 = 99999999999999999999u64;\n"
" return x: i32;\n"
"};\n",
0, 0 },
0, 0, "bad integer literal" },
/* REJECT — 65-bit hex (smallest overflow above U64_MAX). */
{ "hex_overflow",
@@ -58,7 +59,7 @@ static const struct row rows[] = {
" let x: u64 = 0x1ffffffffffffffffu64;\n"
" return x: i32;\n"
"};\n",
0, 0 },
0, 0, "bad integer literal" },
/* REJECT — 2^128-1 decimal, far over u64. */
{ "dec_huge",
@@ -67,7 +68,7 @@ static const struct row rows[] = {
" let x: u64 = 340282366920938463463374607431768211455u64;\n"
" return x: i32;\n"
"};\n",
0, 0 },
0, 0, "bad integer literal" },
/* control — U64_MAX decimal is the largest accepted literal. */
{ "u64max_dec_ok",
@@ -122,11 +123,30 @@ run_build(const char *driver, const struct row *r, int i)
}
static int
build_should_fail(const char *driver, const char *src, int i)
filehas(const char *path, const char *needle)
{
char s[64], tmpdir[64], cmd[1024];
char buf[8192];
FILE *f = fopen(path, "rb");
if (!f) return 0;
size_t n = fread(buf, 1, sizeof buf - 1, f);
fclose(f);
buf[n] = '\0';
return strstr(buf, needle) != NULL;
}
/* build_should_fail — the build must FAIL *and* emit `diag`. A crash
* (segfault) wraps as a nonzero "w6c failed" with no diagnostic, so the
* substring check distinguishes it from a clean reject (#20). cstage
* quotes the literal ("bad integer literal '99...'"), wwstage does not;
* "bad integer literal" is the shared core. */
static int
build_should_fail(const char *driver, const char *src, const char *diag,
int i)
{
char s[64], tmpdir[64], cmd[1024], errf[64];
snprintf(s, sizeof s, "/tmp/iovn_%d_%d.ww", getpid(), i);
snprintf(tmpdir, sizeof tmpdir, "/tmp/iovn_%d_d_%d", getpid(), i);
snprintf(errf, sizeof errf, "/tmp/iovn_%d_e_%d.txt", getpid(), i);
FILE *f = fopen(s, "wb");
if (!f) return -1;
@@ -134,11 +154,13 @@ build_should_fail(const char *driver, const char *src, int i)
fclose(f);
mkdir(tmpdir, 0755);
snprintf(cmd, sizeof cmd, "cd %s && %s build %s 2>/dev/null",
tmpdir, driver, s);
snprintf(cmd, sizeof cmd, "cd %s && %s build %s >/dev/null 2>%s",
tmpdir, driver, s, errf);
int rc = runwait(cmd);
int hasmsg = filehas(errf, diag);
unlink(s);
unlink(errf);
const char *base = strrchr(s, '/');
base = base ? base + 1 : s;
char outbin[128];
@@ -147,7 +169,8 @@ build_should_fail(const char *driver, const char *src, int i)
if (dot && strcmp(dot, ".ww") == 0) *dot = '\0';
unlink(outbin);
rmdir(tmpdir);
return rc == 0 ? -1 : 0; /* build must NOT succeed */
/* build must NOT succeed AND must emit its diagnostic. */
return (rc != 0 && hasmsg) ? 0 : -1;
}
int
@@ -195,7 +218,7 @@ main(void)
}
} else {
if (build_should_fail(drivers[d].drv, rows[i].src,
100 + i) != 0) {
rows[i].diag, 100 + i) != 0) {
fprintf(stderr, "intoverflow_reject[%s][%s]: "
"built ok, expected a loud reject\n",
drivers[d].name, rows[i].label);