ww: package-level -c -o names the single package's test artifact

The last Open-driver-work bullet. `-c -o <name>` replaces the fixed
<package>.test stem for exactly one package; the coordinator rejects a
multi-package fan-out ("cannot use -o with multiple packages", Go's
`go test -o` rule) and -o without -c is rejected at the driver
("needs -c for a package target" — a plain run executes from the temp
root, so a caller-owned name has nothing to name). Both driver stages
byte-identical wording; -S keeps its single-file-only reject.

package_test gains the contract row (naming, fixed-stem absence,
artifact runs, both rejects, both drivers); the tree-mode -o row's
pinned wording follows the contract.
This commit is contained in:
2026-08-08 17:30:36 +09:00
parent cf90c50c38
commit 192ddd4c66
5 changed files with 150 additions and 22 deletions

View File

@@ -569,7 +569,8 @@ fn packagepath(relative: str) str = {
expectexit(&outc, 2);
expectexit(&outw, 2);
assert(same(outc.stderr, outw.stderr));
assert(has(outc.stderr, "ww test: -c/-S/-o need a single test file\n"));
assert(has(outc.stderr,
"ww test: -o needs -c for a package target\n"));
let wdc: []str = [driver("ww"), "test", "-w", root, spec];
let wdw: []str = [driver("ww_ww"), "test", "-w", root, spec];
@@ -775,3 +776,72 @@ fn runtimepath(relative: str) str = {
"escaped_writer_does_not_hold_runner ... ok\n"));
clean(root);
};
// The package-level -o contract: -c -o names the single package's
// artifact in place of the fixed <package>.test stem; -o without -c
// has nothing to name (runs execute from the temp root); one name
// cannot fan out over multiple packages (Go's `go test -o` rule).
@test fn compile_artifact_naming() void = {
let root: str = fresh();
let pdir: str = strings.concat(root, "/pkg");
assert(os.mkdir(pdir, 493i32) == 0);
writefile(strings.concat(pdir, "/pkg.ww"),
"package pkg;\nexport fn v() i32 = { return 7; };\n");
writefile(strings.concat(pdir, "/pkg_test.ww"), strings.concat(
"package pkg_test;\nimport pkg;\n",
"@test fn seven() void = { assert(pkg.v() == 7); };\n"));
let adir: str = strings.concat(root, "/a");
assert(os.mkdir(adir, 493i32) == 0);
// '_'-prefixed: the tree walk skips it, so the artifacts and
// their .sepwork trees never pollute the multi-package discovery.
let outdir: str = strings.concat(root, "/_out");
assert(os.mkdir(outdir, 493i32) == 0);
writefile(strings.concat(adir, "/a.ww"),
"package a;\nexport fn v() i32 = { return 1; };\n");
writefile(strings.concat(adir, "/a_test.ww"), strings.concat(
"package a_test;\nimport a;\n",
"@test fn one() void = { assert(a.v() == 1); };\n"));
let out: commandout;
let drvs: []str = ["ww", "ww_ww"];
let i: i32 = 0;
for (i < 2) {
let named: str = strings.concat(outdir, "/out_", drvs[i],
".bin");
let coav: []str = [driver(drvs[i]), "test", "-c", "-o",
named, pdir];
runcommand(root, strings.concat("nameco_", drvs[i]), coav,
(30i64 * (time.second: i64)): time.duration, &out);
expectexit(&out, 0);
let fi: os.filestat;
match (os.stat(&fi, named)) {
case void => void;
case let e: os.oserror => abort("-c -o artifact missing");
};
match (os.stat(&fi, strings.concat(pdir, "/pkg.test"))) {
case void => abort("-c -o still published the fixed stem");
case let e: os.oserror => void;
};
let runav: []str = [named];
runcommand(root, strings.concat("namerun_", drvs[i]), runav,
(30i64 * (time.second: i64)): time.duration, &out);
expectexit(&out, 0);
assert(has(out.stdout, "seven ... ok"));
let nocav: []str = [driver(drvs[i]), "test", "-o", named,
pdir];
runcommand(root, strings.concat("noc_", drvs[i]), nocav,
(30i64 * (time.second: i64)): time.duration, &out);
expectexit(&out, 2);
assert(has(out.stderr, "-o needs -c for a package target"));
let mulav: []str = [driver(drvs[i]), "test", "-c", "-o",
named, strings.concat(root, "/...")];
runcommand(root, strings.concat("multi_", drvs[i]), mulav,
(30i64 * (time.second: i64)): time.duration, &out);
expectexit(&out, 2);
assert(has(out.stderr,
"cannot use -o with multiple packages"));
i += 1;
};
clean(root);
};