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:
@@ -158,6 +158,12 @@ static const char *neg[] = {
|
||||
"export fn main() i32 = { return 0; };\n",
|
||||
};
|
||||
|
||||
/* Per-neg expected diagnostic body (parallel to neg[]); shared by both
|
||||
* stages (cstage prepends file:line:col, wwstage does not — #20). */
|
||||
static const char *neg_diag[] = {
|
||||
"[_]T needs an array-literal initialiser",
|
||||
};
|
||||
|
||||
static int
|
||||
run_driver(const char *driver, const struct row *r, int i)
|
||||
{
|
||||
@@ -192,15 +198,30 @@ run_driver(const char *driver, const struct row *r, int i)
|
||||
return got;
|
||||
}
|
||||
|
||||
/* build_should_fail — a `def [_]T` that can't infer must error on
|
||||
* `driver`; returns 0 when the build correctly FAILS, non-zero when it
|
||||
* wrongly succeeded. */
|
||||
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 — a `def [_]T` that can't infer must error on
|
||||
* `driver`; returns 0 when the build FAILS *and* emits `diag`. A crash
|
||||
* (segfault) wraps as a nonzero "w6c failed" with no diagnostic, so the
|
||||
* substring check distinguishes it from a clean reject (#20). */
|
||||
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/dailn_%d_%d.ww", getpid(), i);
|
||||
snprintf(tmpdir, sizeof tmpdir, "/tmp/dailn_%d_d_%d", getpid(), i);
|
||||
snprintf(errf, sizeof errf, "/tmp/dailn_%d_e_%d.txt", getpid(), i);
|
||||
|
||||
FILE *f = fopen(s, "wb");
|
||||
if (!f) return -1;
|
||||
@@ -208,10 +229,12 @@ 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);
|
||||
/* clean any emitted binary */
|
||||
const char *base = strrchr(s, '/');
|
||||
base = base ? base + 1 : s;
|
||||
@@ -221,7 +244,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;
|
||||
}
|
||||
|
||||
/* asm_byte_identical — w6c vs w6c_ww .s for the same source must match.
|
||||
@@ -326,7 +350,7 @@ main(void)
|
||||
for (int i = 0; i < nn; i++) {
|
||||
total++;
|
||||
if (build_should_fail(drivers[d].path, neg[i],
|
||||
100 + i) != 0) {
|
||||
neg_diag[i], 100 + i) != 0) {
|
||||
fprintf(stderr,
|
||||
"def_arr_infer_len[%s][neg%d]: built ok, "
|
||||
"expected a loud error\n",
|
||||
|
||||
Reference in New Issue
Block a user