ww: loud fatal on unresolvable import, inline-package aware (#16 ENFORCE-driver)
Both driver twins: an import that neither locates as a file nor is satisfied by an inline 'package <name>' declaration in the unit is now fatal "ww: cannot find package <name>" (was a silent skip that masked dead imports and typos). The inline scan is a new every-line helper on the uncapped comment-skip core - peekpackage stops at the first decl, and single-file multi-package fixtures declare several. 949 pins both branches (miss->fatal, inline->build+run); 993 adds ww_ww parity.
This commit is contained in:
@@ -13,6 +13,7 @@
|
||||
*/
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/wait.h>
|
||||
|
||||
@@ -156,6 +157,44 @@ run_build_fail(const char *bin, const char *driver)
|
||||
return rc;
|
||||
}
|
||||
|
||||
/* #16 ENFORCE-driver: an unresolvable import is a hard error, not a silent
|
||||
* skip — the driver must exit nonzero AND print "ww: cannot find package
|
||||
* <name>". Both drivers must agree (rule-10 wording). Returns 0 if the
|
||||
* driver loud-fails as expected, 1 otherwise. (The ww_ww half is why this
|
||||
* lives in 993, the rule-14-safe wwstage-driver range.) */
|
||||
static int
|
||||
run_missing_pkg(const char *bin, const char *driver)
|
||||
{
|
||||
char src[64], errf[64];
|
||||
snprintf(src, sizeof src, "/tmp/ww_mp_%s_%d.ww", driver, getpid());
|
||||
snprintf(errf, sizeof errf, "/tmp/ww_mp_%s_%d.err", driver, getpid());
|
||||
FILE *f = fopen(src, "w");
|
||||
if (!f) return 1;
|
||||
fputs("import nosuchpkg;\nexport fn main() i32 = { return 0; };\n", f);
|
||||
fclose(f);
|
||||
|
||||
char cmd[256];
|
||||
snprintf(cmd, sizeof cmd, "%s/%s build %s 2>%s", bin, driver, src, errf);
|
||||
int rc = runwait(cmd);
|
||||
|
||||
int found = 0;
|
||||
FILE *e = fopen(errf, "rb");
|
||||
if (e) {
|
||||
char buf[4096];
|
||||
size_t n = fread(buf, 1, sizeof buf - 1, e);
|
||||
fclose(e);
|
||||
buf[n] = '\0';
|
||||
found = strstr(buf, "cannot find package nosuchpkg") != NULL;
|
||||
}
|
||||
unlink(src); unlink(errf);
|
||||
if (rc == 0 || !found) {
|
||||
fprintf(stderr, "ww_ww FAIL: %s missing-pkg rc=%d found=%d "
|
||||
"(want nonzero + 'cannot find package')\n", driver, rc, found);
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
main(void)
|
||||
{
|
||||
@@ -250,6 +289,11 @@ main(void)
|
||||
rcfail++;
|
||||
}
|
||||
|
||||
/* #16 ENFORCE-driver: a missing import package loud-fails (nonzero +
|
||||
* "cannot find package") on BOTH drivers — identical wording. */
|
||||
rcfail += run_missing_pkg(bin, "ww");
|
||||
rcfail += run_missing_pkg(bin, "ww_ww");
|
||||
|
||||
if (fail || rcfail) {
|
||||
fprintf(stderr, "ww_ww: %d/%d diff(s) failed, %d exit-code "
|
||||
"row(s) failed\n", fail, n, rcfail);
|
||||
|
||||
Reference in New Issue
Block a user