Skip to content

Commit

Permalink
fix: handle exit 1 in some test module funcs
Browse files Browse the repository at this point in the history
stdout_matches and stdout_equals now print the test failure correctly
when exec exits != 0.
  • Loading branch information
rubiojr committed Oct 13, 2024
1 parent c3087a5 commit 90d387f
Showing 1 changed file with 23 additions and 12 deletions.
35 changes: 23 additions & 12 deletions lib/test.risor
Original file line number Diff line number Diff line change
Expand Up @@ -134,12 +134,18 @@ func stdout_equals(desc, cmd, expected) {
if len(tokens) > 1 {
args.extend(tokens[1:])
}
out := exec(bin, args).stdout
if out != expected {
print_fail(desc + ' (expected: {expected}, got: {out})')
} else {
print_ok(desc)
}

try(func() {
out := exec(bin, args)
if out.stdout != expected {
print_fail(desc + ' (expected: {expected}, got: {out})')
} else {
print_ok(desc)
}
}, func(e) {
print_fail(desc + ' (error: {e})')
})

}

// Assert that cmd output matches a regular expression.
Expand All @@ -154,12 +160,17 @@ func stdout_matches(desc, cmd, reg) {
if len(tokens) > 1 {
args.extend(tokens[1:])
}
out := exec(bin, args).stdout
if regexp.match(reg, out) {
print_ok(desc)
} else {
print_fail(desc + '(output {out} does not match {reg})')
}

try(func() {
out := exec(bin, args)
if regexp.match(reg, out.stdout) {
print_ok(desc)
} else {
print_fail(desc + '(output {out} does not match {reg})')
}
}, func(e) {
print_fail(desc + ' (error: {e})')
})
}

// Assert that a path is a directory.
Expand Down

0 comments on commit 90d387f

Please sign in to comment.