Add exit code expectations and fix @setup validation

This commit is contained in:
Chris Wanstrath 2026-03-10 10:20:23 -07:00
parent 0a1100aaf7
commit aeef6041ec
2 changed files with 18 additions and 3 deletions

View File

@ -142,11 +142,22 @@ $ true
// Check setup commands for failures // Check setup commands for failures
for (let i = 0; i < setupCommands.length; i++) { for (let i = 0; i < setupCommands.length; i++) {
const r = fileResult.results[i] const r = fileResult.results[i]
if (r && r.exitCode !== 0) { const expected = setupCommands[i]!.exitCode
const ok = expected === null
? r?.exitCode === 0
: expected === "*"
? r?.exitCode !== 0
: r?.exitCode === expected
if (!ok) {
if (opts.keep) {
process.stderr.write(`${fileResult.tmpDir}\n`)
} else {
await cleanupTmpDir(fileResult.tmpDir)
}
return evaluateFile( return evaluateFile(
parsed.path, parsed.path,
[], [],
`setup command failed (exit ${r.exitCode}): $ ${setupCommands[i]!.command}`, `setup command failed (exit ${r?.exitCode ?? "?"}): $ ${setupCommands[i]!.command}`,
) )
} }
} }

View File

@ -72,7 +72,11 @@ export function parse(path: string, content: string): ShoutFile {
if (!seenCommand && line.startsWith("@")) { if (!seenCommand && line.startsWith("@")) {
if (line.startsWith("@setup ")) { if (line.startsWith("@setup ")) {
directives.push({ type: "setup", path: line.slice(7).trim(), line: i + 1 }) const setupPath = line.slice(7).trim()
if (!setupPath) {
throw new Error(`${path}:${i + 1}: @setup requires a file path`)
}
directives.push({ type: "setup", path: setupPath, line: i + 1 })
} else if (line.startsWith("@env ")) { } else if (line.startsWith("@env ")) {
const rest = line.slice(5).trim() const rest = line.slice(5).trim()
const eq = rest.indexOf("=") const eq = rest.indexOf("=")