Skip to content

Commit

Permalink
Add test for accepting GODEBUG output
Browse files Browse the repository at this point in the history
  • Loading branch information
dnephin committed Jul 8, 2023
1 parent dba56c2 commit e2e5c6a
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
1 change: 1 addition & 0 deletions testjson/execution.go
Original file line number Diff line number Diff line change
Expand Up @@ -742,6 +742,7 @@ func readStderr(config ScanConfig, execution *Execution) error {
}
execution.addError(line)
}

if err := scanner.Err(); err != nil {
return fmt.Errorf("failed to scan stderr: %v", err)
}
Expand Down
21 changes: 20 additions & 1 deletion testjson/execution_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package testjson
import (
"bytes"
"fmt"
"strings"
"testing"
"time"

Expand Down Expand Up @@ -217,6 +218,24 @@ func TestScanOutput_WithNonJSONLines(t *testing.T) {
}
}

func TestScanOutput_WithGODEBUG(t *testing.T) {
goDebugSource := `HASH[moduleIndex]
HASH[moduleIndex]: "go1.20.4"
HASH /usr/lib/go/src/runtime/debuglog_off.go: d6f147198
testcache: package: input list not found: ...`

handler := &captureHandler{}
cfg := ScanConfig{
Stdout: bytes.NewReader(nil),
Stderr: strings.NewReader(goDebugSource),
Handler: handler,
}
exec, err := ScanTestOutput(cfg)
assert.NilError(t, err)
assert.DeepEqual(t, handler.errs, strings.Split(goDebugSource, "\n"))
assert.DeepEqual(t, exec.Errors(), []string(nil))
}

type captureHandler struct {
events []TestEvent
errs []string
Expand All @@ -229,5 +248,5 @@ func (s *captureHandler) Event(event TestEvent, _ *Execution) error {

func (s *captureHandler) Err(text string) error {
s.errs = append(s.errs, text)
return fmt.Errorf(text)
return nil
}

0 comments on commit e2e5c6a

Please sign in to comment.