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("-v, --verbose", "Print each command as it runs")
|
||||
.option("--parallel", "Run files in parallel")
|
||||
.option("--example", "Print an example .shout file and exit")
|
||||
.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 paths = fileArgs.length > 0 ? fileArgs : ["."]
|
||||
const files = await findShoutFiles(paths)
|
||||
|
|
|
|||
|
|
@ -70,20 +70,20 @@ export function formatFailure(test: TestResult): string {
|
|||
lines.push("")
|
||||
lines.push(` ${ansis.dim("$")} ${failure.result.command.command}`)
|
||||
|
||||
for (const dl of failure.diffLines) {
|
||||
switch (dl.kind) {
|
||||
case "equal":
|
||||
lines.push(` ${dl.text}`)
|
||||
break
|
||||
case "expected":
|
||||
lines.push(ansis.red(` - ${dl.text}`))
|
||||
break
|
||||
case "actual":
|
||||
lines.push(ansis.green(` + ${dl.text}`))
|
||||
break
|
||||
case "context":
|
||||
lines.push(ansis.dim(` ${dl.text}`))
|
||||
break
|
||||
if (failure.diffLines.length > 0) {
|
||||
lines.push(ansis.red(" expected:"))
|
||||
for (const dl of failure.diffLines) {
|
||||
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}`)
|
||||
}
|
||||
}
|
||||
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}`)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -91,9 +91,9 @@ export function formatFailure(test: TestResult): string {
|
|||
const expected = failure.result.command.exitCode ?? 0
|
||||
const actual = failure.result.exitCode
|
||||
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