diff --git a/test/wcc/742_parse_error.c b/test/wcc/742_parse_error.c index 2427ee38..50694076 100644 --- a/test/wcc/742_parse_error.c +++ b/test/wcc/742_parse_error.c @@ -12,6 +12,7 @@ */ #include #include +#include #include #include @@ -34,17 +35,41 @@ write_file(const char *path, const char *content) return 0; } +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; +} + +/* check_fail — the tool must exit non-zero AND emit a parse diagnostic. + * Both stages report "expected identifier" first on this fixture; a crash + * exits non-zero with no diagnostic, so the substring distinguishes a + * clean reject from a segfault (#20). */ static int check_fail(const char *tool, const char *src) { - char cmd[4096]; - snprintf(cmd, sizeof cmd, "%s %s >/dev/null 2>/dev/null", tool, src); + char cmd[4096], errf[64]; + snprintf(errf, sizeof errf, "/tmp/parse_err_e_%d.txt", getpid()); + snprintf(cmd, sizeof cmd, "%s %s >/dev/null 2>%s", tool, src, errf); int rc = runwait(cmd); + int hasmsg = filehas(errf, "expected identifier"); + unlink(errf); if (rc == 0) { fprintf(stderr, "742 FAIL: %s exited 0 on parse-error fixture\n", tool); return -1; } + if (!hasmsg) { + fprintf(stderr, "742 FAIL: %s nonzero exit but missing parse " + "diagnostic (a crash, not a clean reject)\n", tool); + return -1; + } return 0; } diff --git a/test/wcc/814_def_arr_infer_len.c b/test/wcc/814_def_arr_infer_len.c index 24b7eef5..e27aab41 100644 --- a/test/wcc/814_def_arr_infer_len.c +++ b/test/wcc/814_def_arr_infer_len.c @@ -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", diff --git a/test/wcc/817_arr_cap_reject.c b/test/wcc/817_arr_cap_reject.c index 2dd546bb..fe3de25c 100644 --- a/test/wcc/817_arr_cap_reject.c +++ b/test/wcc/817_arr_cap_reject.c @@ -121,6 +121,15 @@ static const char *neg[] = { "};\n", }; +/* Per-neg expected diagnostic body (parallel to neg[]); all four rows hit + * the same "no field 'cap' on a fixed-size array" path on both stages. */ +static const char *neg_diag[] = { + "no field 'cap' on a fixed-size array", + "no field 'cap' on a fixed-size array", + "no field 'cap' on a fixed-size array", + "no field 'cap' on a fixed-size array", +}; + static int run_driver(const char *driver, const struct row *r, int i) { @@ -155,14 +164,30 @@ run_driver(const char *driver, const struct row *r, int i) return got; } -/* build_should_fail — `.cap` on an array 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 — `.cap` on an array 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 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/acrn_%d_%d.ww", getpid(), i); snprintf(tmpdir, sizeof tmpdir, "/tmp/acrn_%d_d_%d", getpid(), i); + snprintf(errf, sizeof errf, "/tmp/acrn_%d_e_%d.txt", getpid(), i); FILE *f = fopen(s, "wb"); if (!f) return -1; @@ -170,10 +195,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; @@ -183,7 +210,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. */ @@ -286,7 +314,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, "arr_cap_reject[%s][neg%d]: built ok, " "expected a loud error\n", diff --git a/test/wcc/821_def_str_index_reject.c b/test/wcc/821_def_str_index_reject.c index aa576ca9..5b12ab1d 100644 --- a/test/wcc/821_def_str_index_reject.c +++ b/test/wcc/821_def_str_index_reject.c @@ -141,6 +141,13 @@ static const char *neg[] = { "};\n", }; +/* Per-neg expected diagnostic body (parallel to neg[]); both rows hit the + * same "cannot index a def-constant str" path on both stages. */ +static const char *neg_diag[] = { + "cannot index a def-constant str", + "cannot index a def-constant str", +}; + static int run_driver(const char *driver, const struct row *r, int i) { @@ -175,15 +182,30 @@ run_driver(const char *driver, const struct row *r, int i) return got; } -/* build_should_fail — indexing a def-global scalar str 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 — indexing a def-global scalar str 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 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/dsin_%d_%d.ww", getpid(), i); snprintf(tmpdir, sizeof tmpdir, "/tmp/dsin_%d_d_%d", getpid(), i); + snprintf(errf, sizeof errf, "/tmp/dsin_%d_e_%d.txt", getpid(), i); FILE *f = fopen(s, "wb"); if (!f) return -1; @@ -191,10 +213,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; @@ -204,7 +228,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. */ @@ -307,7 +332,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_str_index_reject[%s][neg%d]: built ok, " "expected a loud error\n", diff --git a/test/wcc/842_dup_main_reject.c b/test/wcc/842_dup_main_reject.c index 9ca3b121..ec2dda27 100644 --- a/test/wcc/842_dup_main_reject.c +++ b/test/wcc/842_dup_main_reject.c @@ -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++) { diff --git a/test/wcc/845_tuple_trailing_comma_reject.c b/test/wcc/845_tuple_trailing_comma_reject.c index d5d0e3d9..632be4bf 100644 --- a/test/wcc/845_tuple_trailing_comma_reject.c +++ b/test/wcc/845_tuple_trailing_comma_reject.c @@ -50,30 +50,59 @@ outbin(char *dst, size_t n, const char *tmpdir, const char *src) if (dot && strcmp(dot, ".ww") == 0) *dot = '\0'; } -/* build_should_fail — returns 0 when the build correctly FAILS. */ +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 — returns 0 when the build FAILS *and* the stage's + * own parse diagnostic appears; a crash wraps as a nonzero "w6c failed" + * with no diagnostic, so the substring distinguishes it (#20). The two + * stages' parse messages diverge with no common core (cstage "unexpected + * token in expression"/"expected ), got ;" vs wwstage "parse: expected + * expression"/"parse: expected ')' in tuple"), so `diag` is passed + * per-stage by the caller (a real fidelity gap, filed under #20). */ 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], bin[128]; + char s[64], tmpdir[64], cmd[1024], bin[128], errf[64]; snprintf(s, sizeof s, "/tmp/tuptc_%d_%d.ww", getpid(), i); snprintf(tmpdir, sizeof tmpdir, "/tmp/tuptc_%d_d_%d", getpid(), i); + snprintf(errf, sizeof errf, "/tmp/tuptc_%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, "tuptc[%s][%s]: built ok, expected a reject\n", driver, label); - return rc == 0 ? -1 : 0; + return -1; + } + if (!hasmsg) { + fprintf(stderr, "tuptc[%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 exit. */ @@ -102,12 +131,18 @@ 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 *cdiag; /* cstage diagnostic body substring */ + const char *wdiag; /* wwstage diagnostic body substring (#20 gap) */ +}; static const struct rejrow reject_rows[] = { { "one_comma", "package main;\n" - "fn main() i32 = { let t = (5,); return 0; };\n" }, + "fn main() i32 = { let t = (5,); return 0; };\n", + "unexpected token in expression", "expected expression" }, }; struct okrow { const char *label; const char *src; int want; }; @@ -161,7 +196,8 @@ main(void) total++; if (build_should_fail(drivers[d].path, reject_rows[i].label, reject_rows[i].src, - d * 100 + i) != 0) + drivers[d].gated ? reject_rows[i].wdiag + : reject_rows[i].cdiag, d * 100 + i) != 0) fail++; } for (int i = 0; i < nok; i++) { diff --git a/test/wcc/846_voidless_return_reject.c b/test/wcc/846_voidless_return_reject.c index f85b05c7..25cb6657 100644 --- a/test/wcc/846_voidless_return_reject.c +++ b/test/wcc/846_voidless_return_reject.c @@ -45,28 +45,56 @@ 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). + * cstage "return void not assignable to i32" and wwstage "return: not + * assignable (void → i32)" share the "not assignable" core. */ +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/vret_%d_%d.ww", getpid(), i); snprintf(tmpdir, sizeof tmpdir, "/tmp/vret_%d_d_%d", getpid(), i); + snprintf(errf, sizeof errf, "/tmp/vret_%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, "vret[%s][%s]: built ok, expected a reject\n", driver, label); - return rc == 0 ? -1 : 0; + return -1; + } + if (!hasmsg) { + fprintf(stderr, "vret[%s][%s]: nonzero exit but missing " + "diagnostic \"%s\" (a crash, not a clean reject)\n", + driver, label, diag); + return -1; + } + return 0; } static int @@ -94,13 +122,14 @@ 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[] = { { "nonvoid", "package main;\n" "fn f() i32 = { return; };\n" - "fn main() i32 = { return f(); };\n" }, + "fn main() i32 = { return f(); };\n", + "not assignable" }, }; struct okrow { const char *label; const char *src; int want; }; @@ -160,7 +189,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++) { diff --git a/test/wcc/847_const_reassign_reject.c b/test/wcc/847_const_reassign_reject.c index bba612e8..87378049 100644 --- a/test/wcc/847_const_reassign_reject.c +++ b/test/wcc/847_const_reassign_reject.c @@ -46,28 +46,56 @@ 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). + * cstage "cannot assign to const `x`" and wwstage "cannot assign to const + * binding" share the "cannot assign to const" core. */ +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/creas_%d_%d.ww", getpid(), i); snprintf(tmpdir, sizeof tmpdir, "/tmp/creas_%d_d_%d", getpid(), i); + snprintf(errf, sizeof errf, "/tmp/creas_%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, "creas[%s][%s]: built ok, expected a reject\n", driver, label); - return rc == 0 ? -1 : 0; + return -1; + } + if (!hasmsg) { + fprintf(stderr, "creas[%s][%s]: nonzero exit but missing " + "diagnostic \"%s\" (a crash, not a clean reject)\n", + driver, label, diag); + return -1; + } + return 0; } static int @@ -95,12 +123,13 @@ 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[] = { { "const_set", "package main;\n" - "fn main() i32 = { const x: i32 = 5; x = 6; return x; };\n" }, + "fn main() i32 = { const x: i32 = 5; x = 6; return x; };\n", + "cannot assign to const" }, }; struct okrow { const char *label; const char *src; int want; }; @@ -148,7 +177,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++) { diff --git a/test/wcc/849_dupfield_reject.c b/test/wcc/849_dupfield_reject.c index de89a7fb..137ee26c 100644 --- a/test/wcc/849_dupfield_reject.c +++ b/test/wcc/849_dupfield_reject.c @@ -49,28 +49,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/dupf_%d_%d.ww", getpid(), i); snprintf(tmpdir, sizeof tmpdir, "/tmp/dupf_%d_d_%d", getpid(), i); + snprintf(errf, sizeof errf, "/tmp/dupf_%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, "dupf[%s][%s]: built ok, expected a reject\n", driver, label); - return rc == 0 ? -1 : 0; + return -1; + } + if (!hasmsg) { + fprintf(stderr, "dupf[%s][%s]: nonzero exit but missing " + "diagnostic \"%s\" (a crash, not a clean reject)\n", + driver, label, diag); + return -1; + } + return 0; } static int @@ -98,21 +124,24 @@ 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[] = { { "adj_dup", "package main;\n" "type d = struct { a: i32, a: i32 };\n" - "fn main() i32 = { let p: *d = nil; return 0; };\n" }, + "fn main() i32 = { let p: *d = nil; return 0; };\n", + "duplicate field" }, { "nonadj_dup", "package main;\n" "type d = struct { a: i32, b: i32, a: i32 };\n" - "fn main() i32 = { let p: *d = nil; return 0; };\n" }, + "fn main() i32 = { let p: *d = nil; return 0; };\n", + "duplicate field" }, { "dup_difftype", "package main;\n" "type d = struct { a: i32, a: bool };\n" - "fn main() i32 = { let p: *d = nil; return 0; };\n" }, + "fn main() i32 = { let p: *d = nil; return 0; };\n", + "duplicate field" }, }; struct okrow { const char *label; const char *src; int want; }; @@ -162,7 +191,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++) { diff --git a/test/wcc/850_enum_reject.c b/test/wcc/850_enum_reject.c index 2b51d99b..e094f305 100644 --- a/test/wcc/850_enum_reject.c +++ b/test/wcc/850_enum_reject.c @@ -51,28 +51,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/enr_%d_%d.ww", getpid(), i); snprintf(tmpdir, sizeof tmpdir, "/tmp/enr_%d_d_%d", getpid(), i); + snprintf(errf, sizeof errf, "/tmp/enr_%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, "enr[%s][%s]: built ok, expected a reject\n", driver, label); - return rc == 0 ? -1 : 0; + return -1; + } + if (!hasmsg) { + fprintf(stderr, "enr[%s][%s]: nonzero exit but missing " + "diagnostic \"%s\" (a crash, not a clean reject)\n", + driver, label, diag); + return -1; + } + return 0; } static int @@ -100,21 +126,28 @@ 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; }; +/* diag substrings are the shared message BODY (no file:line prefix, which + * differs cstage vs wwstage). fwd_ref's stages diverge in wording (cstage + * "enum value: unknown identifier 'B'" vs wwstage "enum value must be a + * constant integer expression"); "enum value" is the common core (#20). */ static const struct rejrow reject_rows[] = { { "nonint_stor", "package main;\n" "type e = enum f64 { A };\n" - "fn main() i32 = { return e.A as i32; };\n" }, + "fn main() i32 = { return e.A as i32; };\n", + "enum storage type must be integer" }, { "dup_member", "package main;\n" "type e = enum { A, B, A };\n" - "fn main() i32 = { return e.A as i32; };\n" }, + "fn main() i32 = { return e.A as i32; };\n", + "duplicate enum member" }, { "fwd_ref", "package main;\n" "type e = enum { A = B, B };\n" - "fn main() i32 = { return e.A as i32; };\n" }, + "fn main() i32 = { return e.A as i32; };\n", + "enum value" }, }; struct okrow { const char *label; const char *src; int want; }; @@ -164,7 +197,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++) { diff --git a/test/wcc/851_index_int_reject.c b/test/wcc/851_index_int_reject.c index 2506332d..3abafeb1 100644 --- a/test/wcc/851_index_int_reject.c +++ b/test/wcc/851_index_int_reject.c @@ -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++) { diff --git a/test/wcc/989_callarg_typecheck.c b/test/wcc/989_callarg_typecheck.c index 56a65f88..22dbf9c5 100644 --- a/test/wcc/989_callarg_typecheck.c +++ b/test/wcc/989_callarg_typecheck.c @@ -68,6 +68,7 @@ struct row { const char *src; int expect_build; /* 1 = build+run to want_exit; 0 = must FAIL */ int want_exit; /* meaningful only when expect_build */ + const char *diag; /* expected reject diagnostic (NULL for build rows) */ }; static const struct row rows[] = { @@ -81,7 +82,7 @@ static const struct row rows[] = { " takesslice(n);\n" " return 0;\n" "};\n", - 0, 0 }, + 0, 0, "not assignable" }, /* (2) str where int is wanted → REJECT both stages. A second scalar * shape: the general check is not array-specific. */ @@ -93,7 +94,7 @@ static const struct row rows[] = { " takesint(s);\n" " return 0;\n" "};\n", - 0, 0 }, + 0, 0, "not assignable" }, /* (3) CONTROL — [3]int into a []int param is the legit #258 borrow * (matching element) → ACCEPT both, run to 0. The general check must @@ -122,7 +123,7 @@ static const struct row rows[] = { { "let_slice_eq_scalar", "package main;\n" "export fn main() int = { let xs: []int = 5; return 0; };\n", - 0, 0 }, + 0, 0, "not assignable" }, /* (6) bare fn name into a fn-alias param → ACCEPT both (#34/c1': a * bare fn rvalue types as its fn TYPE; the general check then sees a @@ -154,7 +155,7 @@ static const struct row rows[] = { "fn g() int = { return 7; };\n" "fn use_it(f: myfn) int = { return f(); };\n" "export fn main() int = { return use_it(&g); };\n", - 0, 0 }, + 0, 0, "not assignable" }, /* (9) matched-signature fn rvalue into a fn slot → ACCEPT both, run 5. * Pins #34's correct-stamp path (fn type vs fn type, equal sigs). */ @@ -172,7 +173,7 @@ static const struct row rows[] = { "package main;\n" "fn h() str = { return \"\"; };\n" "export fn main() int = { let p: fn() int = h; return 0; };\n", - 0, 0 }, + 0, 0, "not assignable" }, /* (11) aggregate<->aggregate KIND mismatch — a [3]int array arg into a * `*int` param. Both aggregate, different kind -> confident reject (the @@ -186,7 +187,7 @@ static const struct row rows[] = { " takesptr(a);\n" " return 0;\n" "};\n", - 0, 0 }, + 0, 0, "not assignable" }, /* (12) CONTROL — a concrete value into a SPREAD-tagged param must NOT * over-reject: cstage flattens `...inner` at resolve_type and accepts @@ -234,14 +235,31 @@ run_build(const char *driver, const struct row *r, int i) return brc == 0 ? got : -1; } -/* build_should_fail — the build must error on `driver`; returns 0 when - * it 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 — the build must FAIL on `driver` *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). All + * rows[] reject on "not assignable" (cstage spells the types, wwstage the + * shorter "ctx: not assignable (...)"); the core is shared. */ +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/catn_%d_%d.ww", getpid(), i); snprintf(tmpdir, sizeof tmpdir, "/tmp/catn_%d_d_%d", getpid(), i); + snprintf(errf, sizeof errf, "/tmp/catn_%d_e_%d.txt", getpid(), i); FILE *f = fopen(s, "wb"); if (!f) return -1; @@ -249,11 +267,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]; @@ -262,7 +282,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; } /* -T reject faces — a user fixture is bundled with lib/test via @@ -313,12 +334,17 @@ tbundle_reject(const char *bin, const char *stage, const char *drv, fputs(t->src, f); fclose(f); + char errf[176]; + snprintf(errf, sizeof errf, "%s.err", stem); snprintf(cmd, sizeof cmd, - "WW_PKGCACHE=%s.pkgc %s/%s test --sep -o %s %s > /dev/null 2>&1", - stem, bin, drv, stem, src); + "WW_PKGCACHE=%s.pkgc %s/%s test --sep -o %s %s >/dev/null 2>%s", + stem, bin, drv, stem, src, errf); int rc = runwait(cmd); + /* Both stages emit the reservation diagnostic; a crash would not (#20). */ + int hasmsg = filehas(errf, "__wwtests is reserved by -T"); unlink(src); + unlink(errf); snprintf(cmd, sizeof cmd, "rm -rf %s %s.sepwork %s.pkgc", stem, stem, stem); if (system(cmd)) {} @@ -327,6 +353,12 @@ tbundle_reject(const char *bin, const char *stage, const char *drv, "accepted (expected a loud reject)\n", stage, t->label, drv); return -1; } + if (!hasmsg) { + fprintf(stderr, "callarg_typecheck[%s][%s]: %s test --sep " + "nonzero exit but missing reservation diagnostic (a crash, " + "not a clean reject)\n", stage, t->label, drv); + return -1; + } return 0; } @@ -375,20 +407,25 @@ multimod_build_fail(const char *drv, const char *mainbody, int withmod1, fputs(mainbody, f); fclose(f); + char errf[128]; + snprintf(errf, sizeof errf, "%s/err.txt", dir); if (withmod1) snprintf(cmd, sizeof cmd, - "cd %s && %s build -I %s -I %s main.ww >/dev/null 2>&1", - dir, drv, io2d, mod1d); + "cd %s && %s build -I %s -I %s main.ww >/dev/null 2>%s", + dir, drv, io2d, mod1d, errf); else snprintf(cmd, sizeof cmd, - "cd %s && %s build -I %s main.ww >/dev/null 2>&1", - dir, drv, io2d); + "cd %s && %s build -I %s main.ww >/dev/null 2>%s", + dir, drv, io2d, errf); int rc = runwait(cmd); + /* Both collision rows reject on "not assignable"; a crash would not (#20). */ + int hasmsg = filehas(errf, "not assignable"); snprintf(rm, sizeof rm, "rm -rf %s", dir); runwait(rm); - return rc == 0 ? -1 : 0; /* build must NOT succeed */ + /* build must NOT succeed AND must emit its diagnostic. */ + return (rc != 0 && hasmsg) ? 0 : -1; } /* a []int SLICE passed where io2.handle = (file | stream) is wanted — NO @@ -468,7 +505,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, "callarg_typecheck[%s][%s]: " "built ok, expected a loud reject\n", drivers[d].name, rows[i].label); diff --git a/test/wcc/989_catA_f2_reject.c b/test/wcc/989_catA_f2_reject.c index fc0bb6d0..8148c002 100644 --- a/test/wcc/989_catA_f2_reject.c +++ b/test/wcc/989_catA_f2_reject.c @@ -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", diff --git a/test/wcc/989_intoverflow_reject.c b/test/wcc/989_intoverflow_reject.c index b6d724ed..90a76cbf 100644 --- a/test/wcc/989_intoverflow_reject.c +++ b/test/wcc/989_intoverflow_reject.c @@ -39,6 +39,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[] = { @@ -49,7 +50,7 @@ static const struct row rows[] = { " let x: u64 = 99999999999999999999u64;\n" " return x: i32;\n" "};\n", - 0, 0 }, + 0, 0, "bad integer literal" }, /* REJECT — 65-bit hex (smallest overflow above U64_MAX). */ { "hex_overflow", @@ -58,7 +59,7 @@ static const struct row rows[] = { " let x: u64 = 0x1ffffffffffffffffu64;\n" " return x: i32;\n" "};\n", - 0, 0 }, + 0, 0, "bad integer literal" }, /* REJECT — 2^128-1 decimal, far over u64. */ { "dec_huge", @@ -67,7 +68,7 @@ static const struct row rows[] = { " let x: u64 = 340282366920938463463374607431768211455u64;\n" " return x: i32;\n" "};\n", - 0, 0 }, + 0, 0, "bad integer literal" }, /* control — U64_MAX decimal is the largest accepted literal. */ { "u64max_dec_ok", @@ -122,11 +123,30 @@ 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 + * quotes the literal ("bad integer literal '99...'"), wwstage does not; + * "bad integer literal" is the shared core. */ +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/iovn_%d_%d.ww", getpid(), i); snprintf(tmpdir, sizeof tmpdir, "/tmp/iovn_%d_d_%d", getpid(), i); + snprintf(errf, sizeof errf, "/tmp/iovn_%d_e_%d.txt", getpid(), i); FILE *f = fopen(s, "wb"); if (!f) return -1; @@ -134,11 +154,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]; @@ -147,7 +169,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 @@ -195,7 +218,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, "intoverflow_reject[%s][%s]: " "built ok, expected a loud reject\n", drivers[d].name, rows[i].label); diff --git a/test/wcc/989_tagged_subset_reject.c b/test/wcc/989_tagged_subset_reject.c index c467552e..fc877a96 100644 --- a/test/wcc/989_tagged_subset_reject.c +++ b/test/wcc/989_tagged_subset_reject.c @@ -89,6 +89,7 @@ struct row { int expect_build; /* 1 = build+run to want_exit; 0 = must FAIL */ int want_exit; /* meaningful only when expect_build */ int byteid; /* 1 = also assert w6c vs w6c_ww .s byte-id */ + const char *diag; /* expected reject diagnostic (NULL for build rows) */ }; static const struct row rows[] = { @@ -100,7 +101,7 @@ static const struct row rows[] = { "type small = (int | bool);\n" "fn f(b: big) small = { return b; };\n" "export fn main() int = { return 0; };\n", - 0, 0, 0 }, + 0, 0, 0, "not assignable" }, /* (2) D flatten-subset, union→union → ACCEPT + byte-id. * {bool,str} ⊆ {int,bool,str}; cstage flattens inner + remaps tags. */ @@ -172,7 +173,7 @@ static const struct row rows[] = { " };\n" "};\n" "export fn main() int = { return 0; };\n", - 0, 0, 0 }, + 0, 0, 0, "not a variant" }, /* (5b) spread → wider subset assign (latent) → KEEP lenient accept. * sp's src side carries a `...e1` spread → the guard keeps the @@ -221,14 +222,29 @@ run_build(const char *driver, const struct row *r, int i) return brc == 0 ? got : -1; } -/* build_should_fail — the build must error on `driver`; returns 0 when it - * 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 — the build must FAIL on `driver` *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/tsrn_%d_%d.ww", getpid(), i); snprintf(tmpdir, sizeof tmpdir, "/tmp/tsrn_%d_d_%d", getpid(), i); + snprintf(errf, sizeof errf, "/tmp/tsrn_%d_e_%d.txt", getpid(), i); FILE *f = fopen(s, "wb"); if (!f) return -1; @@ -236,11 +252,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]; @@ -249,7 +267,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. */ @@ -314,6 +333,7 @@ struct xrow { const char *msrc; /* package main; import e */ int expect_build; /* 1 = build+run to want_exit; 0 = must FAIL */ int want_exit; + const char *rejdiag; /* expected reject diagnostic (NULL for build rows) */ }; static const struct xrow xrows[] = { @@ -345,7 +365,7 @@ static const struct xrow xrows[] = { "type myres = (i64 | e.done);\n" "fn forward() myres = { return e.next(); };\n" "export fn main() i32 = { return 0; };\n", - 0, 0 }, + 0, 0, "not assignable" }, }; /* run_xmod — write e.ww + main.ww into a fresh dir, `ww build -I dir @@ -371,19 +391,26 @@ run_xmod(const char *driver, const struct xrow *x) return -2; } + char errf[1056]; + snprintf(errf, sizeof errf, "%s/err.txt", dir); snprintf(cmd, sizeof cmd, "cd %s && %s build -I %s %s/main.ww " - "2>/dev/null", dir, driver, dir, dir); + ">/dev/null 2>%s", dir, driver, dir, dir, errf); int brc = runwait(cmd); int got = -1; if (brc == 0) { snprintf(path, sizeof path, "%s/main", dir); got = runwait(path); + } else if (x->rejdiag && !filehas(errf, x->rejdiag)) { + /* A REJECT row whose build failed WITHOUT its diagnostic is a + * crash, not a clean reject — return a non-(-1) sentinel so the + * caller (which expects -1 on a clean reject) flags it (#20). */ + got = -3; } snprintf(cmd, sizeof cmd, "rm -rf %s", dir); (void)runwait(cmd); - return brc == 0 ? got : -1; + return got; } int @@ -434,7 +461,7 @@ main(void) } } else { if (build_should_fail(drivers[d].path, - rows[i].src, 100 + i) != 0) { + rows[i].src, rows[i].diag, 100 + i) != 0) { fprintf(stderr, "tagged_subset_reject[%s][%s]: " "built ok, expected a loud reject\n", diff --git a/test/wcc/989_unknowndecl_reject.c b/test/wcc/989_unknowndecl_reject.c index 9533c79f..fe4397e9 100644 --- a/test/wcc/989_unknowndecl_reject.c +++ b/test/wcc/989_unknowndecl_reject.c @@ -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);