From dba56c24705f8c1efcc27c072a33a521054c5175 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Povilas=20Balzaravi=C4=8Dius?= Date: Mon, 12 Jun 2023 08:48:02 +0300 Subject: [PATCH 1/2] Don't treat debug messages as errors --- testjson/execution.go | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/testjson/execution.go b/testjson/execution.go index 49111d30..cc440306 100644 --- a/testjson/execution.go +++ b/testjson/execution.go @@ -734,7 +734,7 @@ 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:") { @@ -765,6 +765,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")) { From e2e5c6afd37bf934977c324f4f64235f95068750 Mon Sep 17 00:00:00 2001 From: Daniel Nephin Date: Sat, 8 Jul 2023 14:33:24 -0400 Subject: [PATCH 2/2] Add test for accepting GODEBUG output --- testjson/execution.go | 1 + testjson/execution_test.go | 21 ++++++++++++++++++++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/testjson/execution.go b/testjson/execution.go index cc440306..a1d4ee1c 100644 --- a/testjson/execution.go +++ b/testjson/execution.go @@ -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) } diff --git a/testjson/execution_test.go b/testjson/execution_test.go index 8cc39fa2..8c7566ee 100644 --- a/testjson/execution_test.go +++ b/testjson/execution_test.go @@ -3,6 +3,7 @@ package testjson import ( "bytes" "fmt" + "strings" "testing" "time" @@ -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 @@ -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 }