| 1 | // Shared plumbing for the per-platform Go test lanes. Group membership stays |
| 2 | // with each platform: Windows needs isolated groups and an explicit -p for |
| 3 | // Defender, macOS only needs the darwin-specific packages. Only the package |
| 4 | // listing, the prefix test and the runner are common. |
| 5 | import { spawnSync } from "node:child_process"; |
| 6 | |
| 7 | export const beneath = (pkg, root) => pkg === root || pkg.startsWith(`${root}/`); |
| 8 | |
| 9 | export const internalRoots = (...names) => names.map(name => `reasonix/internal/${name}`); |
| 10 | |
| 11 | /** `go list ./...`, or `{packages: null}` with the listing's own exit status. */ |
| 12 | export function listPackages() { |
| 13 | const listed = spawnSync("go", ["list", "./..."], { encoding: "utf8" }); |
| 14 | if (listed.error) throw listed.error; |
| 15 | if (listed.status !== 0) { |
| 16 | process.stderr.write(listed.stderr || "go list failed\n"); |
| 17 | return { packages: null, status: listed.status ?? 1 }; |
| 18 | } |
| 19 | return { packages: listed.stdout.trim().split(/\r?\n/).filter(Boolean), status: 0 }; |
| 20 | } |
| 21 | |
| 22 | export function runGoTest(label, selected, args) { |
| 23 | console.log(`${label}: ${selected.length} packages; go ${args.join(" ")}`); |
| 24 | const result = spawnSync("go", args, { stdio: "inherit" }); |
| 25 | if (result.error) throw result.error; |
| 26 | return result.status ?? 1; |
| 27 | } |
| 28 |