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:
@@ -37,6 +37,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[] = {
|
||||
@@ -46,14 +47,14 @@ static const struct row rows[] = {
|
||||
"package main;\n"
|
||||
"fnn helper() i32 = { return 42; };\n"
|
||||
"export fn main() i32 = { return 0; };\n",
|
||||
0, 0 },
|
||||
0, 0, "expected top-level decl" },
|
||||
|
||||
/* REJECT — a stray run of bare identifiers at top level. */
|
||||
{ "stray_idents",
|
||||
"package main;\n"
|
||||
"bogus token here;\n"
|
||||
"export fn main() i32 = { return 0; };\n",
|
||||
0, 0 },
|
||||
0, 0, "expected top-level decl" },
|
||||
|
||||
/* REJECT — a stray decl whose body has internal ';'s, exercising the
|
||||
* brace-balanced chew recovery (still must error, not silently skip). */
|
||||
@@ -61,7 +62,7 @@ static const struct row rows[] = {
|
||||
"package main;\n"
|
||||
"gizmo foo { let a = 1; let b = 2; };\n"
|
||||
"export fn main() i32 = { return 0; };\n",
|
||||
0, 0 },
|
||||
0, 0, "expected top-level decl" },
|
||||
|
||||
/* control — a clean program builds + runs. */
|
||||
{ "clean_ok",
|
||||
@@ -111,11 +112,31 @@ 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
|
||||
* names the offending token ("expected top-level decl, got IDENT"),
|
||||
* wwstage prints "parse: expected top-level decl"; the shared core is
|
||||
* "expected top-level decl". */
|
||||
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/undn_%d_%d.ww", getpid(), i);
|
||||
snprintf(tmpdir, sizeof tmpdir, "/tmp/undn_%d_d_%d", getpid(), i);
|
||||
snprintf(errf, sizeof errf, "/tmp/undn_%d_e_%d.txt", getpid(), i);
|
||||
|
||||
FILE *f = fopen(s, "wb");
|
||||
if (!f) return -1;
|
||||
@@ -123,11 +144,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];
|
||||
@@ -136,7 +159,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
|
||||
@@ -184,7 +208,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, "unknowndecl_reject[%s][%s]: "
|
||||
"built ok, expected a loud reject\n",
|
||||
drivers[d].name, rows[i].label);
|
||||
|
||||
Reference in New Issue
Block a user