Files
ww/test/misc/stampdiag_test.ww
Hojun-Cho 83f5956df2 test: banner purge + WHY-only comment sweep (rule 8)
Every section banner dies (103 -> 0) across test/lang, the observer
suites, the C carriers, and the five comment-heavy corpus fixtures;
banner provenance (#N cites, carrier numbers, repair-cluster labels)
folded into headers or adjacent WHY comments. Narration deleted; row
provenance, ref cites, divergence pins, and layout contracts kept
(fwd-ref decl-order guards and bootstrap-gate corpus rationale
restored where the sweep over-cut). Comment-only proven: all 3742
wwbuild workdir .s byte-identical before/after; test-commit and
test-byteid (161 lang + 1399 data, 0 pinned-divergent) green.
2026-08-08 21:40:23 +09:00

183 lines
5.9 KiB
Plaintext

package stampdiag_test;
// Shared wwstage stamp-diagnostic observer: w6c_ww must compile each
// row cleanly AND emit NO `asserttyped` diagnostic on its stderr —
// the #121 A-narrow checker-stamp net over destructure bindings. Port
// of the retired native carriers test/wcc/954_tuprecv_run.c,
// test/wcc/956_tuprecv_f64_run.c and test/wcc/956_modqualdestr_run.c.
// wwstage-only by construction: cstage check.c has no asserttyped
// walker, so the probe drives the *_ww binary directly (project
// memory: audit wwstage checker behavior with *_ww binaries, never
// cstage w6c).
//
// The value rows and cs==ww byte-id dimensions are owned elsewhere:
// test/lang/tuprecv_test.ww (954), test/lang/tuprecv_f64_test.ww
// (956_tuprecv_f64) plus the test-lang-byteid blanket, and the
// r956_modqual_* fixtures plus the test-data-byteid blanket
// (956_modqualdestr) — the modqual rows below compile those fixture
// files IN PLACE so probe and fixture can never drift. Only the
// stderr stamp-absence dimension lives here (fixtures check exit
// only; asserttyped is a non-fatal stderr diagnostic).
//
// Non-vacuity (drew C4 mutation gate): the same `has` predicate that
// gates every row must FIRE on a literal asserttyped line, asserted
// up front — a broken predicate fails before any row runs.
import os;
import os.exec;
import strings;
import testenv;
import time;
fn fail(label: str, why: str) void = {
let m: str = strings.concat("stampdiag FAIL: ", label, " -- ", why,
"\n");
os.write(2, m.ptr, m.len: u64);
assert(false);
};
fn tmo() time.duration = {
return (180i64 * (time.second: i64)): time.duration;
};
fn selfcheck() void = {
assert(testenv.has("error: asserttyped: e.type_ nil",
"asserttyped"));
};
fn stampprobe(label: str, srcpath: str) void = {
let td: str = testenv.fresh();
let av: []str = [testenv.driver("w6c_ww"), "-o", "/dev/null",
srcpath];
let co: testenv.commandout;
testenv.runcommand(td, td, "probe", av, tmo(), &co);
if (co.termination != exec.termination.EXIT || co.code != 0) {
fail(label, "w6c_ww stamp probe failed to compile");
};
if (testenv.has(co.stderr, "asserttyped")) {
fail(label, strings.concat("w6c_ww emitted asserttyped ",
"(binding unstamped -- #121 stamp net)"));
};
testenv.clean(td);
};
fn stamprow(label: str, src: str) void = {
let td: str = testenv.fresh();
let srcpath: str = strings.concat(td, "/case.ww");
testenv.writefile(srcpath, src);
stampprobe(label, srcpath);
testenv.clean(td);
};
// 954: the un-annotated float-destructure receive of a 16B tuple.
@test fn tuprecvstamp() void = {
selfcheck();
stamprow("ctl_destr", strings.concat(
"package main;\n",
"fn mk() (f64, i64) = { return (2.5, 7); };\n",
"export fn main() i32 = {\n",
"\tlet (f, i) = mk();\n",
"\treturn (f: i32) + (i: i32);\n",
"};\n"));
};
// 956_tuprecv_f64: branched callees so register coincidence cannot
// mask a wrong-class receive.
@test fn tuprecvf64stamp() void = {
selfcheck();
stamprow("destr_f64_i64_br", strings.concat(
"package main;\n",
"fn issub(n: f64) bool = { return false; };\n",
"fn norm(n: f64) (f64, i64) = {\n",
"\tif (issub(n)) { return (n*2.0, -52); };\n",
"\treturn (n, 0);\n",
"};\n",
"export fn main() i32 = {\n",
"\tlet (m, i) = norm(16.0);\n",
"\tif (m != 16.0) { return 1; };\n",
"\tif (i != 0) { return 2; };\n",
"\treturn 0;\n",
"};\n"));
stamprow("destr_i64_f64_br", strings.concat(
"package main;\n",
"fn issub(n: f64) bool = { return false; };\n",
"fn norm(n: f64) (i64, f64) = {\n",
"\tif (issub(n)) { return (-52, n*2.0); };\n",
"\treturn (0, n);\n",
"};\n",
"export fn main() i32 = {\n",
"\tlet (i, m) = norm(16.0);\n",
"\tif (m != 16.0) { return 1; };\n",
"\tif (i != 0) { return 2; };\n",
"\treturn 0;\n",
"};\n"));
stamprow("f64f64_destr_br", strings.concat(
"package main;\n",
"fn issub(n: f64) bool = { return false; };\n",
"fn pair(a: f64, b: f64) (f64, f64) = {\n",
"\tif (issub(a)) { return (a*2.0, b*2.0); };\n",
"\treturn (a, b);\n",
"};\n",
"export fn main() i32 = {\n",
"\tlet (x, y) = pair(3.0, 5.0);\n",
"\tif (x != 3.0) { return 1; };\n",
"\tif (y != 5.0) { return 2; };\n",
"\treturn 0;\n",
"};\n"));
stamprow("i64_f64_i64_destr", strings.concat(
"package main;\n",
"fn issub(n: i64) bool = { return false; };\n",
"fn tri(a: i64, b: f64, c: i64) (i64, f64, i64) = {\n",
"\tif (issub(a)) { return (a*2, b*2.0, c*2); };\n",
"\treturn (a, b, c);\n",
"};\n",
"export fn main() i32 = {\n",
"\tlet (x, y, z) = tri(3, 2.0, 7);\n",
"\tif (x != 3) { return 1; };\n",
"\tif (y != 2.0) { return 2; };\n",
"\tif (z != 7) { return 3; };\n",
"\treturn 0;\n",
"};\n"));
stamprow("f64_str_destr", strings.concat(
"package main;\n",
"fn issub(n: f64) bool = { return false; };\n",
"fn fs(n: f64) (f64, str) = {\n",
"\tif (issub(n)) { return (n*2.0, \"x\"); };\n",
"\treturn (n, \"hello\");\n",
"};\n",
"export fn main() i32 = {\n",
"\tlet (f, s) = fs(4.0);\n",
"\tif (f != 4.0) { return 1; };\n",
"\tif (s.len != 5) { return 2; };\n",
"\treturn 0;\n",
"};\n"));
stamprow("str_f64_destr", strings.concat(
"package main;\n",
"fn issub(n: f64) bool = { return false; };\n",
"fn sf(n: f64) (str, f64) = {\n",
"\tif (issub(n)) { return (\"x\", n*2.0); };\n",
"\treturn (\"hello\", n);\n",
"};\n",
"export fn main() i32 = {\n",
"\tlet (s, f) = sf(4.0);\n",
"\tif (s.len != 5) { return 1; };\n",
"\tif (f != 4.0) { return 2; };\n",
"\treturn 0;\n",
"};\n"));
};
// 956_modqualdestr (#6a-A): module-qualified destructure bindings —
// N_DOT callees — must carry the stamp too, plus the non-destructure
// same-leaf shadow class-closure row.
@test fn modqualstamp() void = {
selfcheck();
let names: []str = ["mq_f64_i64_destr", "mq_i64_bool_destr",
"mq_f64_str_destr", "mq_nondestr_shadow"];
let i: i32 = 0;
for (i < names.len) {
stampprobe(names[i], strings.concat(testenv.repo(),
"/test/wcc/data/r956_modqual_", names[i], "/case.ww"));
i += 1;
};
};