Skip to content

Commit f88851c

Browse files
committed
Test library bump
1 parent c5add3c commit f88851c

File tree

2 files changed

+29
-6
lines changed

2 files changed

+29
-6
lines changed

lib/test.risor

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,31 @@ func stdout_equals(desc, cmd, expected) {
149149

150150
}
151151

152+
// Assert that cmd stderr output matches a regular expression.
153+
//
154+
// desc: the test description
155+
// cmd: the command to run
156+
// reg: the regular expression to match
157+
func stderr_matches(desc, cmd, reg) {
158+
tokens := cmd.split(" ")
159+
bin := tokens[0]
160+
args := [bin]
161+
if len(tokens) > 1 {
162+
args.extend(tokens[1:])
163+
}
164+
165+
try(func() {
166+
res := exec(args)
167+
if regexp.match(reg, res.stderr) {
168+
print_ok(desc)
169+
} else {
170+
error('"{res.stderr}" does not match "{reg}"')
171+
}
172+
}, func(e) {
173+
print_fail(desc + ' (error: {e})')
174+
})
175+
}
176+
152177
// Assert that cmd output matches a regular expression.
153178
//
154179
// desc: the test description
@@ -162,14 +187,12 @@ func stdout_matches(desc, cmd, reg) {
162187
args.extend(tokens[1:])
163188
}
164189

165-
cmd := exec.command(args)
166190
try(func() {
167-
out := cmd.combined_output()
168-
out = string(out)
169-
if regexp.match(reg, out) {
191+
res := exec(args)
192+
if regexp.match(reg, res.stdout) {
170193
print_ok(desc)
171194
} else {
172-
error(desc + ' (output {out} does not match {reg})')
195+
error('"{res.stdout}" does not match "{reg}"')
173196
}
174197
}, func(e) {
175198
print_fail(desc + ' (error: {e})')

tests/tests.risor

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ test.with_temp_dir(func(tmp_dir) {
1919

2020
test.with_temp_dir(func(tmp_dir) {
2121
dir := filepath.join(tmp_dir, "rsx-new")
22-
test.stdout_matches(
22+
test.stderr_matches(
2323
'rsx new without arguments fails',
2424
'{_rsxbin} new',
2525
'Missing directory argument.',

0 commit comments

Comments
 (0)