test/wcc: carrier ownership repair and driver-contract adaptation
Every surviving carrier now owns its artifacts: checked mkdir/mkdtemp/ fopen acquisition, one all-exit cleanup funnel per carrier, ENOENT- tolerant checked unlinks, exact-path deletion (rm -rf only for an owned pid-keyed dir or a .sepwork beneath one), and cleanup failure fails a passing carrier without overwriting its diagnostic. In the same pass the carriers adapt to the driver contract this branch lands: --sep and WW_PKGCACHE are gone, -S and the /tmp/ww_run_<pid> scratch contract are asserted, and rows whose runtime or reject coverage moved to test/wcc/data fixtures or test/lang @test owners are trimmed to the byte/artifact/diagnostic observations only they can make. Repair and adaptation ride together because most files interleave both in the same hunks; splitting would manufacture intermediate carrier states that never existed and cannot run against either driver.
This commit is contained in:
@@ -41,15 +41,15 @@
|
||||
* neg_forrange_tuple_dup | build fails | site 1505
|
||||
* neg_param_dup | build fails | site 1914
|
||||
* neg_toplet_dup | build fails | site 1880
|
||||
* pos_nested_block_shadow | exit=1 | scope boundary
|
||||
* pos_nested_shadow_typed | exit=2 | (name,type) — bucket
|
||||
* | | keys by name only
|
||||
* pos_forrange_body_shadow | exit=99 | for body N_BLOCK
|
||||
* | | opens a fresh scope
|
||||
* pos_mcase_per_arm | exit=7 | match arm scope
|
||||
* The four legal-shadow positive rows are owned by the directive fixtures
|
||||
* under test/wcc/data/r71_redecl_*. This residual wrapper intentionally owns
|
||||
* only the six C-stage-only rejects below: wwstage lacks per-block scoping,
|
||||
* so these cannot be represented by the symmetric //ww:error contract.
|
||||
*/
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <errno.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/wait.h>
|
||||
@@ -64,167 +64,128 @@ runwait(const char *cmd)
|
||||
return -1;
|
||||
}
|
||||
|
||||
/*
|
||||
* kind == 0: negative — build must fail (any nonzero exit).
|
||||
* kind == 1: positive — build must succeed AND binary exits with `want`.
|
||||
*/
|
||||
struct row { const char *label; int kind; const char *src; int want; };
|
||||
struct row { const char *label; const char *src; };
|
||||
|
||||
static const struct row rows[] = {
|
||||
/* neg: site 1443 — block-body let dup. */
|
||||
{ "neg_let_same_block", 0,
|
||||
{ "neg_let_same_block",
|
||||
"fn main() i32 = {\n"
|
||||
" let a: i32 = 1;\n"
|
||||
" let a: i32 = 2;\n"
|
||||
" return a;\n"
|
||||
"};\n",
|
||||
0 },
|
||||
"};\n" },
|
||||
|
||||
/* neg: site 1562 — mlet shadows earlier same-block let. */
|
||||
{ "neg_mlet_same_block", 0,
|
||||
{ "neg_mlet_same_block",
|
||||
"fn pair() (i32, i32) = { return (10, 20); };\n"
|
||||
"fn main() i32 = {\n"
|
||||
" let a: i32 = 1;\n"
|
||||
" let (a, b) = pair();\n"
|
||||
" return a + b;\n"
|
||||
"};\n",
|
||||
0 },
|
||||
"};\n" },
|
||||
|
||||
/* neg: site 1562 — mlet pattern lists the same name twice. */
|
||||
{ "neg_mlet_tuple_dup", 0,
|
||||
{ "neg_mlet_tuple_dup",
|
||||
"fn pair() (i32, i32) = { return (10, 20); };\n"
|
||||
"fn main() i32 = {\n"
|
||||
" let (a, a) = pair();\n"
|
||||
" return a;\n"
|
||||
"};\n",
|
||||
0 },
|
||||
"};\n" },
|
||||
|
||||
/* neg: site 1505 — forrange tuple-pattern lists same name twice. */
|
||||
{ "neg_forrange_tuple_dup", 0,
|
||||
{ "neg_forrange_tuple_dup",
|
||||
"fn main() i32 = {\n"
|
||||
" let xs: [1](i32, i32) = [(10i32, 20i32)];\n"
|
||||
" for (let (a, a) .. xs) {\n"
|
||||
" return a;\n"
|
||||
" };\n"
|
||||
" return -1;\n"
|
||||
"};\n",
|
||||
0 },
|
||||
"};\n" },
|
||||
|
||||
/* neg: site 1914 — two params with the same name. */
|
||||
{ "neg_param_dup", 0,
|
||||
{ "neg_param_dup",
|
||||
"fn f(a: i32, a: i32) i32 = { return a; };\n"
|
||||
"fn main() i32 = { return f(1, 2); };\n",
|
||||
0 },
|
||||
"fn main() i32 = { return f(1, 2); };\n" },
|
||||
|
||||
/* neg: site 1880 — top-level let dup. */
|
||||
{ "neg_toplet_dup", 0,
|
||||
{ "neg_toplet_dup",
|
||||
"let x: i32 = 1;\n"
|
||||
"let x: i32 = 2;\n"
|
||||
"fn main() i32 = { return x; };\n",
|
||||
0 },
|
||||
|
||||
/* pos: nested-block shadow stays legal. Inner block opens a
|
||||
* fresh scope, scope_define's per-scope hash bucket isolates the
|
||||
* inner `a` from the outer one. Outer `a` untouched after the
|
||||
* inner block exits. */
|
||||
{ "pos_nested_block_shadow", 1,
|
||||
"fn main() i32 = {\n"
|
||||
" let a: i32 = 1;\n"
|
||||
" {\n"
|
||||
" let a: i32 = 99;\n"
|
||||
" };\n"
|
||||
" return a;\n"
|
||||
"};\n",
|
||||
1 },
|
||||
|
||||
/* pos: nested-block shadow with a different type. Confirms the
|
||||
* scope-bucket key is the name alone, not (name, type) — the
|
||||
* inner `s: str` does NOT collide with the outer `s: i32`. */
|
||||
{ "pos_nested_shadow_typed", 1,
|
||||
"fn main() i32 = {\n"
|
||||
" let s: i32 = 2;\n"
|
||||
" {\n"
|
||||
" let s: str = \"hi\";\n"
|
||||
" let _ = s;\n"
|
||||
" };\n"
|
||||
" return s;\n"
|
||||
"};\n",
|
||||
2 },
|
||||
|
||||
/* pos: for-loop body N_BLOCK opens a fresh scope, so a `let x`
|
||||
* inside the body doesn't collide with the for-range's binding
|
||||
* `x` (which lives in the per-loop scope, one level above). */
|
||||
{ "pos_forrange_body_shadow", 1,
|
||||
"fn main() i32 = {\n"
|
||||
" let arr: [1]i32 = [42i32];\n"
|
||||
" let r: i32 = 0;\n"
|
||||
" for (let x .. arr) {\n"
|
||||
" let x: i32 = 99;\n"
|
||||
" r = x;\n"
|
||||
" };\n"
|
||||
" return r;\n"
|
||||
"};\n",
|
||||
99 },
|
||||
|
||||
/* pos: each match arm is its own scope, so two arms each
|
||||
* binding `v` don't collide. Pre-#32 this was already legal
|
||||
* (newscope wrapper at check.c:1186); pinned here so a future
|
||||
* scope-tightening can't quietly remove that wrapper. */
|
||||
{ "pos_mcase_per_arm", 1,
|
||||
"type T = (i32 | f64);\n"
|
||||
"fn main() i32 = {\n"
|
||||
" let t: T = 7i32;\n"
|
||||
" match (t) {\n"
|
||||
" case let v: i32 => { return v; };\n"
|
||||
" case let v: f64 => { return -1; };\n"
|
||||
" };\n"
|
||||
"};\n",
|
||||
7 },
|
||||
"fn main() i32 = { return x; };\n" },
|
||||
};
|
||||
|
||||
static int
|
||||
run_row(const char *driver, const struct row *r, int i)
|
||||
{
|
||||
char src[128], tmpdir[128], outbin[128], rmcmd[160], cmd[2048];
|
||||
char src[128], tmpdir[128], outbin[128], sepdir[160], rmcmd[192];
|
||||
char cmd[2048];
|
||||
snprintf(tmpdir, sizeof tmpdir, "/tmp/wcredecl_%d_d_%d", getpid(), i);
|
||||
mkdir(tmpdir, 0755);
|
||||
if (mkdir(tmpdir, 0755) != 0) {
|
||||
fprintf(stderr, "redecl[%s]: mkdir %s: %s\n",
|
||||
r->label, tmpdir, strerror(errno));
|
||||
return -1;
|
||||
}
|
||||
snprintf(src, sizeof src, "%s/wcredecl_%d_%d.ww", tmpdir, getpid(), i);
|
||||
snprintf(outbin, sizeof outbin, "%s/wcredecl_%d_%d", tmpdir, getpid(), i);
|
||||
snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", tmpdir);
|
||||
snprintf(sepdir, sizeof sepdir, "%s.sepwork", outbin);
|
||||
snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", sepdir);
|
||||
int failed = 0, rc;
|
||||
|
||||
FILE *f = fopen(src, "wb");
|
||||
if (!f) { runwait(rmcmd); return -1; }
|
||||
if (!f) {
|
||||
fprintf(stderr, "redecl[%s]: fopen %s: %s\n",
|
||||
r->label, src, strerror(errno));
|
||||
failed = 1;
|
||||
goto cleanup;
|
||||
}
|
||||
wwtest_fputs(r->src, f);
|
||||
fclose(f);
|
||||
if (ferror(f)) {
|
||||
fprintf(stderr, "redecl[%s]: write %s failed\n", r->label, src);
|
||||
failed = 1;
|
||||
}
|
||||
if (fclose(f) != 0) {
|
||||
fprintf(stderr, "redecl[%s]: close %s: %s\n",
|
||||
r->label, src, strerror(errno));
|
||||
failed = 1;
|
||||
}
|
||||
if (failed) goto cleanup;
|
||||
|
||||
snprintf(cmd, sizeof cmd, "%s build -o %s %s >/dev/null 2>&1",
|
||||
driver, outbin, src);
|
||||
int rc = runwait(cmd);
|
||||
rc = runwait(cmd);
|
||||
|
||||
if (r->kind == 0) {
|
||||
/* Negative — build must fail. */
|
||||
if (rc == 0)
|
||||
fprintf(stderr,
|
||||
"redecl[%s]: build unexpectedly succeeded\n",
|
||||
r->label);
|
||||
runwait(rmcmd);
|
||||
return rc == 0 ? -1 : 0;
|
||||
if (rc == 0) {
|
||||
fprintf(stderr, "redecl[%s]: build unexpectedly succeeded\n",
|
||||
r->label);
|
||||
failed = 1;
|
||||
}
|
||||
|
||||
/* Positive — build then run. */
|
||||
if (rc != 0) {
|
||||
fprintf(stderr, "redecl[%s]: build failed\n", r->label);
|
||||
runwait(rmcmd);
|
||||
return -1;
|
||||
cleanup:
|
||||
{
|
||||
int cleanup_failed = 0;
|
||||
if (runwait(rmcmd) != 0) {
|
||||
fprintf(stderr, "redecl[%s]: remove %s failed\n",
|
||||
r->label, sepdir);
|
||||
cleanup_failed = 1;
|
||||
}
|
||||
if (unlink(src) != 0 && errno != ENOENT) {
|
||||
fprintf(stderr, "redecl[%s]: unlink %s: %s\n",
|
||||
r->label, src, strerror(errno));
|
||||
cleanup_failed = 1;
|
||||
}
|
||||
if (unlink(outbin) != 0 && errno != ENOENT) {
|
||||
fprintf(stderr, "redecl[%s]: unlink %s: %s\n",
|
||||
r->label, outbin, strerror(errno));
|
||||
cleanup_failed = 1;
|
||||
}
|
||||
if (rmdir(tmpdir) != 0) {
|
||||
fprintf(stderr, "redecl[%s]: rmdir %s: %s\n",
|
||||
r->label, tmpdir, strerror(errno));
|
||||
cleanup_failed = 1;
|
||||
}
|
||||
if (!failed && cleanup_failed) failed = 1;
|
||||
}
|
||||
int got = runwait(outbin);
|
||||
runwait(rmcmd);
|
||||
if (got != r->want) {
|
||||
fprintf(stderr, "redecl[%s]: exit=%d want=%d\n",
|
||||
r->label, got, r->want);
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
return failed ? -1 : 0;
|
||||
}
|
||||
|
||||
int
|
||||
|
||||
Reference in New Issue
Block a user