test: port the driver-CLI observers to ww; retire 949_driver_flagargs + 949_missingpkg
One commit for both carriers: flag-misuse parity and the missing-package fatal are the same driver-CLI subprocess surface. The -V oracle parses WW_VERSION out of cmd/wcc/ww.h at run time; the missingpkg ww_ww twin stays owned by bootstrap carrier 993_ww_ww.c.
This commit is contained in:
2
Makefile
2
Makefile
@@ -419,7 +419,7 @@ MISC_WW_TARGETS = $(MISC_WW_TESTS:%=wwtest/%)
|
||||
# diagnostic gates, driver-CLI parity, @symbol FFI asm needles, .wwi
|
||||
# wide-rune round-trips, the c6 sep soak). Compiler/driver gates like
|
||||
# test/sep: they run under test-compiler.
|
||||
TOOL_WW_TESTS = test/tool/rejects_test.ww
|
||||
TOOL_WW_TESTS = test/tool/rejects_test.ww test/tool/driver_test.ww
|
||||
TOOL_WW_TARGETS = $(TOOL_WW_TESTS:%=wwtest/%)
|
||||
BOOTSTRAP_WRAPPER_SOURCES = test/wcc/950_selfcheck.c \
|
||||
test/wcc/991_w6a_ww.c \
|
||||
|
||||
202
test/tool/driver_test.ww
Normal file
202
test/tool/driver_test.ww
Normal file
@@ -0,0 +1,202 @@
|
||||
package driver_test;
|
||||
|
||||
// `ww` driver CLI observers. Ports of the retired native carriers
|
||||
// test/wcc/949_driver_flagargs.c and 949_missingpkg.c; every
|
||||
// assertion preserved.
|
||||
//
|
||||
// flagargs (#15 B2) — `ww -V` exits 0 with stdout exactly
|
||||
// "ww <WW_VERSION>\n" and empty stderr; 15 flag-misuse rows each exit
|
||||
// 2 with the row's stderr fragment; and on every row plus -V the
|
||||
// wwstage twin `ww_ww` matches the cstage `ww` byte-exactly on exit
|
||||
// code, stdout and stderr (rule 10 on the driver surface). The
|
||||
// version oracle is parsed from cmd/wcc/ww.h at run time, preserving
|
||||
// the carrier's exact-output ownership without a C toolchain
|
||||
// dependency. Rows run from a fresh scratch cwd: the `test . zzz` row
|
||||
// takes `.` positionally, so the cwd must never be the repo tree.
|
||||
//
|
||||
// missingpkg (#16 ENFORCE-driver) — `ww build` over a source whose
|
||||
// only import cannot be located exits nonzero with "cannot find
|
||||
// package nosuchpkg" on stderr (the driver fatal, emitted by
|
||||
// cmd/ww/main.c, not w6c); the ww_ww twin of this leg is owned by the
|
||||
// retained bootstrap carrier test/wcc/993_ww_ww.c. The inline branch
|
||||
// pins the skip arm: a single-file multi-package unit whose import is
|
||||
// satisfied by an inline `package aa` builds and runs to exit 7 (the
|
||||
// fatal must not over-fire on the inline-package pattern).
|
||||
|
||||
import os;
|
||||
import os.exec;
|
||||
import strings;
|
||||
import testenv;
|
||||
import time;
|
||||
|
||||
fn fail(label: str, why: str) void = {
|
||||
let m: str = strings.concat("driver FAIL: ", label, " -- ", why,
|
||||
"\n");
|
||||
os.write(2, m.ptr, m.len: u64);
|
||||
assert(false);
|
||||
};
|
||||
|
||||
fn tmo() time.duration = {
|
||||
return (30i64 * (time.second: i64)): time.duration;
|
||||
};
|
||||
|
||||
// Byte-offset borrow: strings.sub is rune-indexed and ww.h holds only
|
||||
// ASCII around the define, but the borrow keeps the cursor math exact.
|
||||
fn bslice(s: str, start: i32, end: i32) str = {
|
||||
assert(start <= end && end <= s.len);
|
||||
let r: str;
|
||||
r.ptr = s.ptr + (start: u64);
|
||||
r.len = end - start;
|
||||
return r;
|
||||
};
|
||||
|
||||
// The compile-time constant the C carrier took from #include "ww.h".
|
||||
fn wwversion() str = {
|
||||
let h: str = testenv.readfile(strings.concat(testenv.repo(),
|
||||
"/cmd/wcc/ww.h"));
|
||||
let at: i32 = testenv.pos(h, "#define WW_VERSION");
|
||||
assert(at >= 0);
|
||||
let i: i32 = at;
|
||||
for (h[i] != '"') { i += 1; };
|
||||
let j: i32 = i + 1;
|
||||
for (h[j] != '"') { j += 1; };
|
||||
return bslice(h, i + 1, j);
|
||||
};
|
||||
|
||||
fn rundrv(root: str, name: str, drv: str, argv: []str,
|
||||
out: *testenv.commandout) void = {
|
||||
let av: []str = alloc([], (argv.len + 1): u64)!;
|
||||
append(av, testenv.driver(drv));
|
||||
let i: i32 = 0;
|
||||
for (i < argv.len) { append(av, argv[i]); i += 1; };
|
||||
testenv.runcommand(root, root, name, av, tmo(), out);
|
||||
assert(out.termination == exec.termination.EXIT);
|
||||
};
|
||||
|
||||
@test fn version() void = {
|
||||
let td: str = testenv.fresh();
|
||||
let want: str = strings.concat("ww ", wwversion(), "\n");
|
||||
let co: testenv.commandout;
|
||||
let wo: testenv.commandout;
|
||||
let vtail: []str = ["-V"];
|
||||
rundrv(td, "version_c", "ww", vtail, &co);
|
||||
rundrv(td, "version_w", "ww_ww", vtail, &wo);
|
||||
if (co.code != 0 || !testenv.same(co.stdout, want)
|
||||
|| co.stderr.len != 0) {
|
||||
fail("version", "ww -V rc/stdout/stderr drifted from WW_VERSION");
|
||||
};
|
||||
if (wo.code != co.code || !testenv.same(wo.stdout, co.stdout)
|
||||
|| !testenv.same(wo.stderr, co.stderr)) {
|
||||
fail("version", "ww_ww -V != ww -V (twin parity)");
|
||||
};
|
||||
testenv.clean(td);
|
||||
};
|
||||
|
||||
// a3 == "" means a two-token argv tail; no row passes a literal "".
|
||||
@test fn flagargs() void = {
|
||||
let a1: []str = ["build", "build", "build", "build", "build",
|
||||
"run", "run", "run", "test", "test", "test", "test", "test",
|
||||
"test", "test"];
|
||||
let a2: []str = ["-o", "-I", "-L", "-l", "-zz",
|
||||
"-o", "-l", "-zz", "-l", "-zz", "-I", "-o", "-o",
|
||||
"-run", "."];
|
||||
let a3: []str = ["", "", "", "", "",
|
||||
"", "", "", "", "", "", "", "x",
|
||||
"", "zzz"];
|
||||
let subs: []str = [
|
||||
"ww build: -o needs an argument",
|
||||
"ww build: -I needs an argument",
|
||||
"ww build: -L needs an argument",
|
||||
"ww build: -l needs an argument",
|
||||
"ww build: unknown flag",
|
||||
"ww run: -o needs an argument",
|
||||
"ww run: -l needs an argument",
|
||||
"ww run: unknown flag",
|
||||
"ww test: unknown flag",
|
||||
"ww test: unknown flag",
|
||||
"ww test: -I needs an argument",
|
||||
"ww test: -o needs an argument",
|
||||
"ww test: -c/-S/-o need a single test file",
|
||||
"ww test: -run needs an argument",
|
||||
"ww test: pattern needs a single test file"];
|
||||
let i: i32 = 0;
|
||||
for (i < subs.len) {
|
||||
let td: str = testenv.fresh();
|
||||
let tail: []str = alloc([], 3u64)!;
|
||||
append(tail, a1[i]);
|
||||
append(tail, a2[i]);
|
||||
if (a3[i].len != 0) { append(tail, a3[i]); };
|
||||
let co: testenv.commandout;
|
||||
let wo: testenv.commandout;
|
||||
// fixed capture names: each row owns a fresh td, and the row
|
||||
// fragment holds '/' bytes that may not name a capture file
|
||||
rundrv(td, "row_c", "ww", tail, &co);
|
||||
rundrv(td, "row_w", "ww_ww", tail, &wo);
|
||||
if (co.code != 2) {
|
||||
fail(subs[i], "ww rc != 2");
|
||||
};
|
||||
if (!testenv.has(co.stderr, subs[i])) {
|
||||
fail(subs[i], strings.concat("ww stderr missing fragment; got: ",
|
||||
co.stderr));
|
||||
};
|
||||
if (wo.code != co.code || !testenv.same(wo.stderr, co.stderr)
|
||||
|| !testenv.same(wo.stdout, co.stdout)) {
|
||||
fail(subs[i], "ww_ww != ww (twin parity on rc/stderr/stdout)");
|
||||
};
|
||||
testenv.clean(td);
|
||||
i += 1;
|
||||
};
|
||||
};
|
||||
|
||||
@test fn missingpkg_miss() void = {
|
||||
let td: str = testenv.fresh();
|
||||
let src: str = strings.concat(td, "/miss.ww");
|
||||
testenv.writefile(src, strings.concat(
|
||||
"package main;\n",
|
||||
"import nosuchpkg;\n",
|
||||
"export fn main() i32 = { return 0; };\n"));
|
||||
let co: testenv.commandout;
|
||||
// -o needs a writable stem: the output-derived .sepwork follows -o,
|
||||
// so /dev/null would yield an uncreatable /dev/null.sepwork and
|
||||
// mask the missing-package fatal.
|
||||
let av: []str = [testenv.driver("ww"), "build", src, "-o",
|
||||
strings.concat(td, "/miss.out")];
|
||||
testenv.runcommand(td, td, "miss", av, tmo(), &co);
|
||||
assert(co.termination == exec.termination.EXIT);
|
||||
if (co.code == 0) {
|
||||
fail("missingpkg_miss", "ww accepted a missing import");
|
||||
};
|
||||
if (!testenv.has(co.stderr, "cannot find package nosuchpkg")) {
|
||||
fail("missingpkg_miss",
|
||||
"no 'cannot find package nosuchpkg' on stderr");
|
||||
};
|
||||
testenv.clean(td);
|
||||
};
|
||||
|
||||
@test fn missingpkg_inline() void = {
|
||||
let td: str = testenv.fresh();
|
||||
let src: str = strings.concat(td, "/inline.ww");
|
||||
testenv.writefile(src, strings.concat(
|
||||
"package aa;\n",
|
||||
"export fn getv() i32 = { return 7; };\n",
|
||||
"package main;\n",
|
||||
"import aa;\n",
|
||||
"export fn main() i32 = { return aa.getv(); };\n"));
|
||||
let out: str = strings.concat(td, "/inline");
|
||||
let co: testenv.commandout;
|
||||
let av: []str = [testenv.driver("ww"), "build", "-o", out, src];
|
||||
testenv.runcommand(td, td, "inline_build", av, tmo(), &co);
|
||||
assert(co.termination == exec.termination.EXIT);
|
||||
if (co.code != 0) {
|
||||
fail("missingpkg_inline",
|
||||
"inline-package build failed (inline-skip branch regressed)");
|
||||
};
|
||||
let ro: testenv.commandout;
|
||||
let rav: []str = [out];
|
||||
testenv.runcommand(td, td, "inline_run", rav, tmo(), &ro);
|
||||
assert(ro.termination == exec.termination.EXIT);
|
||||
if (ro.code != 7) {
|
||||
fail("missingpkg_inline", "built binary exit != 7");
|
||||
};
|
||||
testenv.clean(td);
|
||||
};
|
||||
@@ -1,175 +0,0 @@
|
||||
/*
|
||||
* 949_driver_flagargs — task #15 B2: the ww driver's flag-argument error
|
||||
* branches, pinned across BOTH driver twins (cstage `ww` and wwstage
|
||||
* `ww_ww`). The branches under test:
|
||||
* build/run — a lone -I/-L/-l/-o (flag with no following argument) is a
|
||||
* hard error "ww <cmd>: -X needs an argument" (rc 2), not a
|
||||
* silently-swallowed positional.
|
||||
* test — -I/-c/-o carry meaning; -l/-L and any unknown flag are
|
||||
* rejected with "ww test: unknown flag" (rc 2); a lone -I/-o
|
||||
* is "ww test: -X needs an argument" (rc 2); -o without a
|
||||
* single test file is "ww test: -c/-S/-o need a single test
|
||||
* file" (rc 2, #17); a missing -run argument is rc 2; a 2nd positional
|
||||
* in directory mode is "ww test: pattern needs a single test
|
||||
* file" (rc 2, #17).
|
||||
* Each row asserts the expected rc + stderr substring AND that the two
|
||||
* drivers are byte-identical (rule 10): the cstage parse_build_flags /
|
||||
* do_test must match the wwstage main.ww dobuild/dorun/dotest verbatim.
|
||||
* This carrier also owns the `-V` output and C/WW-driver version parity.
|
||||
*
|
||||
* All flag rows error during parsing, before any compile, so there are no
|
||||
* build intermediates to redirect (rule 14: light driver test, any NNN).
|
||||
* Sibling of 949_missingpkg (driver enforcement) and 993_ww_ww (twin parity).
|
||||
*/
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/wait.h>
|
||||
#include "ww.h"
|
||||
|
||||
struct row {
|
||||
const char *args; /* argv tail after the driver path */
|
||||
int rc; /* expected exit code */
|
||||
const char *sub; /* expected stderr substring */
|
||||
};
|
||||
|
||||
static const struct row rows[] = {
|
||||
{ "build -o", 2, "ww build: -o needs an argument" },
|
||||
{ "build -I", 2, "ww build: -I needs an argument" },
|
||||
{ "build -L", 2, "ww build: -L needs an argument" },
|
||||
{ "build -l", 2, "ww build: -l needs an argument" },
|
||||
{ "build -zz", 2, "ww build: unknown flag" },
|
||||
{ "run -o", 2, "ww run: -o needs an argument" },
|
||||
{ "run -l", 2, "ww run: -l needs an argument" },
|
||||
{ "run -zz", 2, "ww run: unknown flag" },
|
||||
{ "test -l", 2, "ww test: unknown flag" },
|
||||
{ "test -zz", 2, "ww test: unknown flag" },
|
||||
{ "test -I", 2, "ww test: -I needs an argument" },
|
||||
/* Package `test -c` is now valid and covered by native package tests. A
|
||||
* lone -o needs an argument, while -o still has no directory contract. */
|
||||
{ "test -o", 2, "ww test: -o needs an argument" },
|
||||
{ "test -o x", 2, "ww test: -c/-S/-o need a single test file" },
|
||||
{ "test -run", 2, "ww test: -run needs an argument" },
|
||||
/* #17: a 2nd positional is a fnmatch name-filter pattern, valid only
|
||||
* for a single test file/module; in directory mode (target ".") it
|
||||
* has no single binary to route to and is rejected (rc 2). */
|
||||
{ "test . zzz", 2, "ww test: pattern needs a single test file" },
|
||||
};
|
||||
|
||||
static void
|
||||
read_text(const char *path, char *buf, size_t bufsz)
|
||||
{
|
||||
buf[0] = '\0';
|
||||
FILE *f = fopen(path, "r");
|
||||
if (f == NULL)
|
||||
return;
|
||||
size_t n = fread(buf, 1, bufsz - 1, f);
|
||||
buf[n] = '\0';
|
||||
fclose(f);
|
||||
}
|
||||
|
||||
/* Run "<bin>/<drv> <args>" and capture both output streams. */
|
||||
static int
|
||||
run_drv(const char *bin, const char *drv, const char *args,
|
||||
char *out, size_t outsz, char *err, size_t errsz)
|
||||
{
|
||||
int pid = getpid();
|
||||
char outf[64], errf[64], cmd[2048];
|
||||
snprintf(outf, sizeof outf, "/tmp/dfa949_%d.out", pid);
|
||||
snprintf(errf, sizeof errf, "/tmp/dfa949_%d.err", pid);
|
||||
snprintf(cmd, sizeof cmd, "%s/%s %s >%s 2>%s",
|
||||
bin, drv, args, outf, errf);
|
||||
int rc = system(cmd);
|
||||
if (rc == -1) {
|
||||
unlink(outf);
|
||||
unlink(errf);
|
||||
return -1;
|
||||
}
|
||||
rc = WIFEXITED(rc) ? WEXITSTATUS(rc) : 1;
|
||||
read_text(outf, out, outsz);
|
||||
read_text(errf, err, errsz);
|
||||
unlink(outf);
|
||||
unlink(errf);
|
||||
return rc;
|
||||
}
|
||||
|
||||
static int
|
||||
test_version(const char *bin)
|
||||
{
|
||||
char cout[128], cerr[128], wout[128], werr[128], want[128];
|
||||
int crc = run_drv(bin, "ww", "-V", cout, sizeof cout,
|
||||
cerr, sizeof cerr);
|
||||
int wrc = run_drv(bin, "ww_ww", "-V", wout, sizeof wout,
|
||||
werr, sizeof werr);
|
||||
int fail = 0;
|
||||
snprintf(want, sizeof want, "ww %s\n", WW_VERSION);
|
||||
if (crc != 0 || strcmp(cout, want) != 0 || cerr[0] != '\0') {
|
||||
fprintf(stderr, "949 FAIL: ww -V rc=%d stdout='%s' stderr='%s'\n",
|
||||
crc, cout, cerr);
|
||||
fail = 1;
|
||||
}
|
||||
if (wrc != crc || strcmp(wout, cout) != 0 || strcmp(werr, cerr) != 0) {
|
||||
fprintf(stderr, "949 FAIL: ww_ww -V rc=%d stdout='%s' stderr='%s' "
|
||||
"!= ww rc=%d stdout='%s' stderr='%s'\n",
|
||||
wrc, wout, werr, crc, cout, cerr);
|
||||
fail = 1;
|
||||
}
|
||||
return fail;
|
||||
}
|
||||
|
||||
int
|
||||
main(void)
|
||||
{
|
||||
const char *bin = getenv("BIN");
|
||||
if (!bin) bin = "out/bin";
|
||||
char absbin[1024];
|
||||
if (bin[0] != '/') {
|
||||
char cwd[1024];
|
||||
if (getcwd(cwd, sizeof cwd) == NULL) return 1;
|
||||
snprintf(absbin, sizeof absbin, "%s/%s", cwd, bin);
|
||||
bin = absbin;
|
||||
}
|
||||
|
||||
int fail = test_version(bin);
|
||||
size_t n = sizeof rows / sizeof rows[0];
|
||||
for (size_t i = 0; i < n; i++) {
|
||||
char cout[256], cerr[4096], wout[256], werr[4096];
|
||||
int crc = run_drv(bin, "ww", rows[i].args,
|
||||
cout, sizeof cout, cerr, sizeof cerr);
|
||||
int wrc = run_drv(bin, "ww_ww", rows[i].args,
|
||||
wout, sizeof wout, werr, sizeof werr);
|
||||
|
||||
if (crc != rows[i].rc) {
|
||||
fprintf(stderr, "949 FAIL: ww %s rc=%d want=%d\n",
|
||||
rows[i].args, crc, rows[i].rc);
|
||||
fail = 1;
|
||||
}
|
||||
if (!strstr(cerr, rows[i].sub)) {
|
||||
fprintf(stderr, "949 FAIL: ww %s stderr missing '%s' (got '%s')\n",
|
||||
rows[i].args, rows[i].sub, cerr);
|
||||
fail = 1;
|
||||
}
|
||||
/* twin parity: ww_ww must match ww exactly (rc + stderr). */
|
||||
if (wrc != crc) {
|
||||
fprintf(stderr, "949 FAIL: %s ww_ww rc=%d != ww rc=%d\n",
|
||||
rows[i].args, wrc, crc);
|
||||
fail = 1;
|
||||
}
|
||||
if (strcmp(werr, cerr) != 0) {
|
||||
fprintf(stderr, "949 FAIL: %s ww_ww stderr '%s' != ww '%s'\n",
|
||||
rows[i].args, werr, cerr);
|
||||
fail = 1;
|
||||
}
|
||||
if (strcmp(wout, cout) != 0) {
|
||||
fprintf(stderr, "949 FAIL: %s ww_ww stdout '%s' != ww '%s'\n",
|
||||
rows[i].args, wout, cout);
|
||||
fail = 1;
|
||||
}
|
||||
}
|
||||
|
||||
if (fail) return 1;
|
||||
printf("driver version + flag-argument errors: %zu rows, ww==ww_ww pinned\n",
|
||||
n);
|
||||
return 0;
|
||||
}
|
||||
@@ -1,186 +0,0 @@
|
||||
/*
|
||||
* 949_missingpkg — #16 ENFORCE-driver, BOTH branches (rob A inline-aware):
|
||||
* miss — `import nosuchpkg;` with no inline package → the cstage `ww`
|
||||
* driver exits nonzero + "ww: cannot find package nosuchpkg"
|
||||
* (was a silent `continue` masking a typo'd/missing package).
|
||||
* inline — a single-file multi-package unit (`package aa; … package
|
||||
* main; import aa; …`) names a package the bundler can't pull
|
||||
* as a file but the checker binds inline; the locate-miss is
|
||||
* inline-satisfied → ww BUILDS + runs green (exit 7). Pins the
|
||||
* skip branch so the fatal can't regress into over-firing on
|
||||
* the legitimate inline-package import-crutch pattern.
|
||||
*
|
||||
* Cstage driver in a 9xx (rule-14: only WWSTAGE-driver tests are pinned to
|
||||
* 950/990-997). The ww_ww twin + cstage/wwstage parity live in 993_ww_ww.
|
||||
* Fixtures staged in /tmp so driver intermediates never touch the tree.
|
||||
*/
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/wait.h>
|
||||
|
||||
static int
|
||||
runwait(const char *cmd)
|
||||
{
|
||||
int rc = system(cmd);
|
||||
if (rc == -1) return -1;
|
||||
if (WIFEXITED(rc)) return WEXITSTATUS(rc);
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* miss branch: `ww build` a missing import → nonzero + "cannot find
|
||||
* package nosuchpkg" on stderr. Returns 0 on success. */
|
||||
static int
|
||||
run_miss(const char *bin)
|
||||
{
|
||||
char tmpdir[] = "/tmp/mp949_miss_XXXXXX";
|
||||
char src[128], errf[128], outb[128], scratch[144], cmd[2048];
|
||||
char line[4096];
|
||||
if (mkdtemp(tmpdir) == NULL) {
|
||||
fprintf(stderr, "949 FAIL: acquire miss workspace\n");
|
||||
return 1;
|
||||
}
|
||||
/* Source, capture, output, and output-derived .sepwork all live under
|
||||
* this invocation-owned directory. */
|
||||
snprintf(src, sizeof src, "%s/miss.ww", tmpdir);
|
||||
snprintf(errf, sizeof errf, "%s/miss.err", tmpdir);
|
||||
/* -o needs a writable stem inside tmpdir (not /dev/null): the
|
||||
* output-derived .sepwork follows -o, so /dev/null would yield an
|
||||
* uncreatable /dev/null.sepwork and mask the missing-package fatal. */
|
||||
snprintf(outb, sizeof outb, "%s/miss.out", tmpdir);
|
||||
snprintf(scratch, sizeof scratch, "%s.sepwork", outb);
|
||||
int result = 1;
|
||||
FILE *f = fopen(src, "w");
|
||||
if (!f) {
|
||||
fprintf(stderr, "949 FAIL: stage miss\n");
|
||||
goto cleanup;
|
||||
}
|
||||
fputs("package main;\n"
|
||||
"import nosuchpkg;\n"
|
||||
"export fn main() i32 = { return 0; };\n", f);
|
||||
fclose(f);
|
||||
|
||||
snprintf(cmd, sizeof cmd, "%s/ww build %s -o %s 2>%s",
|
||||
bin, src, outb, errf);
|
||||
int rc = runwait(cmd);
|
||||
if (rc == 0) {
|
||||
fprintf(stderr, "949 FAIL: ww accepted a missing import\n");
|
||||
goto cleanup;
|
||||
}
|
||||
int found = 0;
|
||||
f = fopen(errf, "r");
|
||||
if (f) {
|
||||
while (fgets(line, sizeof line, f))
|
||||
if (strstr(line, "cannot find package nosuchpkg")) {
|
||||
found = 1; break;
|
||||
}
|
||||
fclose(f);
|
||||
}
|
||||
if (!found) {
|
||||
fprintf(stderr, "949 FAIL: no 'cannot find package nosuchpkg' "
|
||||
"on stderr\n");
|
||||
goto cleanup;
|
||||
}
|
||||
result = 0;
|
||||
|
||||
cleanup:
|
||||
{
|
||||
int bad = 0;
|
||||
snprintf(cmd, sizeof cmd, "rm -rf %s", scratch);
|
||||
if (runwait(cmd) != 0) bad = 1;
|
||||
if (unlink(outb) != 0 && errno != ENOENT) bad = 1;
|
||||
if (unlink(errf) != 0 && errno != ENOENT) bad = 1;
|
||||
if (unlink(src) != 0 && errno != ENOENT) bad = 1;
|
||||
if (rmdir(tmpdir) != 0) bad = 1;
|
||||
if (bad) {
|
||||
fprintf(stderr, "949 FAIL: cleanup miss workspace\n");
|
||||
result = 1;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/* inline branch: a single-file multi-package unit whose `import aa` is
|
||||
* satisfied by the inline `package aa` must BUILD (locate-miss → inline
|
||||
* scan → skip) and run to exit 7. Returns 0 on success. */
|
||||
static int
|
||||
run_inline(const char *bin)
|
||||
{
|
||||
char tmpdir[] = "/tmp/mp949_inl_XXXXXX";
|
||||
char src[128], outb[128], scratch[144], cmd[2048];
|
||||
if (mkdtemp(tmpdir) == NULL) {
|
||||
fprintf(stderr, "949 FAIL: acquire inline workspace\n");
|
||||
return 1;
|
||||
}
|
||||
/* Source, output, and output-derived .sepwork all live under this
|
||||
* invocation-owned directory. */
|
||||
snprintf(src, sizeof src, "%s/inline.ww", tmpdir);
|
||||
snprintf(outb, sizeof outb, "%s/inline", tmpdir);
|
||||
snprintf(scratch, sizeof scratch, "%s.sepwork", outb);
|
||||
int result = 1;
|
||||
FILE *f = fopen(src, "w");
|
||||
if (!f) {
|
||||
fprintf(stderr, "949 FAIL: stage inline\n");
|
||||
goto cleanup;
|
||||
}
|
||||
fputs("package aa;\n"
|
||||
"export fn getv() i32 = { return 7; };\n"
|
||||
"package main;\n"
|
||||
"import aa;\n"
|
||||
"export fn main() i32 = { return aa.getv(); };\n", f);
|
||||
fclose(f);
|
||||
|
||||
snprintf(cmd, sizeof cmd,
|
||||
"%s/ww build -o %s %s >/dev/null 2>&1", bin, outb, src);
|
||||
int rc = runwait(cmd);
|
||||
if (rc != 0) {
|
||||
fprintf(stderr, "949 FAIL: inline-package build failed "
|
||||
"(inline-skip branch regressed)\n");
|
||||
goto cleanup;
|
||||
}
|
||||
int got = runwait(outb);
|
||||
if (got != 7) {
|
||||
fprintf(stderr, "949 FAIL: inline-package exit=%d want=7\n", got);
|
||||
goto cleanup;
|
||||
}
|
||||
result = 0;
|
||||
|
||||
cleanup:
|
||||
{
|
||||
int bad = 0;
|
||||
snprintf(cmd, sizeof cmd, "rm -rf %s", scratch);
|
||||
if (runwait(cmd) != 0) bad = 1;
|
||||
if (unlink(outb) != 0 && errno != ENOENT) bad = 1;
|
||||
if (unlink(src) != 0 && errno != ENOENT) bad = 1;
|
||||
if (rmdir(tmpdir) != 0) bad = 1;
|
||||
if (bad) {
|
||||
fprintf(stderr, "949 FAIL: cleanup inline workspace\n");
|
||||
result = 1;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
int
|
||||
main(void)
|
||||
{
|
||||
const char *bin = getenv("BIN");
|
||||
if (!bin) bin = "out/bin";
|
||||
char absbin[1024];
|
||||
if (bin[0] != '/') {
|
||||
char cwd[1024];
|
||||
if (getcwd(cwd, sizeof cwd) == NULL) return 1;
|
||||
snprintf(absbin, sizeof absbin, "%s/%s", cwd, bin);
|
||||
bin = absbin;
|
||||
}
|
||||
|
||||
int fail = 0;
|
||||
fail += run_miss(bin);
|
||||
fail += run_inline(bin);
|
||||
if (fail) return 1;
|
||||
printf("missing-package: miss->fatal + inline->skip(build+run) both pinned\n");
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user