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:
@@ -12,6 +12,7 @@
|
|||||||
*/
|
*/
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <sys/wait.h>
|
#include <sys/wait.h>
|
||||||
|
|
||||||
@@ -34,17 +35,41 @@ write_file(const char *path, const char *content)
|
|||||||
return 0;
|
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
|
static int
|
||||||
check_fail(const char *tool, const char *src)
|
check_fail(const char *tool, const char *src)
|
||||||
{
|
{
|
||||||
char cmd[4096];
|
char cmd[4096], errf[64];
|
||||||
snprintf(cmd, sizeof cmd, "%s %s >/dev/null 2>/dev/null", tool, src);
|
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 rc = runwait(cmd);
|
||||||
|
int hasmsg = filehas(errf, "expected identifier");
|
||||||
|
unlink(errf);
|
||||||
if (rc == 0) {
|
if (rc == 0) {
|
||||||
fprintf(stderr, "742 FAIL: %s exited 0 on parse-error fixture\n",
|
fprintf(stderr, "742 FAIL: %s exited 0 on parse-error fixture\n",
|
||||||
tool);
|
tool);
|
||||||
return -1;
|
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;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -158,6 +158,12 @@ static const char *neg[] = {
|
|||||||
"export fn main() i32 = { return 0; };\n",
|
"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
|
static int
|
||||||
run_driver(const char *driver, const struct row *r, int i)
|
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;
|
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
|
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(s, sizeof s, "/tmp/dailn_%d_%d.ww", getpid(), i);
|
||||||
snprintf(tmpdir, sizeof tmpdir, "/tmp/dailn_%d_d_%d", 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");
|
FILE *f = fopen(s, "wb");
|
||||||
if (!f) return -1;
|
if (!f) return -1;
|
||||||
@@ -208,10 +229,12 @@ build_should_fail(const char *driver, const char *src, int i)
|
|||||||
fclose(f);
|
fclose(f);
|
||||||
|
|
||||||
mkdir(tmpdir, 0755);
|
mkdir(tmpdir, 0755);
|
||||||
snprintf(cmd, sizeof cmd, "cd %s && %s build %s 2>/dev/null",
|
snprintf(cmd, sizeof cmd, "cd %s && %s build %s >/dev/null 2>%s",
|
||||||
tmpdir, driver, s);
|
tmpdir, driver, s, errf);
|
||||||
int rc = runwait(cmd);
|
int rc = runwait(cmd);
|
||||||
|
int hasmsg = filehas(errf, diag);
|
||||||
unlink(s);
|
unlink(s);
|
||||||
|
unlink(errf);
|
||||||
/* clean any emitted binary */
|
/* clean any emitted binary */
|
||||||
const char *base = strrchr(s, '/');
|
const char *base = strrchr(s, '/');
|
||||||
base = base ? base + 1 : 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';
|
if (dot && strcmp(dot, ".ww") == 0) *dot = '\0';
|
||||||
unlink(outbin);
|
unlink(outbin);
|
||||||
rmdir(tmpdir);
|
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.
|
/* 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++) {
|
for (int i = 0; i < nn; i++) {
|
||||||
total++;
|
total++;
|
||||||
if (build_should_fail(drivers[d].path, neg[i],
|
if (build_should_fail(drivers[d].path, neg[i],
|
||||||
100 + i) != 0) {
|
neg_diag[i], 100 + i) != 0) {
|
||||||
fprintf(stderr,
|
fprintf(stderr,
|
||||||
"def_arr_infer_len[%s][neg%d]: built ok, "
|
"def_arr_infer_len[%s][neg%d]: built ok, "
|
||||||
"expected a loud error\n",
|
"expected a loud error\n",
|
||||||
|
|||||||
@@ -121,6 +121,15 @@ static const char *neg[] = {
|
|||||||
"};\n",
|
"};\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
|
static int
|
||||||
run_driver(const char *driver, const struct row *r, int i)
|
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;
|
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
|
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(s, sizeof s, "/tmp/acrn_%d_%d.ww", getpid(), i);
|
||||||
snprintf(tmpdir, sizeof tmpdir, "/tmp/acrn_%d_d_%d", 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");
|
FILE *f = fopen(s, "wb");
|
||||||
if (!f) return -1;
|
if (!f) return -1;
|
||||||
@@ -170,10 +195,12 @@ build_should_fail(const char *driver, const char *src, int i)
|
|||||||
fclose(f);
|
fclose(f);
|
||||||
|
|
||||||
mkdir(tmpdir, 0755);
|
mkdir(tmpdir, 0755);
|
||||||
snprintf(cmd, sizeof cmd, "cd %s && %s build %s 2>/dev/null",
|
snprintf(cmd, sizeof cmd, "cd %s && %s build %s >/dev/null 2>%s",
|
||||||
tmpdir, driver, s);
|
tmpdir, driver, s, errf);
|
||||||
int rc = runwait(cmd);
|
int rc = runwait(cmd);
|
||||||
|
int hasmsg = filehas(errf, diag);
|
||||||
unlink(s);
|
unlink(s);
|
||||||
|
unlink(errf);
|
||||||
/* clean any emitted binary */
|
/* clean any emitted binary */
|
||||||
const char *base = strrchr(s, '/');
|
const char *base = strrchr(s, '/');
|
||||||
base = base ? base + 1 : 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';
|
if (dot && strcmp(dot, ".ww") == 0) *dot = '\0';
|
||||||
unlink(outbin);
|
unlink(outbin);
|
||||||
rmdir(tmpdir);
|
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. */
|
/* 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++) {
|
for (int i = 0; i < nn; i++) {
|
||||||
total++;
|
total++;
|
||||||
if (build_should_fail(drivers[d].path, neg[i],
|
if (build_should_fail(drivers[d].path, neg[i],
|
||||||
100 + i) != 0) {
|
neg_diag[i], 100 + i) != 0) {
|
||||||
fprintf(stderr,
|
fprintf(stderr,
|
||||||
"arr_cap_reject[%s][neg%d]: built ok, "
|
"arr_cap_reject[%s][neg%d]: built ok, "
|
||||||
"expected a loud error\n",
|
"expected a loud error\n",
|
||||||
|
|||||||
@@ -141,6 +141,13 @@ static const char *neg[] = {
|
|||||||
"};\n",
|
"};\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
|
static int
|
||||||
run_driver(const char *driver, const struct row *r, int i)
|
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;
|
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
|
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(s, sizeof s, "/tmp/dsin_%d_%d.ww", getpid(), i);
|
||||||
snprintf(tmpdir, sizeof tmpdir, "/tmp/dsin_%d_d_%d", 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");
|
FILE *f = fopen(s, "wb");
|
||||||
if (!f) return -1;
|
if (!f) return -1;
|
||||||
@@ -191,10 +213,12 @@ build_should_fail(const char *driver, const char *src, int i)
|
|||||||
fclose(f);
|
fclose(f);
|
||||||
|
|
||||||
mkdir(tmpdir, 0755);
|
mkdir(tmpdir, 0755);
|
||||||
snprintf(cmd, sizeof cmd, "cd %s && %s build %s 2>/dev/null",
|
snprintf(cmd, sizeof cmd, "cd %s && %s build %s >/dev/null 2>%s",
|
||||||
tmpdir, driver, s);
|
tmpdir, driver, s, errf);
|
||||||
int rc = runwait(cmd);
|
int rc = runwait(cmd);
|
||||||
|
int hasmsg = filehas(errf, diag);
|
||||||
unlink(s);
|
unlink(s);
|
||||||
|
unlink(errf);
|
||||||
/* clean any emitted binary */
|
/* clean any emitted binary */
|
||||||
const char *base = strrchr(s, '/');
|
const char *base = strrchr(s, '/');
|
||||||
base = base ? base + 1 : 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';
|
if (dot && strcmp(dot, ".ww") == 0) *dot = '\0';
|
||||||
unlink(outbin);
|
unlink(outbin);
|
||||||
rmdir(tmpdir);
|
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. */
|
/* 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++) {
|
for (int i = 0; i < nn; i++) {
|
||||||
total++;
|
total++;
|
||||||
if (build_should_fail(drivers[d].path, neg[i],
|
if (build_should_fail(drivers[d].path, neg[i],
|
||||||
100 + i) != 0) {
|
neg_diag[i], 100 + i) != 0) {
|
||||||
fprintf(stderr,
|
fprintf(stderr,
|
||||||
"def_str_index_reject[%s][neg%d]: built ok, "
|
"def_str_index_reject[%s][neg%d]: built ok, "
|
||||||
"expected a loud error\n",
|
"expected a loud error\n",
|
||||||
|
|||||||
@@ -62,17 +62,32 @@ runwait(const char *cmd)
|
|||||||
return -1;
|
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`
|
/* build_should_fail — a dup-`main` program must error on `driver`
|
||||||
* (loud reject); returns 0 when the build correctly FAILS, non-zero
|
* (loud reject); returns 0 when the build FAILS *and* emits `diag`.
|
||||||
* when it wrongly succeeded. Intermediates land in tmpdir, never the
|
* This test drives the full `ww` driver, so a crash inside w6c also
|
||||||
* source tree (rule 14). */
|
* 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
|
static int
|
||||||
build_should_fail(const char *driver, const char *label, const char *src,
|
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(s, sizeof s, "/tmp/dupmain_%d_%d.ww", getpid(), i);
|
||||||
snprintf(tmpdir, sizeof tmpdir, "/tmp/dupmain_%d_d_%d", 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");
|
FILE *f = fopen(s, "wb");
|
||||||
if (!f) return -1;
|
if (!f) return -1;
|
||||||
@@ -80,9 +95,10 @@ build_should_fail(const char *driver, const char *label, const char *src,
|
|||||||
fclose(f);
|
fclose(f);
|
||||||
|
|
||||||
mkdir(tmpdir, 0755);
|
mkdir(tmpdir, 0755);
|
||||||
snprintf(cmd, sizeof cmd, "cd %s && %s build %s 2>/dev/null",
|
snprintf(cmd, sizeof cmd, "cd %s && %s build %s >/dev/null 2>%s",
|
||||||
tmpdir, driver, s);
|
tmpdir, driver, s, errf);
|
||||||
int rc = runwait(cmd);
|
int rc = runwait(cmd);
|
||||||
|
int hasmsg = filehas(errf, diag);
|
||||||
|
|
||||||
const char *base = strrchr(s, '/');
|
const char *base = strrchr(s, '/');
|
||||||
base = base ? base + 1 : 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, '.');
|
char *dot = strrchr(outbin, '.');
|
||||||
if (dot && strcmp(dot, ".ww") == 0) *dot = '\0';
|
if (dot && strcmp(dot, ".ww") == 0) *dot = '\0';
|
||||||
unlink(s);
|
unlink(s);
|
||||||
|
unlink(errf);
|
||||||
unlink(outbin);
|
unlink(outbin);
|
||||||
rmdir(tmpdir);
|
rmdir(tmpdir);
|
||||||
if (rc == 0)
|
if (rc == 0) {
|
||||||
fprintf(stderr,
|
fprintf(stderr,
|
||||||
"dup_main[%s][%s]: built ok, expected a loud reject\n",
|
"dup_main[%s][%s]: built ok, expected a loud reject\n",
|
||||||
driver, label);
|
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
|
/* 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;
|
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)
|
/* Each program declares a second top-level `main` (in package foo)
|
||||||
* alongside the entry `fn main` (in package main), bound by a REAL
|
* 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"
|
"export fn anchor() i32 = { return main; };\n"
|
||||||
"package main;\n"
|
"package main;\n"
|
||||||
"import foo;\n"
|
"import foo;\n"
|
||||||
"fn main() i32 = { return foo.anchor(); };\n" },
|
"fn main() i32 = { return foo.anchor(); };\n",
|
||||||
|
"duplicate entry main" },
|
||||||
|
|
||||||
{ "fn_main",
|
{ "fn_main",
|
||||||
"package foo;\n"
|
"package foo;\n"
|
||||||
@@ -158,7 +184,8 @@ static const struct rejrow reject_rows[] = {
|
|||||||
"export fn anchor() i32 = { return 2; };\n"
|
"export fn anchor() i32 = { return 2; };\n"
|
||||||
"package main;\n"
|
"package main;\n"
|
||||||
"import foo;\n"
|
"import foo;\n"
|
||||||
"fn main() i32 = { return foo.anchor(); };\n" },
|
"fn main() i32 = { return foo.anchor(); };\n",
|
||||||
|
"duplicate entry main" },
|
||||||
|
|
||||||
{ "def_main",
|
{ "def_main",
|
||||||
"package foo;\n"
|
"package foo;\n"
|
||||||
@@ -166,7 +193,8 @@ static const struct rejrow reject_rows[] = {
|
|||||||
"export fn anchor() i32 = { return main; };\n"
|
"export fn anchor() i32 = { return main; };\n"
|
||||||
"package main;\n"
|
"package main;\n"
|
||||||
"import foo;\n"
|
"import foo;\n"
|
||||||
"fn main() i32 = { return foo.anchor(); };\n" },
|
"fn main() i32 = { return foo.anchor(); };\n",
|
||||||
|
"duplicate entry main" },
|
||||||
|
|
||||||
{ "type_main",
|
{ "type_main",
|
||||||
"package foo;\n"
|
"package foo;\n"
|
||||||
@@ -174,7 +202,8 @@ static const struct rejrow reject_rows[] = {
|
|||||||
"export fn anchor() i32 = { return 3; };\n"
|
"export fn anchor() i32 = { return 3; };\n"
|
||||||
"package main;\n"
|
"package main;\n"
|
||||||
"import foo;\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; };
|
struct okrow { const char *label; const char *src; int want; };
|
||||||
@@ -225,7 +254,7 @@ main(void)
|
|||||||
total++;
|
total++;
|
||||||
if (build_should_fail(drivers[d].path,
|
if (build_should_fail(drivers[d].path,
|
||||||
reject_rows[i].label, reject_rows[i].src,
|
reject_rows[i].label, reject_rows[i].src,
|
||||||
d * 100 + i) != 0)
|
reject_rows[i].diag, d * 100 + i) != 0)
|
||||||
fail++;
|
fail++;
|
||||||
}
|
}
|
||||||
for (int i = 0; i < nok; i++) {
|
for (int i = 0; i < nok; i++) {
|
||||||
|
|||||||
@@ -50,30 +50,59 @@ outbin(char *dst, size_t n, const char *tmpdir, const char *src)
|
|||||||
if (dot && strcmp(dot, ".ww") == 0) *dot = '\0';
|
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
|
static int
|
||||||
build_should_fail(const char *driver, const char *label, const char *src,
|
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(s, sizeof s, "/tmp/tuptc_%d_%d.ww", getpid(), i);
|
||||||
snprintf(tmpdir, sizeof tmpdir, "/tmp/tuptc_%d_d_%d", 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");
|
FILE *f = fopen(s, "wb");
|
||||||
if (!f) return -1;
|
if (!f) return -1;
|
||||||
fputs(src, f);
|
fputs(src, f);
|
||||||
fclose(f);
|
fclose(f);
|
||||||
mkdir(tmpdir, 0755);
|
mkdir(tmpdir, 0755);
|
||||||
snprintf(cmd, sizeof cmd, "cd %s && %s build %s 2>/dev/null",
|
snprintf(cmd, sizeof cmd, "cd %s && %s build %s >/dev/null 2>%s",
|
||||||
tmpdir, driver, s);
|
tmpdir, driver, s, errf);
|
||||||
int rc = runwait(cmd);
|
int rc = runwait(cmd);
|
||||||
|
int hasmsg = filehas(errf, diag);
|
||||||
outbin(bin, sizeof bin, tmpdir, s);
|
outbin(bin, sizeof bin, tmpdir, s);
|
||||||
unlink(s);
|
unlink(s);
|
||||||
unlink(bin);
|
unlink(bin);
|
||||||
|
unlink(errf);
|
||||||
rmdir(tmpdir);
|
rmdir(tmpdir);
|
||||||
if (rc == 0)
|
if (rc == 0) {
|
||||||
fprintf(stderr, "tuptc[%s][%s]: built ok, expected a reject\n",
|
fprintf(stderr, "tuptc[%s][%s]: built ok, expected a reject\n",
|
||||||
driver, label);
|
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. */
|
/* 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;
|
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[] = {
|
static const struct rejrow reject_rows[] = {
|
||||||
{ "one_comma",
|
{ "one_comma",
|
||||||
"package main;\n"
|
"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; };
|
struct okrow { const char *label; const char *src; int want; };
|
||||||
@@ -161,7 +196,8 @@ main(void)
|
|||||||
total++;
|
total++;
|
||||||
if (build_should_fail(drivers[d].path,
|
if (build_should_fail(drivers[d].path,
|
||||||
reject_rows[i].label, reject_rows[i].src,
|
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++;
|
fail++;
|
||||||
}
|
}
|
||||||
for (int i = 0; i < nok; i++) {
|
for (int i = 0; i < nok; i++) {
|
||||||
|
|||||||
@@ -45,28 +45,56 @@ outbin(char *dst, size_t n, const char *tmpdir, const char *src)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
build_should_fail(const char *driver, const char *label, const char *src,
|
filehas(const char *path, const char *needle)
|
||||||
int i)
|
|
||||||
{
|
{
|
||||||
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(s, sizeof s, "/tmp/vret_%d_%d.ww", getpid(), i);
|
||||||
snprintf(tmpdir, sizeof tmpdir, "/tmp/vret_%d_d_%d", 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");
|
FILE *f = fopen(s, "wb");
|
||||||
if (!f) return -1;
|
if (!f) return -1;
|
||||||
fputs(src, f);
|
fputs(src, f);
|
||||||
fclose(f);
|
fclose(f);
|
||||||
mkdir(tmpdir, 0755);
|
mkdir(tmpdir, 0755);
|
||||||
snprintf(cmd, sizeof cmd, "cd %s && %s build %s 2>/dev/null",
|
snprintf(cmd, sizeof cmd, "cd %s && %s build %s >/dev/null 2>%s",
|
||||||
tmpdir, driver, s);
|
tmpdir, driver, s, errf);
|
||||||
int rc = runwait(cmd);
|
int rc = runwait(cmd);
|
||||||
|
int hasmsg = filehas(errf, diag);
|
||||||
outbin(bin, sizeof bin, tmpdir, s);
|
outbin(bin, sizeof bin, tmpdir, s);
|
||||||
unlink(s);
|
unlink(s);
|
||||||
unlink(bin);
|
unlink(bin);
|
||||||
|
unlink(errf);
|
||||||
rmdir(tmpdir);
|
rmdir(tmpdir);
|
||||||
if (rc == 0)
|
if (rc == 0) {
|
||||||
fprintf(stderr, "vret[%s][%s]: built ok, expected a reject\n",
|
fprintf(stderr, "vret[%s][%s]: built ok, expected a reject\n",
|
||||||
driver, label);
|
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
|
static int
|
||||||
@@ -94,13 +122,14 @@ run_build(const char *driver, const char *label, const char *src, int i)
|
|||||||
return got;
|
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[] = {
|
static const struct rejrow reject_rows[] = {
|
||||||
{ "nonvoid",
|
{ "nonvoid",
|
||||||
"package main;\n"
|
"package main;\n"
|
||||||
"fn f() i32 = { return; };\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; };
|
struct okrow { const char *label; const char *src; int want; };
|
||||||
@@ -160,7 +189,7 @@ main(void)
|
|||||||
total++;
|
total++;
|
||||||
if (build_should_fail(drivers[d].path,
|
if (build_should_fail(drivers[d].path,
|
||||||
reject_rows[i].label, reject_rows[i].src,
|
reject_rows[i].label, reject_rows[i].src,
|
||||||
d * 100 + i) != 0)
|
reject_rows[i].diag, d * 100 + i) != 0)
|
||||||
fail++;
|
fail++;
|
||||||
}
|
}
|
||||||
for (int i = 0; i < nok; i++) {
|
for (int i = 0; i < nok; i++) {
|
||||||
|
|||||||
@@ -46,28 +46,56 @@ outbin(char *dst, size_t n, const char *tmpdir, const char *src)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
build_should_fail(const char *driver, const char *label, const char *src,
|
filehas(const char *path, const char *needle)
|
||||||
int i)
|
|
||||||
{
|
{
|
||||||
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(s, sizeof s, "/tmp/creas_%d_%d.ww", getpid(), i);
|
||||||
snprintf(tmpdir, sizeof tmpdir, "/tmp/creas_%d_d_%d", 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");
|
FILE *f = fopen(s, "wb");
|
||||||
if (!f) return -1;
|
if (!f) return -1;
|
||||||
fputs(src, f);
|
fputs(src, f);
|
||||||
fclose(f);
|
fclose(f);
|
||||||
mkdir(tmpdir, 0755);
|
mkdir(tmpdir, 0755);
|
||||||
snprintf(cmd, sizeof cmd, "cd %s && %s build %s 2>/dev/null",
|
snprintf(cmd, sizeof cmd, "cd %s && %s build %s >/dev/null 2>%s",
|
||||||
tmpdir, driver, s);
|
tmpdir, driver, s, errf);
|
||||||
int rc = runwait(cmd);
|
int rc = runwait(cmd);
|
||||||
|
int hasmsg = filehas(errf, diag);
|
||||||
outbin(bin, sizeof bin, tmpdir, s);
|
outbin(bin, sizeof bin, tmpdir, s);
|
||||||
unlink(s);
|
unlink(s);
|
||||||
unlink(bin);
|
unlink(bin);
|
||||||
|
unlink(errf);
|
||||||
rmdir(tmpdir);
|
rmdir(tmpdir);
|
||||||
if (rc == 0)
|
if (rc == 0) {
|
||||||
fprintf(stderr, "creas[%s][%s]: built ok, expected a reject\n",
|
fprintf(stderr, "creas[%s][%s]: built ok, expected a reject\n",
|
||||||
driver, label);
|
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
|
static int
|
||||||
@@ -95,12 +123,13 @@ run_build(const char *driver, const char *label, const char *src, int i)
|
|||||||
return got;
|
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[] = {
|
static const struct rejrow reject_rows[] = {
|
||||||
{ "const_set",
|
{ "const_set",
|
||||||
"package main;\n"
|
"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; };
|
struct okrow { const char *label; const char *src; int want; };
|
||||||
@@ -148,7 +177,7 @@ main(void)
|
|||||||
total++;
|
total++;
|
||||||
if (build_should_fail(drivers[d].path,
|
if (build_should_fail(drivers[d].path,
|
||||||
reject_rows[i].label, reject_rows[i].src,
|
reject_rows[i].label, reject_rows[i].src,
|
||||||
d * 100 + i) != 0)
|
reject_rows[i].diag, d * 100 + i) != 0)
|
||||||
fail++;
|
fail++;
|
||||||
}
|
}
|
||||||
for (int i = 0; i < nok; i++) {
|
for (int i = 0; i < nok; i++) {
|
||||||
|
|||||||
@@ -49,28 +49,54 @@ outbin(char *dst, size_t n, const char *tmpdir, const char *src)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
build_should_fail(const char *driver, const char *label, const char *src,
|
filehas(const char *path, const char *needle)
|
||||||
int i)
|
|
||||||
{
|
{
|
||||||
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(s, sizeof s, "/tmp/dupf_%d_%d.ww", getpid(), i);
|
||||||
snprintf(tmpdir, sizeof tmpdir, "/tmp/dupf_%d_d_%d", 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");
|
FILE *f = fopen(s, "wb");
|
||||||
if (!f) return -1;
|
if (!f) return -1;
|
||||||
fputs(src, f);
|
fputs(src, f);
|
||||||
fclose(f);
|
fclose(f);
|
||||||
mkdir(tmpdir, 0755);
|
mkdir(tmpdir, 0755);
|
||||||
snprintf(cmd, sizeof cmd, "cd %s && %s build %s 2>/dev/null",
|
snprintf(cmd, sizeof cmd, "cd %s && %s build %s >/dev/null 2>%s",
|
||||||
tmpdir, driver, s);
|
tmpdir, driver, s, errf);
|
||||||
int rc = runwait(cmd);
|
int rc = runwait(cmd);
|
||||||
|
int hasmsg = filehas(errf, diag);
|
||||||
outbin(bin, sizeof bin, tmpdir, s);
|
outbin(bin, sizeof bin, tmpdir, s);
|
||||||
unlink(s);
|
unlink(s);
|
||||||
unlink(bin);
|
unlink(bin);
|
||||||
|
unlink(errf);
|
||||||
rmdir(tmpdir);
|
rmdir(tmpdir);
|
||||||
if (rc == 0)
|
if (rc == 0) {
|
||||||
fprintf(stderr, "dupf[%s][%s]: built ok, expected a reject\n",
|
fprintf(stderr, "dupf[%s][%s]: built ok, expected a reject\n",
|
||||||
driver, label);
|
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
|
static int
|
||||||
@@ -98,21 +124,24 @@ run_build(const char *driver, const char *label, const char *src, int i)
|
|||||||
return got;
|
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[] = {
|
static const struct rejrow reject_rows[] = {
|
||||||
{ "adj_dup",
|
{ "adj_dup",
|
||||||
"package main;\n"
|
"package main;\n"
|
||||||
"type d = struct { a: i32, a: i32 };\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",
|
{ "nonadj_dup",
|
||||||
"package main;\n"
|
"package main;\n"
|
||||||
"type d = struct { a: i32, b: i32, a: i32 };\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",
|
{ "dup_difftype",
|
||||||
"package main;\n"
|
"package main;\n"
|
||||||
"type d = struct { a: i32, a: bool };\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; };
|
struct okrow { const char *label; const char *src; int want; };
|
||||||
@@ -162,7 +191,7 @@ main(void)
|
|||||||
total++;
|
total++;
|
||||||
if (build_should_fail(drivers[d].path,
|
if (build_should_fail(drivers[d].path,
|
||||||
reject_rows[i].label, reject_rows[i].src,
|
reject_rows[i].label, reject_rows[i].src,
|
||||||
d * 100 + i) != 0)
|
reject_rows[i].diag, d * 100 + i) != 0)
|
||||||
fail++;
|
fail++;
|
||||||
}
|
}
|
||||||
for (int i = 0; i < nok; i++) {
|
for (int i = 0; i < nok; i++) {
|
||||||
|
|||||||
@@ -51,28 +51,54 @@ outbin(char *dst, size_t n, const char *tmpdir, const char *src)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
build_should_fail(const char *driver, const char *label, const char *src,
|
filehas(const char *path, const char *needle)
|
||||||
int i)
|
|
||||||
{
|
{
|
||||||
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(s, sizeof s, "/tmp/enr_%d_%d.ww", getpid(), i);
|
||||||
snprintf(tmpdir, sizeof tmpdir, "/tmp/enr_%d_d_%d", 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");
|
FILE *f = fopen(s, "wb");
|
||||||
if (!f) return -1;
|
if (!f) return -1;
|
||||||
fputs(src, f);
|
fputs(src, f);
|
||||||
fclose(f);
|
fclose(f);
|
||||||
mkdir(tmpdir, 0755);
|
mkdir(tmpdir, 0755);
|
||||||
snprintf(cmd, sizeof cmd, "cd %s && %s build %s 2>/dev/null",
|
snprintf(cmd, sizeof cmd, "cd %s && %s build %s >/dev/null 2>%s",
|
||||||
tmpdir, driver, s);
|
tmpdir, driver, s, errf);
|
||||||
int rc = runwait(cmd);
|
int rc = runwait(cmd);
|
||||||
|
int hasmsg = filehas(errf, diag);
|
||||||
outbin(bin, sizeof bin, tmpdir, s);
|
outbin(bin, sizeof bin, tmpdir, s);
|
||||||
unlink(s);
|
unlink(s);
|
||||||
unlink(bin);
|
unlink(bin);
|
||||||
|
unlink(errf);
|
||||||
rmdir(tmpdir);
|
rmdir(tmpdir);
|
||||||
if (rc == 0)
|
if (rc == 0) {
|
||||||
fprintf(stderr, "enr[%s][%s]: built ok, expected a reject\n",
|
fprintf(stderr, "enr[%s][%s]: built ok, expected a reject\n",
|
||||||
driver, label);
|
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
|
static int
|
||||||
@@ -100,21 +126,28 @@ run_build(const char *driver, const char *label, const char *src, int i)
|
|||||||
return got;
|
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[] = {
|
static const struct rejrow reject_rows[] = {
|
||||||
{ "nonint_stor",
|
{ "nonint_stor",
|
||||||
"package main;\n"
|
"package main;\n"
|
||||||
"type e = enum f64 { A };\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",
|
{ "dup_member",
|
||||||
"package main;\n"
|
"package main;\n"
|
||||||
"type e = enum { A, B, A };\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",
|
{ "fwd_ref",
|
||||||
"package main;\n"
|
"package main;\n"
|
||||||
"type e = enum { A = B, B };\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; };
|
struct okrow { const char *label; const char *src; int want; };
|
||||||
@@ -164,7 +197,7 @@ main(void)
|
|||||||
total++;
|
total++;
|
||||||
if (build_should_fail(drivers[d].path,
|
if (build_should_fail(drivers[d].path,
|
||||||
reject_rows[i].label, reject_rows[i].src,
|
reject_rows[i].label, reject_rows[i].src,
|
||||||
d * 100 + i) != 0)
|
reject_rows[i].diag, d * 100 + i) != 0)
|
||||||
fail++;
|
fail++;
|
||||||
}
|
}
|
||||||
for (int i = 0; i < nok; i++) {
|
for (int i = 0; i < nok; i++) {
|
||||||
|
|||||||
@@ -60,28 +60,54 @@ outbin(char *dst, size_t n, const char *tmpdir, const char *src)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
build_should_fail(const char *driver, const char *label, const char *src,
|
filehas(const char *path, const char *needle)
|
||||||
int i)
|
|
||||||
{
|
{
|
||||||
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(s, sizeof s, "/tmp/idxr_%d_%d.ww", getpid(), i);
|
||||||
snprintf(tmpdir, sizeof tmpdir, "/tmp/idxr_%d_d_%d", 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");
|
FILE *f = fopen(s, "wb");
|
||||||
if (!f) return -1;
|
if (!f) return -1;
|
||||||
fputs(src, f);
|
fputs(src, f);
|
||||||
fclose(f);
|
fclose(f);
|
||||||
mkdir(tmpdir, 0755);
|
mkdir(tmpdir, 0755);
|
||||||
snprintf(cmd, sizeof cmd, "cd %s && %s build %s 2>/dev/null",
|
snprintf(cmd, sizeof cmd, "cd %s && %s build %s >/dev/null 2>%s",
|
||||||
tmpdir, driver, s);
|
tmpdir, driver, s, errf);
|
||||||
int rc = runwait(cmd);
|
int rc = runwait(cmd);
|
||||||
|
int hasmsg = filehas(errf, diag);
|
||||||
outbin(bin, sizeof bin, tmpdir, s);
|
outbin(bin, sizeof bin, tmpdir, s);
|
||||||
unlink(s);
|
unlink(s);
|
||||||
unlink(bin);
|
unlink(bin);
|
||||||
|
unlink(errf);
|
||||||
rmdir(tmpdir);
|
rmdir(tmpdir);
|
||||||
if (rc == 0)
|
if (rc == 0) {
|
||||||
fprintf(stderr, "idxr[%s][%s]: built ok, expected a reject\n",
|
fprintf(stderr, "idxr[%s][%s]: built ok, expected a reject\n",
|
||||||
driver, label);
|
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
|
static int
|
||||||
@@ -109,7 +135,7 @@ run_build(const char *driver, const char *label, const char *src, int i)
|
|||||||
return got;
|
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[] = {
|
static const struct rejrow reject_rows[] = {
|
||||||
{ "by_float",
|
{ "by_float",
|
||||||
@@ -118,28 +144,32 @@ static const struct rejrow reject_rows[] = {
|
|||||||
" let a: [3]i32 = [10i32, 20i32, 30i32];\n"
|
" let a: [3]i32 = [10i32, 20i32, 30i32];\n"
|
||||||
" let f: f64 = 1.0;\n"
|
" let f: f64 = 1.0;\n"
|
||||||
" return a[f];\n"
|
" return a[f];\n"
|
||||||
"};\n" },
|
"};\n",
|
||||||
|
"index must be integer" },
|
||||||
{ "by_str",
|
{ "by_str",
|
||||||
"package main;\n"
|
"package main;\n"
|
||||||
"fn main() i32 = {\n"
|
"fn main() i32 = {\n"
|
||||||
" let a: [3]i32 = [10i32, 20i32, 30i32];\n"
|
" let a: [3]i32 = [10i32, 20i32, 30i32];\n"
|
||||||
" let s: str = \"x\";\n"
|
" let s: str = \"x\";\n"
|
||||||
" return a[s];\n"
|
" return a[s];\n"
|
||||||
"};\n" },
|
"};\n",
|
||||||
|
"index must be integer" },
|
||||||
{ "by_ptr",
|
{ "by_ptr",
|
||||||
"package main;\n"
|
"package main;\n"
|
||||||
"fn main() i32 = {\n"
|
"fn main() i32 = {\n"
|
||||||
" let a: [3]i32 = [10i32, 20i32, 30i32];\n"
|
" let a: [3]i32 = [10i32, 20i32, 30i32];\n"
|
||||||
" let p: *i32 = nil;\n"
|
" let p: *i32 = nil;\n"
|
||||||
" return a[p];\n"
|
" return a[p];\n"
|
||||||
"};\n" },
|
"};\n",
|
||||||
|
"index must be integer" },
|
||||||
{ "by_bool",
|
{ "by_bool",
|
||||||
"package main;\n"
|
"package main;\n"
|
||||||
"fn main() i32 = {\n"
|
"fn main() i32 = {\n"
|
||||||
" let a: [3]i32 = [10i32, 20i32, 30i32];\n"
|
" let a: [3]i32 = [10i32, 20i32, 30i32];\n"
|
||||||
" let b: bool = true;\n"
|
" let b: bool = true;\n"
|
||||||
" return a[b];\n"
|
" return a[b];\n"
|
||||||
"};\n" },
|
"};\n",
|
||||||
|
"index must be integer" },
|
||||||
};
|
};
|
||||||
|
|
||||||
struct okrow { const char *label; const char *src; int want; };
|
struct okrow { const char *label; const char *src; int want; };
|
||||||
@@ -217,7 +247,7 @@ main(void)
|
|||||||
total++;
|
total++;
|
||||||
if (build_should_fail(drivers[d].path,
|
if (build_should_fail(drivers[d].path,
|
||||||
reject_rows[i].label, reject_rows[i].src,
|
reject_rows[i].label, reject_rows[i].src,
|
||||||
d * 100 + i) != 0)
|
reject_rows[i].diag, d * 100 + i) != 0)
|
||||||
fail++;
|
fail++;
|
||||||
}
|
}
|
||||||
for (int i = 0; i < nok; i++) {
|
for (int i = 0; i < nok; i++) {
|
||||||
|
|||||||
@@ -68,6 +68,7 @@ struct row {
|
|||||||
const char *src;
|
const char *src;
|
||||||
int expect_build; /* 1 = build+run to want_exit; 0 = must FAIL */
|
int expect_build; /* 1 = build+run to want_exit; 0 = must FAIL */
|
||||||
int want_exit; /* meaningful only when expect_build */
|
int want_exit; /* meaningful only when expect_build */
|
||||||
|
const char *diag; /* expected reject diagnostic (NULL for build rows) */
|
||||||
};
|
};
|
||||||
|
|
||||||
static const struct row rows[] = {
|
static const struct row rows[] = {
|
||||||
@@ -81,7 +82,7 @@ static const struct row rows[] = {
|
|||||||
" takesslice(n);\n"
|
" takesslice(n);\n"
|
||||||
" return 0;\n"
|
" return 0;\n"
|
||||||
"};\n",
|
"};\n",
|
||||||
0, 0 },
|
0, 0, "not assignable" },
|
||||||
|
|
||||||
/* (2) str where int is wanted → REJECT both stages. A second scalar
|
/* (2) str where int is wanted → REJECT both stages. A second scalar
|
||||||
* shape: the general check is not array-specific. */
|
* shape: the general check is not array-specific. */
|
||||||
@@ -93,7 +94,7 @@ static const struct row rows[] = {
|
|||||||
" takesint(s);\n"
|
" takesint(s);\n"
|
||||||
" return 0;\n"
|
" return 0;\n"
|
||||||
"};\n",
|
"};\n",
|
||||||
0, 0 },
|
0, 0, "not assignable" },
|
||||||
|
|
||||||
/* (3) CONTROL — [3]int into a []int param is the legit #258 borrow
|
/* (3) CONTROL — [3]int into a []int param is the legit #258 borrow
|
||||||
* (matching element) → ACCEPT both, run to 0. The general check must
|
* (matching element) → ACCEPT both, run to 0. The general check must
|
||||||
@@ -122,7 +123,7 @@ static const struct row rows[] = {
|
|||||||
{ "let_slice_eq_scalar",
|
{ "let_slice_eq_scalar",
|
||||||
"package main;\n"
|
"package main;\n"
|
||||||
"export fn main() int = { let xs: []int = 5; return 0; };\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
|
/* (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
|
* 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 g() int = { return 7; };\n"
|
||||||
"fn use_it(f: myfn) int = { return f(); };\n"
|
"fn use_it(f: myfn) int = { return f(); };\n"
|
||||||
"export fn main() int = { return use_it(&g); };\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.
|
/* (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). */
|
* 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"
|
"package main;\n"
|
||||||
"fn h() str = { return \"\"; };\n"
|
"fn h() str = { return \"\"; };\n"
|
||||||
"export fn main() int = { let p: fn() int = h; return 0; };\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
|
/* (11) aggregate<->aggregate KIND mismatch — a [3]int array arg into a
|
||||||
* `*int` param. Both aggregate, different kind -> confident reject (the
|
* `*int` param. Both aggregate, different kind -> confident reject (the
|
||||||
@@ -186,7 +187,7 @@ static const struct row rows[] = {
|
|||||||
" takesptr(a);\n"
|
" takesptr(a);\n"
|
||||||
" return 0;\n"
|
" return 0;\n"
|
||||||
"};\n",
|
"};\n",
|
||||||
0, 0 },
|
0, 0, "not assignable" },
|
||||||
|
|
||||||
/* (12) CONTROL — a concrete value into a SPREAD-tagged param must NOT
|
/* (12) CONTROL — a concrete value into a SPREAD-tagged param must NOT
|
||||||
* over-reject: cstage flattens `...inner` at resolve_type and accepts
|
* 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;
|
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
|
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(s, sizeof s, "/tmp/catn_%d_%d.ww", getpid(), i);
|
||||||
snprintf(tmpdir, sizeof tmpdir, "/tmp/catn_%d_d_%d", 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");
|
FILE *f = fopen(s, "wb");
|
||||||
if (!f) return -1;
|
if (!f) return -1;
|
||||||
@@ -249,11 +267,13 @@ build_should_fail(const char *driver, const char *src, int i)
|
|||||||
fclose(f);
|
fclose(f);
|
||||||
|
|
||||||
mkdir(tmpdir, 0755);
|
mkdir(tmpdir, 0755);
|
||||||
snprintf(cmd, sizeof cmd, "cd %s && %s build %s 2>/dev/null",
|
snprintf(cmd, sizeof cmd, "cd %s && %s build %s >/dev/null 2>%s",
|
||||||
tmpdir, driver, s);
|
tmpdir, driver, s, errf);
|
||||||
int rc = runwait(cmd);
|
int rc = runwait(cmd);
|
||||||
|
int hasmsg = filehas(errf, diag);
|
||||||
|
|
||||||
unlink(s);
|
unlink(s);
|
||||||
|
unlink(errf);
|
||||||
const char *base = strrchr(s, '/');
|
const char *base = strrchr(s, '/');
|
||||||
base = base ? base + 1 : s;
|
base = base ? base + 1 : s;
|
||||||
char outbin[128];
|
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';
|
if (dot && strcmp(dot, ".ww") == 0) *dot = '\0';
|
||||||
unlink(outbin);
|
unlink(outbin);
|
||||||
rmdir(tmpdir);
|
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
|
/* -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);
|
fputs(t->src, f);
|
||||||
fclose(f);
|
fclose(f);
|
||||||
|
|
||||||
|
char errf[176];
|
||||||
|
snprintf(errf, sizeof errf, "%s.err", stem);
|
||||||
snprintf(cmd, sizeof cmd,
|
snprintf(cmd, sizeof cmd,
|
||||||
"WW_PKGCACHE=%s.pkgc %s/%s test --sep -o %s %s > /dev/null 2>&1",
|
"WW_PKGCACHE=%s.pkgc %s/%s test --sep -o %s %s >/dev/null 2>%s",
|
||||||
stem, bin, drv, stem, src);
|
stem, bin, drv, stem, src, errf);
|
||||||
int rc = runwait(cmd);
|
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(src);
|
||||||
|
unlink(errf);
|
||||||
snprintf(cmd, sizeof cmd, "rm -rf %s %s.sepwork %s.pkgc",
|
snprintf(cmd, sizeof cmd, "rm -rf %s %s.sepwork %s.pkgc",
|
||||||
stem, stem, stem);
|
stem, stem, stem);
|
||||||
if (system(cmd)) {}
|
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);
|
"accepted (expected a loud reject)\n", stage, t->label, drv);
|
||||||
return -1;
|
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;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -375,20 +407,25 @@ multimod_build_fail(const char *drv, const char *mainbody, int withmod1,
|
|||||||
fputs(mainbody, f);
|
fputs(mainbody, f);
|
||||||
fclose(f);
|
fclose(f);
|
||||||
|
|
||||||
|
char errf[128];
|
||||||
|
snprintf(errf, sizeof errf, "%s/err.txt", dir);
|
||||||
if (withmod1)
|
if (withmod1)
|
||||||
snprintf(cmd, sizeof cmd,
|
snprintf(cmd, sizeof cmd,
|
||||||
"cd %s && %s build -I %s -I %s main.ww >/dev/null 2>&1",
|
"cd %s && %s build -I %s -I %s main.ww >/dev/null 2>%s",
|
||||||
dir, drv, io2d, mod1d);
|
dir, drv, io2d, mod1d, errf);
|
||||||
else
|
else
|
||||||
snprintf(cmd, sizeof cmd,
|
snprintf(cmd, sizeof cmd,
|
||||||
"cd %s && %s build -I %s main.ww >/dev/null 2>&1",
|
"cd %s && %s build -I %s main.ww >/dev/null 2>%s",
|
||||||
dir, drv, io2d);
|
dir, drv, io2d, errf);
|
||||||
int rc = runwait(cmd);
|
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);
|
snprintf(rm, sizeof rm, "rm -rf %s", dir);
|
||||||
runwait(rm);
|
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
|
/* a []int SLICE passed where io2.handle = (file | stream) is wanted — NO
|
||||||
@@ -468,7 +505,7 @@ main(void)
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (build_should_fail(drivers[d].drv, rows[i].src,
|
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]: "
|
fprintf(stderr, "callarg_typecheck[%s][%s]: "
|
||||||
"built ok, expected a loud reject\n",
|
"built ok, expected a loud reject\n",
|
||||||
drivers[d].name, rows[i].label);
|
drivers[d].name, rows[i].label);
|
||||||
|
|||||||
@@ -40,6 +40,8 @@ struct row {
|
|||||||
const char *src;
|
const char *src;
|
||||||
int expect_build; /* 1 = build+run to want_exit; 0 = must FAIL */
|
int expect_build; /* 1 = build+run to want_exit; 0 = must FAIL */
|
||||||
int want_exit;
|
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[] = {
|
static const struct row rows[] = {
|
||||||
@@ -53,7 +55,7 @@ static const struct row rows[] = {
|
|||||||
" xs[0] = 77u8;\n"
|
" xs[0] = 77u8;\n"
|
||||||
" return n;\n"
|
" return n;\n"
|
||||||
"};\n",
|
"};\n",
|
||||||
0, 0 },
|
0, 0, "array length must be an integer literal" },
|
||||||
|
|
||||||
/* #2 control — a literal dimension stays valid → run 0. */
|
/* #2 control — a literal dimension stays valid → run 0. */
|
||||||
{ "arrlen_const_ok",
|
{ "arrlen_const_ok",
|
||||||
@@ -75,7 +77,7 @@ static const struct row rows[] = {
|
|||||||
" let c: str = a + b;\n"
|
" let c: str = a + b;\n"
|
||||||
" return c.len: i32;\n"
|
" return c.len: i32;\n"
|
||||||
"};\n",
|
"};\n",
|
||||||
0, 0 },
|
0, 0, "arithmetic on non-numeric type" },
|
||||||
|
|
||||||
/* #6 — bitwise & on str is non-integer → REJECT. */
|
/* #6 — bitwise & on str is non-integer → REJECT. */
|
||||||
{ "str_bitand",
|
{ "str_bitand",
|
||||||
@@ -86,7 +88,7 @@ static const struct row rows[] = {
|
|||||||
" let n: i32 = (a & b): i32;\n"
|
" let n: i32 = (a & b): i32;\n"
|
||||||
" return n;\n"
|
" return n;\n"
|
||||||
"};\n",
|
"};\n",
|
||||||
0, 0 },
|
0, 0, "bitwise on non-integer type" },
|
||||||
|
|
||||||
/* #6 — ordered comparison on str is non-numeric → REJECT (EQ/NEQ stay
|
/* #6 — ordered comparison on str is non-numeric → REJECT (EQ/NEQ stay
|
||||||
* valid; only the ordered <,<=,>,>= are gated, matching cstage). */
|
* valid; only the ordered <,<=,>,>= are gated, matching cstage). */
|
||||||
@@ -98,7 +100,7 @@ static const struct row rows[] = {
|
|||||||
" if (a < b) { return 1; };\n"
|
" if (a < b) { return 1; };\n"
|
||||||
" return 0;\n"
|
" return 0;\n"
|
||||||
"};\n",
|
"};\n",
|
||||||
0, 0 },
|
0, 0, "ordered comparison on non-numeric" },
|
||||||
|
|
||||||
/* #6 — unary ~ on a non-integer (str) → REJECT. */
|
/* #6 — unary ~ on a non-integer (str) → REJECT. */
|
||||||
{ "tilde_str",
|
{ "tilde_str",
|
||||||
@@ -108,7 +110,7 @@ static const struct row rows[] = {
|
|||||||
" let n: i32 = (~a): i32;\n"
|
" let n: i32 = (~a): i32;\n"
|
||||||
" return n;\n"
|
" return n;\n"
|
||||||
"};\n",
|
"};\n",
|
||||||
0, 0 },
|
0, 0, "~ on non-integer" },
|
||||||
|
|
||||||
/* #6 control — integer arithmetic, comparison, bitwise all valid. */
|
/* #6 control — integer arithmetic, comparison, bitwise all valid. */
|
||||||
{ "int_ops_ok",
|
{ "int_ops_ok",
|
||||||
@@ -130,7 +132,7 @@ static const struct row rows[] = {
|
|||||||
" let v: i32 = 5;\n"
|
" let v: i32 = 5;\n"
|
||||||
" return size(v): i32;\n"
|
" return size(v): i32;\n"
|
||||||
"};\n",
|
"};\n",
|
||||||
0, 0 },
|
0, 0, "unknown type 'v'" },
|
||||||
|
|
||||||
/* #7 control — size() of a real type folds → run 4. */
|
/* #7 control — size() of a real type folds → run 4. */
|
||||||
{ "size_type_ok",
|
{ "size_type_ok",
|
||||||
@@ -145,7 +147,7 @@ static const struct row rows[] = {
|
|||||||
" let t: (i32, i32) = (1, 2, 3);\n"
|
" let t: (i32, i32) = (1, 2, 3);\n"
|
||||||
" return 0;\n"
|
" return 0;\n"
|
||||||
"};\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
|
/* #10 — a short tuple literal → REJECT (the live miscompile: cgen
|
||||||
* filled the missing slot with a stale register). */
|
* 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"
|
" let t: (i32, i32, i32) = (1, 2);\n"
|
||||||
" return 0;\n"
|
" return 0;\n"
|
||||||
"};\n",
|
"};\n",
|
||||||
0, 0 },
|
0, 0, "not assignable to declared", "tuple literal has 2 elements" },
|
||||||
|
|
||||||
/* #10 control — a matching-arity tuple literal → run 3. */
|
/* #10 control — a matching-arity tuple literal → run 3. */
|
||||||
{ "tuple_match_ok",
|
{ "tuple_match_ok",
|
||||||
@@ -178,7 +180,7 @@ static const struct row rows[] = {
|
|||||||
" a, s = f();\n"
|
" a, s = f();\n"
|
||||||
" return 0;\n"
|
" return 0;\n"
|
||||||
"};\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. */
|
/* #39 — multi-assign rhs is a plain scalar, not a tuple → REJECT. */
|
||||||
{ "massign_scalar",
|
{ "massign_scalar",
|
||||||
@@ -190,7 +192,7 @@ static const struct row rows[] = {
|
|||||||
" a, s = g();\n"
|
" a, s = g();\n"
|
||||||
" return 0;\n"
|
" return 0;\n"
|
||||||
"};\n",
|
"};\n",
|
||||||
0, 0 },
|
0, 0, "multi-assign rhs is not a tuple" },
|
||||||
|
|
||||||
/* #39 control — a bare-tuple-returning fn drives a valid massign. */
|
/* #39 control — a bare-tuple-returning fn drives a valid massign. */
|
||||||
{ "massign_tuple_ok",
|
{ "massign_tuple_ok",
|
||||||
@@ -213,7 +215,7 @@ static const struct row rows[] = {
|
|||||||
"type e = !void;\n"
|
"type e = !void;\n"
|
||||||
"fn g() (...inner | e) = { return true; };\n"
|
"fn g() (...inner | e) = { return true; };\n"
|
||||||
"export fn main() i32 = { let x = g()!; return 0; };\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. */
|
/* #8 control — a single-success tagged union try unwraps fine → run 5. */
|
||||||
{ "try_single_ok",
|
{ "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"
|
" let r = match (v) { case i32 => yield 7; case str => yield \"oops\"; };\n"
|
||||||
" return 0;\n"
|
" return 0;\n"
|
||||||
"};\n",
|
"};\n",
|
||||||
0, 0 },
|
0, 0, "match arm yields" },
|
||||||
|
|
||||||
/* match-yield control — same-family arm yields (untyped_int + i32) must
|
/* match-yield control — same-family arm yields (untyped_int + i32) must
|
||||||
* NOT over-reject (the untyped->concrete promotion cstage admits) → run 9. */
|
* 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
|
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(s, sizeof s, "/tmp/f2n_%d_%d.ww", getpid(), i);
|
||||||
snprintf(tmpdir, sizeof tmpdir, "/tmp/f2n_%d_d_%d", 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");
|
FILE *f = fopen(s, "wb");
|
||||||
if (!f) return -1;
|
if (!f) return -1;
|
||||||
@@ -293,11 +312,13 @@ build_should_fail(const char *driver, const char *src, int i)
|
|||||||
fclose(f);
|
fclose(f);
|
||||||
|
|
||||||
mkdir(tmpdir, 0755);
|
mkdir(tmpdir, 0755);
|
||||||
snprintf(cmd, sizeof cmd, "cd %s && %s build %s 2>/dev/null",
|
snprintf(cmd, sizeof cmd, "cd %s && %s build %s >/dev/null 2>%s",
|
||||||
tmpdir, driver, s);
|
tmpdir, driver, s, errf);
|
||||||
int rc = runwait(cmd);
|
int rc = runwait(cmd);
|
||||||
|
int hasmsg = filehas(errf, diag);
|
||||||
|
|
||||||
unlink(s);
|
unlink(s);
|
||||||
|
unlink(errf);
|
||||||
const char *base = strrchr(s, '/');
|
const char *base = strrchr(s, '/');
|
||||||
base = base ? base + 1 : s;
|
base = base ? base + 1 : s;
|
||||||
char outbin[128];
|
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';
|
if (dot && strcmp(dot, ".ww") == 0) *dot = '\0';
|
||||||
unlink(outbin);
|
unlink(outbin);
|
||||||
rmdir(tmpdir);
|
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
|
int
|
||||||
@@ -354,6 +376,8 @@ main(void)
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (build_should_fail(drivers[d].drv, rows[i].src,
|
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) {
|
100 + i) != 0) {
|
||||||
fprintf(stderr, "catA_f2_reject[%s][%s]: "
|
fprintf(stderr, "catA_f2_reject[%s][%s]: "
|
||||||
"built ok, expected a loud reject\n",
|
"built ok, expected a loud reject\n",
|
||||||
|
|||||||
@@ -39,6 +39,7 @@ struct row {
|
|||||||
const char *src;
|
const char *src;
|
||||||
int expect_build; /* 1 = build+run to want_exit; 0 = must FAIL */
|
int expect_build; /* 1 = build+run to want_exit; 0 = must FAIL */
|
||||||
int want_exit;
|
int want_exit;
|
||||||
|
const char *diag; /* expected reject diagnostic (NULL for build rows) */
|
||||||
};
|
};
|
||||||
|
|
||||||
static const struct row rows[] = {
|
static const struct row rows[] = {
|
||||||
@@ -49,7 +50,7 @@ static const struct row rows[] = {
|
|||||||
" let x: u64 = 99999999999999999999u64;\n"
|
" let x: u64 = 99999999999999999999u64;\n"
|
||||||
" return x: i32;\n"
|
" return x: i32;\n"
|
||||||
"};\n",
|
"};\n",
|
||||||
0, 0 },
|
0, 0, "bad integer literal" },
|
||||||
|
|
||||||
/* REJECT — 65-bit hex (smallest overflow above U64_MAX). */
|
/* REJECT — 65-bit hex (smallest overflow above U64_MAX). */
|
||||||
{ "hex_overflow",
|
{ "hex_overflow",
|
||||||
@@ -58,7 +59,7 @@ static const struct row rows[] = {
|
|||||||
" let x: u64 = 0x1ffffffffffffffffu64;\n"
|
" let x: u64 = 0x1ffffffffffffffffu64;\n"
|
||||||
" return x: i32;\n"
|
" return x: i32;\n"
|
||||||
"};\n",
|
"};\n",
|
||||||
0, 0 },
|
0, 0, "bad integer literal" },
|
||||||
|
|
||||||
/* REJECT — 2^128-1 decimal, far over u64. */
|
/* REJECT — 2^128-1 decimal, far over u64. */
|
||||||
{ "dec_huge",
|
{ "dec_huge",
|
||||||
@@ -67,7 +68,7 @@ static const struct row rows[] = {
|
|||||||
" let x: u64 = 340282366920938463463374607431768211455u64;\n"
|
" let x: u64 = 340282366920938463463374607431768211455u64;\n"
|
||||||
" return x: i32;\n"
|
" return x: i32;\n"
|
||||||
"};\n",
|
"};\n",
|
||||||
0, 0 },
|
0, 0, "bad integer literal" },
|
||||||
|
|
||||||
/* control — U64_MAX decimal is the largest accepted literal. */
|
/* control — U64_MAX decimal is the largest accepted literal. */
|
||||||
{ "u64max_dec_ok",
|
{ "u64max_dec_ok",
|
||||||
@@ -122,11 +123,30 @@ run_build(const char *driver, const struct row *r, int i)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static int
|
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(s, sizeof s, "/tmp/iovn_%d_%d.ww", getpid(), i);
|
||||||
snprintf(tmpdir, sizeof tmpdir, "/tmp/iovn_%d_d_%d", 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");
|
FILE *f = fopen(s, "wb");
|
||||||
if (!f) return -1;
|
if (!f) return -1;
|
||||||
@@ -134,11 +154,13 @@ build_should_fail(const char *driver, const char *src, int i)
|
|||||||
fclose(f);
|
fclose(f);
|
||||||
|
|
||||||
mkdir(tmpdir, 0755);
|
mkdir(tmpdir, 0755);
|
||||||
snprintf(cmd, sizeof cmd, "cd %s && %s build %s 2>/dev/null",
|
snprintf(cmd, sizeof cmd, "cd %s && %s build %s >/dev/null 2>%s",
|
||||||
tmpdir, driver, s);
|
tmpdir, driver, s, errf);
|
||||||
int rc = runwait(cmd);
|
int rc = runwait(cmd);
|
||||||
|
int hasmsg = filehas(errf, diag);
|
||||||
|
|
||||||
unlink(s);
|
unlink(s);
|
||||||
|
unlink(errf);
|
||||||
const char *base = strrchr(s, '/');
|
const char *base = strrchr(s, '/');
|
||||||
base = base ? base + 1 : s;
|
base = base ? base + 1 : s;
|
||||||
char outbin[128];
|
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';
|
if (dot && strcmp(dot, ".ww") == 0) *dot = '\0';
|
||||||
unlink(outbin);
|
unlink(outbin);
|
||||||
rmdir(tmpdir);
|
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
|
int
|
||||||
@@ -195,7 +218,7 @@ main(void)
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (build_should_fail(drivers[d].drv, rows[i].src,
|
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]: "
|
fprintf(stderr, "intoverflow_reject[%s][%s]: "
|
||||||
"built ok, expected a loud reject\n",
|
"built ok, expected a loud reject\n",
|
||||||
drivers[d].name, rows[i].label);
|
drivers[d].name, rows[i].label);
|
||||||
|
|||||||
@@ -89,6 +89,7 @@ struct row {
|
|||||||
int expect_build; /* 1 = build+run to want_exit; 0 = must FAIL */
|
int expect_build; /* 1 = build+run to want_exit; 0 = must FAIL */
|
||||||
int want_exit; /* meaningful only when expect_build */
|
int want_exit; /* meaningful only when expect_build */
|
||||||
int byteid; /* 1 = also assert w6c vs w6c_ww .s byte-id */
|
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[] = {
|
static const struct row rows[] = {
|
||||||
@@ -100,7 +101,7 @@ static const struct row rows[] = {
|
|||||||
"type small = (int | bool);\n"
|
"type small = (int | bool);\n"
|
||||||
"fn f(b: big) small = { return b; };\n"
|
"fn f(b: big) small = { return b; };\n"
|
||||||
"export fn main() int = { return 0; };\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.
|
/* (2) D flatten-subset, union→union → ACCEPT + byte-id.
|
||||||
* {bool,str} ⊆ {int,bool,str}; cstage flattens inner + remaps tags. */
|
* {bool,str} ⊆ {int,bool,str}; cstage flattens inner + remaps tags. */
|
||||||
@@ -172,7 +173,7 @@ static const struct row rows[] = {
|
|||||||
" };\n"
|
" };\n"
|
||||||
"};\n"
|
"};\n"
|
||||||
"export fn main() int = { return 0; };\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.
|
/* (5b) spread → wider subset assign (latent) → KEEP lenient accept.
|
||||||
* sp's src side carries a `...e1` spread → the guard keeps the
|
* 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;
|
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
|
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(s, sizeof s, "/tmp/tsrn_%d_%d.ww", getpid(), i);
|
||||||
snprintf(tmpdir, sizeof tmpdir, "/tmp/tsrn_%d_d_%d", 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");
|
FILE *f = fopen(s, "wb");
|
||||||
if (!f) return -1;
|
if (!f) return -1;
|
||||||
@@ -236,11 +252,13 @@ build_should_fail(const char *driver, const char *src, int i)
|
|||||||
fclose(f);
|
fclose(f);
|
||||||
|
|
||||||
mkdir(tmpdir, 0755);
|
mkdir(tmpdir, 0755);
|
||||||
snprintf(cmd, sizeof cmd, "cd %s && %s build %s 2>/dev/null",
|
snprintf(cmd, sizeof cmd, "cd %s && %s build %s >/dev/null 2>%s",
|
||||||
tmpdir, driver, s);
|
tmpdir, driver, s, errf);
|
||||||
int rc = runwait(cmd);
|
int rc = runwait(cmd);
|
||||||
|
int hasmsg = filehas(errf, diag);
|
||||||
|
|
||||||
unlink(s);
|
unlink(s);
|
||||||
|
unlink(errf);
|
||||||
const char *base = strrchr(s, '/');
|
const char *base = strrchr(s, '/');
|
||||||
base = base ? base + 1 : s;
|
base = base ? base + 1 : s;
|
||||||
char outbin[128];
|
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';
|
if (dot && strcmp(dot, ".ww") == 0) *dot = '\0';
|
||||||
unlink(outbin);
|
unlink(outbin);
|
||||||
rmdir(tmpdir);
|
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. */
|
/* 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 */
|
const char *msrc; /* package main; import e */
|
||||||
int expect_build; /* 1 = build+run to want_exit; 0 = must FAIL */
|
int expect_build; /* 1 = build+run to want_exit; 0 = must FAIL */
|
||||||
int want_exit;
|
int want_exit;
|
||||||
|
const char *rejdiag; /* expected reject diagnostic (NULL for build rows) */
|
||||||
};
|
};
|
||||||
|
|
||||||
static const struct xrow xrows[] = {
|
static const struct xrow xrows[] = {
|
||||||
@@ -345,7 +365,7 @@ static const struct xrow xrows[] = {
|
|||||||
"type myres = (i64 | e.done);\n"
|
"type myres = (i64 | e.done);\n"
|
||||||
"fn forward() myres = { return e.next(); };\n"
|
"fn forward() myres = { return e.next(); };\n"
|
||||||
"export fn main() i32 = { return 0; };\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
|
/* 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;
|
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 "
|
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 brc = runwait(cmd);
|
||||||
|
|
||||||
int got = -1;
|
int got = -1;
|
||||||
if (brc == 0) {
|
if (brc == 0) {
|
||||||
snprintf(path, sizeof path, "%s/main", dir);
|
snprintf(path, sizeof path, "%s/main", dir);
|
||||||
got = runwait(path);
|
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);
|
snprintf(cmd, sizeof cmd, "rm -rf %s", dir);
|
||||||
(void)runwait(cmd);
|
(void)runwait(cmd);
|
||||||
return brc == 0 ? got : -1;
|
return got;
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
@@ -434,7 +461,7 @@ main(void)
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (build_should_fail(drivers[d].path,
|
if (build_should_fail(drivers[d].path,
|
||||||
rows[i].src, 100 + i) != 0) {
|
rows[i].src, rows[i].diag, 100 + i) != 0) {
|
||||||
fprintf(stderr,
|
fprintf(stderr,
|
||||||
"tagged_subset_reject[%s][%s]: "
|
"tagged_subset_reject[%s][%s]: "
|
||||||
"built ok, expected a loud reject\n",
|
"built ok, expected a loud reject\n",
|
||||||
|
|||||||
@@ -37,6 +37,7 @@ struct row {
|
|||||||
const char *src;
|
const char *src;
|
||||||
int expect_build; /* 1 = build+run to want_exit; 0 = must FAIL */
|
int expect_build; /* 1 = build+run to want_exit; 0 = must FAIL */
|
||||||
int want_exit;
|
int want_exit;
|
||||||
|
const char *diag; /* expected reject diagnostic (NULL for build rows) */
|
||||||
};
|
};
|
||||||
|
|
||||||
static const struct row rows[] = {
|
static const struct row rows[] = {
|
||||||
@@ -46,14 +47,14 @@ static const struct row rows[] = {
|
|||||||
"package main;\n"
|
"package main;\n"
|
||||||
"fnn helper() i32 = { return 42; };\n"
|
"fnn helper() i32 = { return 42; };\n"
|
||||||
"export fn main() i32 = { return 0; };\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. */
|
/* REJECT — a stray run of bare identifiers at top level. */
|
||||||
{ "stray_idents",
|
{ "stray_idents",
|
||||||
"package main;\n"
|
"package main;\n"
|
||||||
"bogus token here;\n"
|
"bogus token here;\n"
|
||||||
"export fn main() i32 = { return 0; };\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
|
/* REJECT — a stray decl whose body has internal ';'s, exercising the
|
||||||
* brace-balanced chew recovery (still must error, not silently skip). */
|
* brace-balanced chew recovery (still must error, not silently skip). */
|
||||||
@@ -61,7 +62,7 @@ static const struct row rows[] = {
|
|||||||
"package main;\n"
|
"package main;\n"
|
||||||
"gizmo foo { let a = 1; let b = 2; };\n"
|
"gizmo foo { let a = 1; let b = 2; };\n"
|
||||||
"export fn main() i32 = { return 0; };\n",
|
"export fn main() i32 = { return 0; };\n",
|
||||||
0, 0 },
|
0, 0, "expected top-level decl" },
|
||||||
|
|
||||||
/* control — a clean program builds + runs. */
|
/* control — a clean program builds + runs. */
|
||||||
{ "clean_ok",
|
{ "clean_ok",
|
||||||
@@ -111,11 +112,31 @@ run_build(const char *driver, const struct row *r, int i)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static int
|
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(s, sizeof s, "/tmp/undn_%d_%d.ww", getpid(), i);
|
||||||
snprintf(tmpdir, sizeof tmpdir, "/tmp/undn_%d_d_%d", 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");
|
FILE *f = fopen(s, "wb");
|
||||||
if (!f) return -1;
|
if (!f) return -1;
|
||||||
@@ -123,11 +144,13 @@ build_should_fail(const char *driver, const char *src, int i)
|
|||||||
fclose(f);
|
fclose(f);
|
||||||
|
|
||||||
mkdir(tmpdir, 0755);
|
mkdir(tmpdir, 0755);
|
||||||
snprintf(cmd, sizeof cmd, "cd %s && %s build %s 2>/dev/null",
|
snprintf(cmd, sizeof cmd, "cd %s && %s build %s >/dev/null 2>%s",
|
||||||
tmpdir, driver, s);
|
tmpdir, driver, s, errf);
|
||||||
int rc = runwait(cmd);
|
int rc = runwait(cmd);
|
||||||
|
int hasmsg = filehas(errf, diag);
|
||||||
|
|
||||||
unlink(s);
|
unlink(s);
|
||||||
|
unlink(errf);
|
||||||
const char *base = strrchr(s, '/');
|
const char *base = strrchr(s, '/');
|
||||||
base = base ? base + 1 : s;
|
base = base ? base + 1 : s;
|
||||||
char outbin[128];
|
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';
|
if (dot && strcmp(dot, ".ww") == 0) *dot = '\0';
|
||||||
unlink(outbin);
|
unlink(outbin);
|
||||||
rmdir(tmpdir);
|
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
|
int
|
||||||
@@ -184,7 +208,7 @@ main(void)
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (build_should_fail(drivers[d].drv, rows[i].src,
|
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]: "
|
fprintf(stderr, "unknowndecl_reject[%s][%s]: "
|
||||||
"built ok, expected a loud reject\n",
|
"built ok, expected a loud reject\n",
|
||||||
drivers[d].name, rows[i].label);
|
drivers[d].name, rows[i].label);
|
||||||
|
|||||||
Reference in New Issue
Block a user