Skip to content
This repository has been archived by the owner on Aug 2, 2021. It is now read-only.

Commit

Permalink
Check stderr for regex matches, as well as stdout to fix failing test
Browse files Browse the repository at this point in the history
  • Loading branch information
chadsr committed Feb 4, 2020
1 parent 36ccdf4 commit a0b33b0
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions internal/cmdtest/test_cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,11 +147,20 @@ func (tt *TestCmd) matchExactOutput(want []byte) error {
// after ExpectRegexp.
func (tt *TestCmd) ExpectRegexp(regex string) (*regexp.Regexp, []string) {
regex = strings.TrimPrefix(regex, "\n")

var (
re = regexp.MustCompile(regex)
rtee = &runeTee{in: tt.stdout}
matches []int
)

// Read stderr into stdout so that its output is checked for matches, too
_, err := tt.stdout.Read(tt.stderr.buf.Bytes())
if err != nil {
tt.Fatalf("could not read stderr into stdout: %v", err)
return re, nil
}

tt.withKillTimeout(func() { matches = re.FindReaderSubmatchIndex(rtee) })
output := rtee.buf.Bytes()
if matches == nil {
Expand Down

0 comments on commit a0b33b0

Please sign in to comment.