Skip to content

Commit 049fc26

Browse files
authored
Merge pull request #336 from Pawka/debug
Don't treat debug messages as errors
2 parents f48942a + e2e5c6a commit 049fc26

File tree

2 files changed

+36
-2
lines changed

2 files changed

+36
-2
lines changed

testjson/execution.go

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -746,14 +746,15 @@ func readStderr(config ScanConfig, execution *Execution) error {
746746
if err := config.Handler.Err(line); err != nil {
747747
return fmt.Errorf("failed to handle stderr: %v", err)
748748
}
749-
if isGoModuleOutput(line) {
749+
if isGoModuleOutput(line) || isGoDebugOutput(line) {
750750
continue
751751
}
752752
if strings.HasPrefix(line, "warning:") {
753753
continue
754754
}
755755
execution.addError(line)
756756
}
757+
757758
if err := scanner.Err(); err != nil {
758759
return fmt.Errorf("failed to scan stderr: %v", err)
759760
}
@@ -777,6 +778,20 @@ func isGoModuleOutput(scannerText string) bool {
777778
return false
778779
}
779780

781+
func isGoDebugOutput(scannerText string) bool {
782+
prefixes := []string{
783+
"HASH", // Printed when tests are running with `GODEBUG=gocachehash=1`.
784+
"testcache:", // Printed when tests are running with `GODEBUG=gocachetest=1`.
785+
}
786+
787+
for _, prefix := range prefixes {
788+
if strings.HasPrefix(scannerText, prefix) {
789+
return true
790+
}
791+
}
792+
return false
793+
}
794+
780795
func parseEvent(raw []byte) (TestEvent, error) {
781796
// TODO: this seems to be a bug in the `go test -json` output
782797
if bytes.HasPrefix(raw, []byte("FAIL")) {

testjson/execution_test.go

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package testjson
33
import (
44
"bytes"
55
"fmt"
6+
"strings"
67
"testing"
78
"time"
89

@@ -217,6 +218,24 @@ func TestScanOutput_WithNonJSONLines(t *testing.T) {
217218
}
218219
}
219220

221+
func TestScanOutput_WithGODEBUG(t *testing.T) {
222+
goDebugSource := `HASH[moduleIndex]
223+
HASH[moduleIndex]: "go1.20.4"
224+
HASH /usr/lib/go/src/runtime/debuglog_off.go: d6f147198
225+
testcache: package: input list not found: ...`
226+
227+
handler := &captureHandler{}
228+
cfg := ScanConfig{
229+
Stdout: bytes.NewReader(nil),
230+
Stderr: strings.NewReader(goDebugSource),
231+
Handler: handler,
232+
}
233+
exec, err := ScanTestOutput(cfg)
234+
assert.NilError(t, err)
235+
assert.DeepEqual(t, handler.errs, strings.Split(goDebugSource, "\n"))
236+
assert.DeepEqual(t, exec.Errors(), []string(nil))
237+
}
238+
220239
type captureHandler struct {
221240
events []TestEvent
222241
errs []string
@@ -229,5 +248,5 @@ func (s *captureHandler) Event(event TestEvent, _ *Execution) error {
229248

230249
func (s *captureHandler) Err(text string) error {
231250
s.errs = append(s.errs, text)
232-
return fmt.Errorf(text)
251+
return nil
233252
}

0 commit comments

Comments
 (0)