Add --example flag and improve diff formatting
This commit is contained in:
parent
fbeba43120
commit
2bd8b21e7f
|
|
@ -54,7 +54,28 @@ program
|
||||||
.option("--timeout <dur>", "Per-command timeout", "10s")
|
.option("--timeout <dur>", "Per-command timeout", "10s")
|
||||||
.option("-v, --verbose", "Print each command as it runs")
|
.option("-v, --verbose", "Print each command as it runs")
|
||||||
.option("--parallel", "Run files in parallel")
|
.option("--parallel", "Run files in parallel")
|
||||||
|
.option("--example", "Print an example .shout file and exit")
|
||||||
.action(async (fileArgs: string[], opts) => {
|
.action(async (fileArgs: string[], opts) => {
|
||||||
|
if (opts.example) {
|
||||||
|
console.log(`# Example .shout file
|
||||||
|
$ echo hello
|
||||||
|
hello
|
||||||
|
|
||||||
|
$ echo "one"; echo "two"; echo "three"
|
||||||
|
one
|
||||||
|
...
|
||||||
|
three
|
||||||
|
|
||||||
|
$ cat nonexistent
|
||||||
|
cat: nonexistent: ...
|
||||||
|
[1]
|
||||||
|
|
||||||
|
$ exit 0
|
||||||
|
[0]`)
|
||||||
|
process.exit(0)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
const timeoutMs = parseDuration(opts.timeout)
|
const timeoutMs = parseDuration(opts.timeout)
|
||||||
const paths = fileArgs.length > 0 ? fileArgs : ["."]
|
const paths = fileArgs.length > 0 ? fileArgs : ["."]
|
||||||
const files = await findShoutFiles(paths)
|
const files = await findShoutFiles(paths)
|
||||||
|
|
|
||||||
|
|
@ -70,20 +70,20 @@ export function formatFailure(test: TestResult): string {
|
||||||
lines.push("")
|
lines.push("")
|
||||||
lines.push(` ${ansis.dim("$")} ${failure.result.command.command}`)
|
lines.push(` ${ansis.dim("$")} ${failure.result.command.command}`)
|
||||||
|
|
||||||
|
if (failure.diffLines.length > 0) {
|
||||||
|
lines.push(ansis.red(" expected:"))
|
||||||
for (const dl of failure.diffLines) {
|
for (const dl of failure.diffLines) {
|
||||||
switch (dl.kind) {
|
if (dl.kind === "expected" || dl.kind === "equal" || dl.kind === "context") {
|
||||||
case "equal":
|
const prefix = dl.kind === "expected" ? ansis.red(" > ") : " "
|
||||||
lines.push(` ${dl.text}`)
|
lines.push(`${prefix}${dl.kind === "context" ? ansis.dim(dl.text) : dl.text}`)
|
||||||
break
|
}
|
||||||
case "expected":
|
}
|
||||||
lines.push(ansis.red(` - ${dl.text}`))
|
lines.push(ansis.green(" actual:"))
|
||||||
break
|
for (const dl of failure.diffLines) {
|
||||||
case "actual":
|
if (dl.kind === "actual" || dl.kind === "equal" || dl.kind === "context") {
|
||||||
lines.push(ansis.green(` + ${dl.text}`))
|
const prefix = dl.kind === "actual" ? ansis.green(" > ") : " "
|
||||||
break
|
lines.push(`${prefix}${dl.kind === "context" ? ansis.dim(dl.text) : dl.text}`)
|
||||||
case "context":
|
}
|
||||||
lines.push(ansis.dim(` ${dl.text}`))
|
|
||||||
break
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -91,9 +91,9 @@ export function formatFailure(test: TestResult): string {
|
||||||
const expected = failure.result.command.exitCode ?? 0
|
const expected = failure.result.command.exitCode ?? 0
|
||||||
const actual = failure.result.exitCode
|
const actual = failure.result.exitCode
|
||||||
lines.push(
|
lines.push(
|
||||||
ansis.red(` - exit code: ${expected === "*" ? "non-zero" : expected}`),
|
ansis.red(` expected exit code: ${expected === "*" ? "non-zero" : expected}`),
|
||||||
)
|
)
|
||||||
lines.push(ansis.green(` + exit code: ${actual}`))
|
lines.push(ansis.green(` actual exit code: ${actual}`))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user