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:
@@ -60,28 +60,54 @@ outbin(char *dst, size_t n, const char *tmpdir, const char *src)
|
||||
}
|
||||
|
||||
static int
|
||||
build_should_fail(const char *driver, const char *label, const char *src,
|
||||
int i)
|
||||
filehas(const char *path, const char *needle)
|
||||
{
|
||||
char s[64], tmpdir[64], cmd[1024], bin[128];
|
||||
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;
|
||||
}
|
||||
|
||||
/* A reject row passes only when the build FAILS *and* the stage's clean
|
||||
* diagnostic appears; a crash (segfault) wraps as a nonzero "w6c failed"
|
||||
* with no diagnostic, so the substring check distinguishes it (#20). */
|
||||
static int
|
||||
build_should_fail(const char *driver, const char *label, const char *src,
|
||||
const char *diag, int i)
|
||||
{
|
||||
char s[64], tmpdir[64], cmd[1024], bin[128], errf[64];
|
||||
snprintf(s, sizeof s, "/tmp/idxr_%d_%d.ww", getpid(), i);
|
||||
snprintf(tmpdir, sizeof tmpdir, "/tmp/idxr_%d_d_%d", getpid(), i);
|
||||
snprintf(errf, sizeof errf, "/tmp/idxr_%d_e_%d.txt", getpid(), i);
|
||||
FILE *f = fopen(s, "wb");
|
||||
if (!f) return -1;
|
||||
fputs(src, f);
|
||||
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);
|
||||
outbin(bin, sizeof bin, tmpdir, s);
|
||||
unlink(s);
|
||||
unlink(bin);
|
||||
unlink(errf);
|
||||
rmdir(tmpdir);
|
||||
if (rc == 0)
|
||||
if (rc == 0) {
|
||||
fprintf(stderr, "idxr[%s][%s]: built ok, expected a reject\n",
|
||||
driver, label);
|
||||
return rc == 0 ? -1 : 0;
|
||||
return -1;
|
||||
}
|
||||
if (!hasmsg) {
|
||||
fprintf(stderr, "idxr[%s][%s]: nonzero exit but missing "
|
||||
"diagnostic \"%s\" (a crash, not a clean reject)\n",
|
||||
driver, label, diag);
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
@@ -109,7 +135,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; };
|
||||
|
||||
static const struct rejrow reject_rows[] = {
|
||||
{ "by_float",
|
||||
@@ -118,28 +144,32 @@ static const struct rejrow reject_rows[] = {
|
||||
" let a: [3]i32 = [10i32, 20i32, 30i32];\n"
|
||||
" let f: f64 = 1.0;\n"
|
||||
" return a[f];\n"
|
||||
"};\n" },
|
||||
"};\n",
|
||||
"index must be integer" },
|
||||
{ "by_str",
|
||||
"package main;\n"
|
||||
"fn main() i32 = {\n"
|
||||
" let a: [3]i32 = [10i32, 20i32, 30i32];\n"
|
||||
" let s: str = \"x\";\n"
|
||||
" return a[s];\n"
|
||||
"};\n" },
|
||||
"};\n",
|
||||
"index must be integer" },
|
||||
{ "by_ptr",
|
||||
"package main;\n"
|
||||
"fn main() i32 = {\n"
|
||||
" let a: [3]i32 = [10i32, 20i32, 30i32];\n"
|
||||
" let p: *i32 = nil;\n"
|
||||
" return a[p];\n"
|
||||
"};\n" },
|
||||
"};\n",
|
||||
"index must be integer" },
|
||||
{ "by_bool",
|
||||
"package main;\n"
|
||||
"fn main() i32 = {\n"
|
||||
" let a: [3]i32 = [10i32, 20i32, 30i32];\n"
|
||||
" let b: bool = true;\n"
|
||||
" return a[b];\n"
|
||||
"};\n" },
|
||||
"};\n",
|
||||
"index must be integer" },
|
||||
};
|
||||
|
||||
struct okrow { const char *label; const char *src; int want; };
|
||||
@@ -217,7 +247,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++) {
|
||||
|
||||
Reference in New Issue
Block a user