Skip to content

Commit

Permalink
Merge pull request #336 from Pawka/debug
Browse files Browse the repository at this point in the history
Don't treat debug messages as errors
  • Loading branch information
dnephin authored Jul 8, 2023
2 parents f48942a + e2e5c6a commit 049fc26
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 2 deletions.
17 changes: 16 additions & 1 deletion testjson/execution.go
Original file line number Diff line number Diff line change
Expand Up @@ -746,14 +746,15 @@ func readStderr(config ScanConfig, execution *Execution) error {
if err := config.Handler.Err(line); err != nil {
return fmt.Errorf("failed to handle stderr: %v", err)
}
if isGoModuleOutput(line) {
if isGoModuleOutput(line) || isGoDebugOutput(line) {
continue
}
if strings.HasPrefix(line, "warning:") {
continue
}
execution.addError(line)
}

if err := scanner.Err(); err != nil {
return fmt.Errorf("failed to scan stderr: %v", err)
}
Expand All @@ -777,6 +778,20 @@ func isGoModuleOutput(scannerText string) bool {
return false
}

func isGoDebugOutput(scannerText string) bool {
prefixes := []string{
"HASH", // Printed when tests are running with `GODEBUG=gocachehash=1`.
"testcache:", // Printed when tests are running with `GODEBUG=gocachetest=1`.
}

for _, prefix := range prefixes {
if strings.HasPrefix(scannerText, prefix) {
return true
}
}
return false
}

func parseEvent(raw []byte) (TestEvent, error) {
// TODO: this seems to be a bug in the `go test -json` output
if bytes.HasPrefix(raw, []byte("FAIL")) {
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 049fc26

Please sign in to comment.