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

@@ -62,17 +62,32 @@ runwait(const char *cmd)
return -1;
}
static int
filehas(const char *path, const char *needle)
{
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 — a dup-`main` program must error on `driver`
* (loud reject); returns 0 when the build correctly FAILS, non-zero
* when it wrongly succeeded. Intermediates land in tmpdir, never the
* source tree (rule 14). */
* (loud reject); returns 0 when the build FAILS *and* emits `diag`.
* This test drives the full `ww` driver, so a crash inside w6c also
* surfaces as the driver's "w6c failed" exit 1 — the diagnostic-substring
* check is the ONLY way to tell a crash from a clean reject here (#20).
* Intermediates land in tmpdir, never the source tree (rule 14). */
static int
build_should_fail(const char *driver, const char *label, const char *src,
int i)
const char *diag, int i)
{
char s[64], tmpdir[64], cmd[1024];
char s[64], tmpdir[64], cmd[1024], errf[64];
snprintf(s, sizeof s, "/tmp/dupmain_%d_%d.ww", getpid(), i);
snprintf(tmpdir, sizeof tmpdir, "/tmp/dupmain_%d_d_%d", getpid(), i);
snprintf(errf, sizeof errf, "/tmp/dupmain_%d_e_%d.txt", getpid(), i);
FILE *f = fopen(s, "wb");
if (!f) return -1;
@@ -80,9 +95,10 @@ build_should_fail(const char *driver, const char *label, const char *src,
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);
const char *base = strrchr(s, '/');
base = base ? base + 1 : s;
@@ -91,13 +107,22 @@ build_should_fail(const char *driver, const char *label, const char *src,
char *dot = strrchr(outbin, '.');
if (dot && strcmp(dot, ".ww") == 0) *dot = '\0';
unlink(s);
unlink(errf);
unlink(outbin);
rmdir(tmpdir);
if (rc == 0)
if (rc == 0) {
fprintf(stderr,
"dup_main[%s][%s]: built ok, expected a loud reject\n",
driver, label);
return rc == 0 ? -1 : 0; /* build must NOT succeed */
return -1;
}
if (!hasmsg) {
fprintf(stderr, "dup_main[%s][%s]: nonzero exit but missing "
"diagnostic \"%s\" (a crash, not a clean reject)\n",
driver, label, diag);
return -1;
}
return 0;
}
/* run_build — build a program that MUST compile, run it, return its
@@ -134,7 +159,7 @@ run_build(const char *driver, const char *label, const char *src, int i)
return got;
}
struct rejrow { const char *label; const char *src; };
struct rejrow { const char *label; const char *src; const char *diag; };
/* Each program declares a second top-level `main` (in package foo)
* alongside the entry `fn main` (in package main), bound by a REAL
@@ -150,7 +175,8 @@ static const struct rejrow reject_rows[] = {
"export fn anchor() i32 = { return main; };\n"
"package main;\n"
"import foo;\n"
"fn main() i32 = { return foo.anchor(); };\n" },
"fn main() i32 = { return foo.anchor(); };\n",
"duplicate entry main" },
{ "fn_main",
"package foo;\n"
@@ -158,7 +184,8 @@ static const struct rejrow reject_rows[] = {
"export fn anchor() i32 = { return 2; };\n"
"package main;\n"
"import foo;\n"
"fn main() i32 = { return foo.anchor(); };\n" },
"fn main() i32 = { return foo.anchor(); };\n",
"duplicate entry main" },
{ "def_main",
"package foo;\n"
@@ -166,7 +193,8 @@ static const struct rejrow reject_rows[] = {
"export fn anchor() i32 = { return main; };\n"
"package main;\n"
"import foo;\n"
"fn main() i32 = { return foo.anchor(); };\n" },
"fn main() i32 = { return foo.anchor(); };\n",
"duplicate entry main" },
{ "type_main",
"package foo;\n"
@@ -174,7 +202,8 @@ static const struct rejrow reject_rows[] = {
"export fn anchor() i32 = { return 3; };\n"
"package main;\n"
"import foo;\n"
"fn main() i32 = { return foo.anchor(); };\n" },
"fn main() i32 = { return foo.anchor(); };\n",
"duplicate entry main" },
};
struct okrow { const char *label; const char *src; int want; };
@@ -225,7 +254,7 @@ main(void)
total++;
if (build_should_fail(drivers[d].path,
reject_rows[i].label, reject_rows[i].src,
d * 100 + i) != 0)
reject_rows[i].diag, d * 100 + i) != 0)
fail++;
}
for (int i = 0; i < nok; i++) {