From aeef6041ec39af34ee999f040f5e0849d9793c26 Mon Sep 17 00:00:00 2001 From: Chris Wanstrath Date: Tue, 10 Mar 2026 10:20:23 -0700 Subject: [PATCH] Add exit code expectations and fix @setup validation --- src/cli/index.ts | 15 +++++++++++++-- src/parse.ts | 6 +++++- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/src/cli/index.ts b/src/cli/index.ts index f73bf30..eff10c6 100755 --- a/src/cli/index.ts +++ b/src/cli/index.ts @@ -142,11 +142,22 @@ $ true // Check setup commands for failures for (let i = 0; i < setupCommands.length; 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( parsed.path, [], - `setup command failed (exit ${r.exitCode}): $ ${setupCommands[i]!.command}`, + `setup command failed (exit ${r?.exitCode ?? "?"}): $ ${setupCommands[i]!.command}`, ) } } diff --git a/src/parse.ts b/src/parse.ts index 615204a..94cb20c 100644 --- a/src/parse.ts +++ b/src/parse.ts @@ -72,7 +72,11 @@ export function parse(path: string, content: string): ShoutFile { if (!seenCommand && line.startsWith("@")) { 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 ")) { const rest = line.slice(5).trim() const eq = rest.indexOf("=")