diff --git a/CLAUDE.md b/CLAUDE.md index 91ea242..f38af9c 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -23,6 +23,7 @@ Transcript-based shell integration test runner. Bun + TypeScript. - `src/match.ts` — wildcard-aware output matching and diff generation - `src/format.ts` — evaluates pass/fail, formats failures and summary - `src/update.ts` — rewrites `.shout` files with actual output (`--update` mode) +- `src/utils.ts` — shared utilities (`trimTrailingEmpty`, `escapeRegex`) - `src/duration.ts` — parses duration strings (`10s`, `500ms`, `1m`) - `src/cli/index.ts` — CLI entry point via `commander` - `src/index.ts` — barrel exports diff --git a/bun.lock b/bun.lock index 0f05d9c..f147370 100644 --- a/bun.lock +++ b/bun.lock @@ -12,8 +12,6 @@ "devDependencies": { "@types/bun": "latest", "@types/diff": "^8.0.0", - }, - "peerDependencies": { "typescript": "^5.9.3", }, }, diff --git a/index.ts b/index.ts deleted file mode 100644 index f67b2c6..0000000 --- a/index.ts +++ /dev/null @@ -1 +0,0 @@ -console.log("Hello via Bun!"); \ No newline at end of file diff --git a/package.json b/package.json index a8505d5..8c65d52 100644 --- a/package.json +++ b/package.json @@ -15,19 +15,12 @@ }, "scripts": { "check": "bunx tsc --noEmit", - "build": "./scripts/build.sh", - "cli:build": "bun run scripts/build.ts", - "cli:build:all": "bun run scripts/build.ts --all", - "cli:install": "bun cli:build && sudo cp dist/shout /usr/local/bin", "cli:link": "ln -sf $(pwd)/src/cli/index.ts ~/.bun/bin/shout", - "cli:uninstall": "sudo rm /usr/local/bin", "test": "bun test" }, "devDependencies": { "@types/bun": "latest", - "@types/diff": "^8.0.0" - }, - "peerDependencies": { + "@types/diff": "^8.0.0", "typescript": "^5.9.3" }, "dependencies": { diff --git a/src/cli/index.ts b/src/cli/index.ts index 8f03f05..2140ee8 100755 --- a/src/cli/index.ts +++ b/src/cli/index.ts @@ -139,7 +139,6 @@ program sourceDir: resolve(dirname(filePath)), projectDir: cwd, timeout: timeoutMs, - verbose: opts.verbose ?? false, onCommand: opts.verbose ? (cmd) => process.stderr.write(ansis.dim(` $ ${cmd.command}\n`)) : undefined, diff --git a/src/format.ts b/src/format.ts index 352c7b2..87e33a2 100644 --- a/src/format.ts +++ b/src/format.ts @@ -72,20 +72,21 @@ export function formatFailure(test: TestResult): string { lines.push(` ${ansis.dim("$")} ${failure.result.command.command}`) if (failure.diffLines.length > 0) { - lines.push(ansis.red(" expected:")) + const expectedLines: string[] = [] + const actualLines: string[] = [] for (const dl of failure.diffLines) { + const text = dl.kind === "context" ? ansis.dim(dl.text) : dl.text if (dl.kind === "expected" || dl.kind === "equal" || dl.kind === "context") { const prefix = dl.kind === "expected" ? ansis.red(" > ") : " " - lines.push(`${prefix}${dl.kind === "context" ? ansis.dim(dl.text) : dl.text}`) + expectedLines.push(`${prefix}${text}`) } - } - lines.push(ansis.green(" actual:")) - for (const dl of failure.diffLines) { if (dl.kind === "actual" || dl.kind === "equal" || dl.kind === "context") { const prefix = dl.kind === "actual" ? ansis.green(" > ") : " " - lines.push(`${prefix}${dl.kind === "context" ? ansis.dim(dl.text) : dl.text}`) + actualLines.push(`${prefix}${text}`) } } + lines.push(ansis.red(" expected:"), ...expectedLines) + lines.push(ansis.green(" actual:"), ...actualLines) } if (failure.exitCodeMismatch) { diff --git a/src/match.ts b/src/match.ts index c846630..deedf42 100644 --- a/src/match.ts +++ b/src/match.ts @@ -1,3 +1,5 @@ +import { escapeRegex } from "./utils.ts" + export function matchLine(pattern: string, actual: string): boolean { if (!pattern.includes("...")) return pattern === actual @@ -8,10 +10,6 @@ export function matchLine(pattern: string, actual: string): boolean { return regex.test(actual) } -function escapeRegex(s: string): string { - return s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&") -} - export function matchOutput( expected: string[], actual: string[], diff --git a/src/parse.ts b/src/parse.ts index e25ae74..b5709bc 100644 --- a/src/parse.ts +++ b/src/parse.ts @@ -1,3 +1,5 @@ +import { trimTrailingEmpty } from "./utils.ts" + export type Command = { line: number raw: string @@ -54,12 +56,6 @@ function parseExitCode(lines: string[]): { return { lines, exitCode: null } } -function trimTrailingEmpty(lines: string[]): string[] { - let end = lines.length - while (end > 0 && lines[end - 1] === "") end-- - return lines.slice(0, end) -} - function parseEnvDirective(path: string, line: string, lineNum: number): { key: string; value: string } { const rest = line.slice(5).trim() const eq = rest.indexOf("=") diff --git a/src/run.ts b/src/run.ts index 74a61dd..e1c0e31 100644 --- a/src/run.ts +++ b/src/run.ts @@ -3,6 +3,7 @@ import { tmpdir } from "node:os" import { join } from "node:path" import type { Command, ShoutFile } from "./parse.ts" +import { trimTrailingEmpty } from "./utils.ts" export type CommandResult = { command: Command @@ -24,7 +25,6 @@ type RunOptions = { sourceDir?: string projectDir?: string timeout: number - verbose: boolean onCommand?: (cmd: Command) => void } @@ -92,7 +92,6 @@ function buildScript(commands: Command[], sentinel: string, verbose: boolean): s function parseSentinelOutput( raw: string, - sentinel: string, commandCount: number, ): { outputs: string[][]; exitCodes: number[] } { const outputs: string[][] = [] @@ -100,7 +99,7 @@ function parseSentinelOutput( // Split by sentinel lines const sentinelRegex = new RegExp( - `${escapeRegex(sentinel)}(\\d+)_(\\d+)__`, + `${SENTINEL_PREFIX}(\\d+)_(\\d+)__`, ) let remaining = raw @@ -152,16 +151,6 @@ function stripAnsi(line: string): string { return line.replace(ANSI_REGEX, "") } -function trimTrailingEmpty(lines: string[]): string[] { - let end = lines.length - while (end > 0 && lines[end - 1] === "") end-- - return lines.slice(0, end) -} - -function escapeRegex(s: string): string { - return s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&") -} - function streamVerboseMarkers( stderr: ReadableStream, commands: Command[], @@ -254,7 +243,6 @@ export async function runFile( const { outputs, exitCodes } = parseSentinelOutput( stdout, - sentinel, file.commands.length, ) diff --git a/src/update.ts b/src/update.ts index 3546b8a..ecc4790 100644 --- a/src/update.ts +++ b/src/update.ts @@ -1,7 +1,8 @@ import type { CommandResult } from "./run.ts" import type { ShoutFile } from "./parse.ts" -import { matchOutput, matchLine } from "./match.ts" +import { matchOutput } from "./match.ts" import { isCommentLine } from "./parse.ts" +import { trimTrailingEmpty } from "./utils.ts" export function rewriteFile( file: ShoutFile, @@ -83,9 +84,3 @@ export function rewriteFile( function escapeDollar(line: string): string { return line.startsWith("$ ") ? "\\" + line : line } - -function trimTrailingEmpty(lines: string[]): string[] { - let end = lines.length - while (end > 0 && lines[end - 1] === "") end-- - return lines.slice(0, end) -} diff --git a/src/utils.ts b/src/utils.ts new file mode 100644 index 0000000..ae4e3cb --- /dev/null +++ b/src/utils.ts @@ -0,0 +1,9 @@ +export function trimTrailingEmpty(lines: string[]): string[] { + let end = lines.length + while (end > 0 && lines[end - 1] === "") end-- + return lines.slice(0, end) +} + +export function escapeRegex(s: string): string { + return s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&") +} diff --git a/tsconfig.json b/tsconfig.json index d5ad05c..23a8e6b 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -27,17 +27,6 @@ "noUnusedLocals": false, "noUnusedParameters": false, "noPropertyAccessFromIndexSignature": false, - "baseUrl": ".", - "paths": { - "$*": [ - "./src/server/*" - ], - "@*": [ - "./src/shared/*" - ], - "%*": [ - "./src/lib/*" - ] - } + "baseUrl": "." } } \ No newline at end of file