compiler: support package test runtime aliases

This commit is contained in:
2026-08-12 03:46:28 +09:00
parent 0ac0fd68ec
commit e59881cb30
7 changed files with 92 additions and 50 deletions

View File

@@ -46,6 +46,9 @@ export type parser = struct {
// rule stay intact), and the in-file `package` clause asserts (leaf ==
// last component) instead of overwriting curmod. "" means inactive.
resetmod: str,
// Hidden package-driver alias for the toolchain `package test` source.
// Empty outside that one separate-compilation edge.
testmodule: str,
};
fn refill(p: *parser) void = {
@@ -67,6 +70,7 @@ export fn parserinit(p: *parser, l: *lex) void = {
p.nocast = 0;
p.pathmod = "";
p.resetmod = "";
p.testmodule = "";
refill(p);
};
@@ -611,7 +615,11 @@ export fn parsefile(p: *parser) *node = {
let (pre, post) = strings.rcut(active, ".");
let last: str = post;
if (post.len == 0) { last = active; };
if (strings.compare(name, last) != 0) {
let testsupport: bool = strings.compare(
p.testmodule, "__wwtest") == 0
&& strings.compare(active, "__wwtest") == 0
&& strings.compare(name, "test") == 0;
if (strings.compare(name, last) != 0 && !testsupport) {
errmsg(p, "package does not match import path");
};
} else {