Files
ww/test/xmod/modreset_test.ww

82 lines
3.0 KiB
Plaintext

package modreset_test;
// BUG-A (#9) regression pin: the lexer must not leave a stale
// TK_MODPATH pending past a `//ww:module-reset`. Port of the retired
// native carrier test/wcc/989_modresetadj_run.c; every assertion
// preserved.
//
// The composed sep-unit puts `//ww:module e` and `//ww:module-reset`
// in ONE skipws run with no real token between (the shape the sep
// driver emits for an empty/export-less inlined module body); pre-fix
// the stale modpath=e survived the reset and `package main` was
// rejected against import path "e". The unit is fed STRAIGHT to
// w6c/w6c_ww: the natural empty-module dir route trips the separate
// #11 wwi_emit bug first, and the driver cannot locate the phantom
// directive owner e (which is also why the corpus cannot host it -- the
// blanket data byte-id gate drives every non-error fixture through
// `ww build`).
//
// Legs: (1) w6c accepts the adjacency (pre-fix REJECT -- the teeth);
// (2) w6c_ww accepts it (rule-10 twin); (3a) the two .s are
// byte-identical; (3b) assemble+link+run to exit 42 (the emitted code
// is valid, not just parse-clean).
import os;
import os.exec;
import strings;
import testenv;
import time;
fn fail(why: str) void = {
let m: str = strings.concat("modreset FAIL: ", why, "\n");
os.write(2, m.ptr, m.len: u64);
assert(false);
};
fn tmo() time.duration = {
return (240i64 * (time.second: i64)): time.duration;
};
// -1 encodes an abnormal (non-EXIT) termination, never a valid code.
fn runcode(dir: str, name: str, argv: []str) i32 = {
let co: testenv.commandout;
testenv.runcommand(dir, dir, name, argv, tmo(), &co);
if (co.termination != exec.termination.EXIT) { return -1; };
return co.code;
};
@test fn modresetadj() void = {
let td: str = testenv.fresh();
let unit: str = strings.concat(td, "/mradj.unit.ww");
testenv.writefile(unit, strings.concat(
"//ww:module e\n",
"//ww:module-reset\n",
"package main;\n",
"export fn main() i32 = { return 42; };\n"));
let scs: str = strings.concat(td, "/cs.s");
let sww: str = strings.concat(td, "/ww.s");
let cav: []str = [testenv.driver("w6c"), "-c", "-o", scs, unit];
if (runcode(td, "w6c", cav) != 0) {
fail("w6c rejected the adjacency unit (BUG-A stale modpath)");
};
let wav: []str = [testenv.driver("w6c_ww"), "-c", "-o", sww, unit];
if (runcode(td, "w6c_ww", wav) != 0) {
fail("w6c_ww rejected the adjacency unit (BUG-A)");
};
if (!testenv.same(testenv.readfile(scs), testenv.readfile(sww))) {
fail("w6c vs w6c_ww .s differ (rule 10)");
};
let obj: str = strings.concat(td, "/mradj.o");
let aav: []str = [testenv.driver("w6a"), "-o", obj, scs];
if (runcode(td, "w6a", aav) != 0) { fail("w6a errored"); };
let prog: str = strings.concat(td, "/mradj.bin");
let lav: []str = [testenv.driver("w6l"), "-o", prog, obj,
strings.concat(testenv.repo(), "/out/lib/libwwrt.a")];
if (runcode(td, "w6l", lav) != 0) { fail("w6l errored"); };
let rav: []str = [prog];
if (runcode(td, "run", rav) != 42) {
fail("program exit != 42 (main did not run to its return)");
};
testenv.clean(td);
};