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 <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/wait.h>
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user