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:
@@ -40,6 +40,8 @@ struct row {
|
||||
const char *src;
|
||||
int expect_build; /* 1 = build+run to want_exit; 0 = must FAIL */
|
||||
int want_exit;
|
||||
const char *diag; /* cstage/shared reject diagnostic (NULL for build rows) */
|
||||
const char *wdiag; /* wwstage override when stages diverge (NULL = use diag) */
|
||||
};
|
||||
|
||||
static const struct row rows[] = {
|
||||
@@ -53,7 +55,7 @@ static const struct row rows[] = {
|
||||
" xs[0] = 77u8;\n"
|
||||
" return n;\n"
|
||||
"};\n",
|
||||
0, 0 },
|
||||
0, 0, "array length must be an integer literal" },
|
||||
|
||||
/* #2 control — a literal dimension stays valid → run 0. */
|
||||
{ "arrlen_const_ok",
|
||||
@@ -75,7 +77,7 @@ static const struct row rows[] = {
|
||||
" let c: str = a + b;\n"
|
||||
" return c.len: i32;\n"
|
||||
"};\n",
|
||||
0, 0 },
|
||||
0, 0, "arithmetic on non-numeric type" },
|
||||
|
||||
/* #6 — bitwise & on str is non-integer → REJECT. */
|
||||
{ "str_bitand",
|
||||
@@ -86,7 +88,7 @@ static const struct row rows[] = {
|
||||
" let n: i32 = (a & b): i32;\n"
|
||||
" return n;\n"
|
||||
"};\n",
|
||||
0, 0 },
|
||||
0, 0, "bitwise on non-integer type" },
|
||||
|
||||
/* #6 — ordered comparison on str is non-numeric → REJECT (EQ/NEQ stay
|
||||
* valid; only the ordered <,<=,>,>= are gated, matching cstage). */
|
||||
@@ -98,7 +100,7 @@ static const struct row rows[] = {
|
||||
" if (a < b) { return 1; };\n"
|
||||
" return 0;\n"
|
||||
"};\n",
|
||||
0, 0 },
|
||||
0, 0, "ordered comparison on non-numeric" },
|
||||
|
||||
/* #6 — unary ~ on a non-integer (str) → REJECT. */
|
||||
{ "tilde_str",
|
||||
@@ -108,7 +110,7 @@ static const struct row rows[] = {
|
||||
" let n: i32 = (~a): i32;\n"
|
||||
" return n;\n"
|
||||
"};\n",
|
||||
0, 0 },
|
||||
0, 0, "~ on non-integer" },
|
||||
|
||||
/* #6 control — integer arithmetic, comparison, bitwise all valid. */
|
||||
{ "int_ops_ok",
|
||||
@@ -130,7 +132,7 @@ static const struct row rows[] = {
|
||||
" let v: i32 = 5;\n"
|
||||
" return size(v): i32;\n"
|
||||
"};\n",
|
||||
0, 0 },
|
||||
0, 0, "unknown type 'v'" },
|
||||
|
||||
/* #7 control — size() of a real type folds → run 4. */
|
||||
{ "size_type_ok",
|
||||
@@ -145,7 +147,7 @@ static const struct row rows[] = {
|
||||
" let t: (i32, i32) = (1, 2, 3);\n"
|
||||
" return 0;\n"
|
||||
"};\n",
|
||||
0, 0 },
|
||||
0, 0, "not assignable to declared", "tuple literal has 3 elements" },
|
||||
|
||||
/* #10 — a short tuple literal → REJECT (the live miscompile: cgen
|
||||
* filled the missing slot with a stale register). */
|
||||
@@ -155,7 +157,7 @@ static const struct row rows[] = {
|
||||
" let t: (i32, i32, i32) = (1, 2);\n"
|
||||
" return 0;\n"
|
||||
"};\n",
|
||||
0, 0 },
|
||||
0, 0, "not assignable to declared", "tuple literal has 2 elements" },
|
||||
|
||||
/* #10 control — a matching-arity tuple literal → run 3. */
|
||||
{ "tuple_match_ok",
|
||||
@@ -178,7 +180,7 @@ static const struct row rows[] = {
|
||||
" a, s = f();\n"
|
||||
" return 0;\n"
|
||||
"};\n",
|
||||
0, 0 },
|
||||
0, 0, "multi-assign rhs is not a tuple" },
|
||||
|
||||
/* #39 — multi-assign rhs is a plain scalar, not a tuple → REJECT. */
|
||||
{ "massign_scalar",
|
||||
@@ -190,7 +192,7 @@ static const struct row rows[] = {
|
||||
" a, s = g();\n"
|
||||
" return 0;\n"
|
||||
"};\n",
|
||||
0, 0 },
|
||||
0, 0, "multi-assign rhs is not a tuple" },
|
||||
|
||||
/* #39 control — a bare-tuple-returning fn drives a valid massign. */
|
||||
{ "massign_tuple_ok",
|
||||
@@ -213,7 +215,7 @@ static const struct row rows[] = {
|
||||
"type e = !void;\n"
|
||||
"fn g() (...inner | e) = { return true; };\n"
|
||||
"export fn main() i32 = { let x = g()!; return 0; };\n",
|
||||
0, 0 },
|
||||
0, 0, "multi-success union unwired" },
|
||||
|
||||
/* #8 control — a single-success tagged union try unwraps fine → run 5. */
|
||||
{ "try_single_ok",
|
||||
@@ -234,7 +236,7 @@ static const struct row rows[] = {
|
||||
" let r = match (v) { case i32 => yield 7; case str => yield \"oops\"; };\n"
|
||||
" return 0;\n"
|
||||
"};\n",
|
||||
0, 0 },
|
||||
0, 0, "match arm yields" },
|
||||
|
||||
/* match-yield control — same-family arm yields (untyped_int + i32) must
|
||||
* NOT over-reject (the untyped->concrete promotion cstage admits) → run 9. */
|
||||
@@ -281,11 +283,28 @@ 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). */
|
||||
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/f2n_%d_%d.ww", getpid(), i);
|
||||
snprintf(tmpdir, sizeof tmpdir, "/tmp/f2n_%d_d_%d", getpid(), i);
|
||||
snprintf(errf, sizeof errf, "/tmp/f2n_%d_e_%d.txt", getpid(), i);
|
||||
|
||||
FILE *f = fopen(s, "wb");
|
||||
if (!f) return -1;
|
||||
@@ -293,11 +312,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];
|
||||
@@ -306,7 +327,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
|
||||
@@ -354,6 +376,8 @@ main(void)
|
||||
}
|
||||
} else {
|
||||
if (build_should_fail(drivers[d].drv, rows[i].src,
|
||||
drivers[d].gated && rows[i].wdiag
|
||||
? rows[i].wdiag : rows[i].diag,
|
||||
100 + i) != 0) {
|
||||
fprintf(stderr, "catA_f2_reject[%s][%s]: "
|
||||
"built ok, expected a loud reject\n",
|
||||
|
||||
Reference in New Issue
Block a user