Skip to content

Commit eff05c3

Browse files
wizzomafizzonizos
authored andcommitted
fix(go): restore error message visibility in formatter output
The formatter was suppressing critical error information by returning empty strings for build failures, individual test failures, and most FAIL output. This made debugging difficult when tests failed. Changes: - handleFail now shows build failures as "FAIL\t{package} [build failed]" - handleFail now shows individual test failures as "FAIL\t{package}/{test}" - handleBuildFail added to show "BUILD FAILED" instead of filtering - handleOutput preserves all FAIL\t output instead of selective filtering Tests updated to reflect new expected behavior that prioritizes error visibility over minimal output.
1 parent 9bfea76 commit eff05c3

File tree

2 files changed

+33
-21
lines changed

2 files changed

+33
-21
lines changed

reporters/go/internal/formatter/formatter.go

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ func (f *Formatter) initHandlers() {
2828
"start": returnEmpty,
2929
"run": returnEmpty,
3030
"build-output": f.handleBuildOutput,
31-
"build-fail": returnEmpty,
31+
"build-fail": f.handleBuildFail,
3232
"output": f.handleOutput,
3333
"pass": f.handlePass,
3434
"fail": f.handleFail,
@@ -47,6 +47,13 @@ func (f *Formatter) handleBuildOutput(event parser.TestEvent) string {
4747
return trimNewline(event.Output)
4848
}
4949

50+
func (f *Formatter) handleBuildFail(event parser.TestEvent) string {
51+
if event.Package != "" {
52+
return fmt.Sprintf("BUILD FAILED\t%s", event.Package)
53+
}
54+
return "BUILD FAILED"
55+
}
56+
5057
// handleOutput filters redundant output lines and preserves error messages.
5158
// Removes duplicate package summaries (we generate our own from pass/fail events)
5259
// and test execution markers while keeping actual test failures and error details.
@@ -63,11 +70,8 @@ func (f *Formatter) handleOutput(event parser.TestEvent) string {
6370
case strings.HasPrefix(output, "ok \t"):
6471
return "" // Filtered - we generate from pass event
6572
case strings.HasPrefix(output, "FAIL\t"):
66-
// Keep compilation failures, filter test failures (generated from fail event)
67-
if strings.Contains(output, "[setup failed]") {
68-
return trimNewline(output)
69-
}
70-
return ""
73+
// Keep all FAIL output to preserve error information
74+
return trimNewline(output)
7175
}
7276

7377
if event.Test != "" {
@@ -98,15 +102,19 @@ func (f *Formatter) handlePass(event parser.TestEvent) string {
98102
}
99103

100104
// handleFail generates the "FAIL" summary line for failed package tests.
101-
// Avoids duplicate output for build failures which are already shown as "[setup failed]".
105+
// Shows build failures with package information for better error visibility.
102106
func (f *Formatter) handleFail(event parser.TestEvent) string {
103107
if event.Package != "" && event.Test == "" {
104108
if event.FailedBuild != "" {
105-
return "" // Already shown as "FAIL ... [setup failed]" in output event
109+
return fmt.Sprintf("FAIL\t%s [build failed]", event.Package)
106110
}
107111
return fmt.Sprintf("FAIL\t%s\t%.3fs", event.Package, event.Elapsed)
108112
}
109-
return "" // Filter individual test failures (details shown in output)
113+
// Show individual test failure summaries for better error tracking
114+
if event.Test != "" {
115+
return fmt.Sprintf("FAIL\t%s/%s", event.Package, event.Test)
116+
}
117+
return ""
110118
}
111119

112120
func (f *Formatter) handleUnknown(event parser.TestEvent) string {

reporters/go/internal/formatter/formatter_test.go

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -90,15 +90,16 @@ func TestFormatter(t *testing.T) {
9090
}
9191
})
9292

93-
t.Run("TestSkipPackageFailWithBuildFailure", func(t *testing.T) {
93+
t.Run("TestShowPackageFailWithBuildFailure", func(t *testing.T) {
9494
result := formatEvent(t, parser.TestEvent{
9595
Action: "fail",
9696
Package: "command-line-arguments",
9797
Elapsed: 0,
9898
FailedBuild: "github.com/non-existent/module",
9999
})
100-
if result != "" {
101-
t.Fatalf("Expected build failure package fail to be filtered, got '%s'", result)
100+
expected := "FAIL\tcommand-line-arguments [build failed]"
101+
if result != expected {
102+
t.Fatalf("Expected '%s', got '%s'", expected, result)
102103
}
103104
})
104105

@@ -114,15 +115,16 @@ func TestFormatter(t *testing.T) {
114115
}
115116
})
116117

117-
t.Run("TestFilterTestLevelFailEvents", func(t *testing.T) {
118+
t.Run("TestShowTestLevelFailEvents", func(t *testing.T) {
118119
result := formatEvent(t, parser.TestEvent{
119120
Action: "fail",
120121
Package: "command-line-arguments",
121122
Test: "TestCalculator",
122123
Elapsed: 0.001,
123124
})
124-
if result != "" {
125-
t.Fatalf("Expected test-level fail events to be filtered out, got '%s'", result)
125+
expected := "FAIL\tcommand-line-arguments/TestCalculator"
126+
if result != expected {
127+
t.Fatalf("Expected '%s', got '%s'", expected, result)
126128
}
127129
})
128130

@@ -174,14 +176,15 @@ func TestFormatter(t *testing.T) {
174176
}
175177
})
176178

177-
t.Run("TestFilterPackageFailOutput", func(t *testing.T) {
179+
t.Run("TestShowPackageFailOutput", func(t *testing.T) {
178180
result := formatEvent(t, parser.TestEvent{
179181
Action: "output",
180182
Package: "example.com/pkg",
181183
Output: "FAIL\texample.com/pkg\t0.002s\n",
182184
})
183-
if result != "" {
184-
t.Fatalf("Expected package FAIL output to be filtered out, got '%s'", result)
185+
expected := "FAIL\texample.com/pkg\t0.002s"
186+
if result != expected {
187+
t.Fatalf("Expected '%s', got '%s'", expected, result)
185188
}
186189
})
187190

@@ -208,10 +211,11 @@ func TestFormatter(t *testing.T) {
208211
}
209212
})
210213

211-
t.Run("TestFilterBuildFailEvents", func(t *testing.T) {
214+
t.Run("TestShowBuildFailEvents", func(t *testing.T) {
212215
result := formatEvent(t, parser.TestEvent{Action: "build-fail"})
213-
if result != "" {
214-
t.Fatalf("Expected build-fail events to be filtered out, got '%s'", result)
216+
expected := "BUILD FAILED"
217+
if result != expected {
218+
t.Fatalf("Expected '%s', got '%s'", expected, result)
215219
}
216220
})
217221

0 commit comments

Comments
 (0)