@@ -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})')
0 commit comments