Skip to content

Commit 3f7ff0e

Browse files
authored
Merge pull request #476 from dnephin/build-failures-go1.24
Include new json build failures (go1.24)
2 parents c64e7cd + d0bfcd8 commit 3f7ff0e

12 files changed

+125
-29
lines changed

cmd/handler_test.go

+48
Original file line numberDiff line numberDiff line change
@@ -174,3 +174,51 @@ func TestScanTestOutput_TestTimeoutPanicRace(t *testing.T) {
174174
})
175175
}
176176
}
177+
178+
// Tests output when a package fails to build because of a compilation error
179+
// and no tests are run in the package.
180+
func TestEventHandler_TestBuildFail(t *testing.T) {
181+
t.Setenv("GITHUB_ACTIONS", "no")
182+
183+
buf := new(bufferCloser)
184+
errBuf := new(bytes.Buffer)
185+
format := testjson.NewEventFormatter(errBuf, "testname", testjson.FormatOptions{})
186+
187+
source := golden.Get(t, "input/go-test-build-failed.out")
188+
cfg := testjson.ScanConfig{
189+
Stdout: bytes.NewReader(source),
190+
Handler: &eventHandler{jsonFile: buf, formatter: format},
191+
}
192+
exec, err := testjson.ScanTestOutput(cfg)
193+
assert.NilError(t, err)
194+
195+
out := new(bytes.Buffer)
196+
testjson.PrintSummary(out, exec, testjson.SummarizeAll)
197+
198+
actual := text.ProcessLines(t, out, text.OpRemoveSummaryLineElapsedTime)
199+
golden.Assert(t, actual, "expected/build-fail-expected")
200+
}
201+
202+
// Tests output when a package fails to build because of a compilation error
203+
// due to syntax errors and the like.
204+
func TestEventHandler_SetupFail(t *testing.T) {
205+
t.Setenv("GITHUB_ACTIONS", "no")
206+
207+
buf := new(bufferCloser)
208+
errBuf := new(bytes.Buffer)
209+
format := testjson.NewEventFormatter(errBuf, "testname", testjson.FormatOptions{})
210+
211+
source := golden.Get(t, "input/go-test-setup-failed.out")
212+
cfg := testjson.ScanConfig{
213+
Stdout: bytes.NewReader(source),
214+
Handler: &eventHandler{jsonFile: buf, formatter: format},
215+
}
216+
exec, err := testjson.ScanTestOutput(cfg)
217+
assert.NilError(t, err)
218+
219+
out := new(bytes.Buffer)
220+
testjson.PrintSummary(out, exec, testjson.SummarizeAll)
221+
222+
actual := text.ProcessLines(t, out, text.OpRemoveSummaryLineElapsedTime)
223+
golden.Assert(t, actual, "expected/setup-fail-expected")
224+
}

cmd/main_e2e_test.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package cmd
22

33
import (
44
"bytes"
5+
goversion "go/version"
56
"os"
67
"path/filepath"
78
"runtime"
@@ -123,17 +124,16 @@ func osEnviron() map[string]string {
123124
func expectedFilename(name string) string {
124125
ver := runtime.Version()
125126
switch {
126-
case isPreGo120(ver):
127-
return name + "-go1.19"
127+
case isPreGo124(ver):
128+
return name + "-go1.23"
128129
default:
129130
return name
130131
}
131132
}
132133

133-
// go1.20.0 changed how it prints messages from subtests. It seems the output
134-
// has changed back to match the output from go1.14 and earlier.
135-
func isPreGo120(ver string) bool {
136-
return strings.HasPrefix(ver, "go1.1")
134+
// go1.24 changed how it handles build output
135+
func isPreGo124(ver string) bool {
136+
return goversion.Compare(ver, "go1.24") < 0
137137
}
138138

139139
var binaryFixture pkgFixtureFile

cmd/testdata/e2e/expected/TestE2E_RerunFails/first_run_has_errors,_abort_rerun

+1
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,5 @@ FAIL gotest.tools/gotestsum/testjson/internal/broken [build failed]
77
=== Errors
88
../testjson/internal/broken/broken.go:5:21: undefined: somepackage
99

10+
1011
DONE 0 tests, 1 failure, 1 error

cmd/testdata/e2e/expected/TestE2E_RerunFails/first_run_has_errors,_abort_rerun-go1.19

-5
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
FAIL testjson/internal/broken
2+
3+
=== Failed
4+
=== FAIL: testjson/internal/broken
5+
FAIL gotest.tools/gotestsum/testjson/internal/broken [build failed]
6+
7+
=== Errors
8+
../testjson/internal/broken/broken.go:5:21: undefined: somepackage
9+
10+
DONE 0 tests, 1 failure, 1 error

cmd/testdata/e2e/expected/TestE2E_RerunFails/reruns_continues_to_fail-go1.19 cmd/testdata/e2e/expected/TestE2E_RerunFails/reruns_continues_to_fail-go1.23

+3-6
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ FAIL cmd/testdata/e2e/flaky.TestFailsSometimes
1212
PASS cmd/testdata/e2e/flaky.TestFailsOften/subtest_always_passes
1313
=== RUN TestFailsOften/subtest_may_fail
1414
flaky_test.go:68: not this time
15-
--- FAIL: TestFailsOften/subtest_may_fail
15+
--- FAIL: TestFailsOften/subtest_may_fail
1616
FAIL cmd/testdata/e2e/flaky.TestFailsOften/subtest_may_fail
1717
=== RUN TestFailsOften
1818
SEED: 0
@@ -30,7 +30,7 @@ PASS cmd/testdata/e2e/flaky.TestFailsSometimes (re-run 1)
3030
PASS cmd/testdata/e2e/flaky
3131
=== RUN TestFailsOften/subtest_may_fail
3232
flaky_test.go:68: not this time
33-
--- FAIL: TestFailsOften/subtest_may_fail
33+
--- FAIL: TestFailsOften/subtest_may_fail
3434
FAIL cmd/testdata/e2e/flaky.TestFailsOften/subtest_may_fail (re-run 1)
3535
=== RUN TestFailsOften
3636
SEED: 3
@@ -42,7 +42,7 @@ DONE 2 runs, 12 tests, 6 failures
4242

4343
=== RUN TestFailsOften/subtest_may_fail
4444
flaky_test.go:68: not this time
45-
--- FAIL: TestFailsOften/subtest_may_fail
45+
--- FAIL: TestFailsOften/subtest_may_fail
4646
FAIL cmd/testdata/e2e/flaky.TestFailsOften/subtest_may_fail (re-run 2)
4747
=== RUN TestFailsOften
4848
SEED: 4
@@ -61,21 +61,18 @@ SEED: 0
6161

6262
=== FAIL: cmd/testdata/e2e/flaky TestFailsOften/subtest_may_fail
6363
flaky_test.go:68: not this time
64-
--- FAIL: TestFailsOften/subtest_may_fail
6564

6665
=== FAIL: cmd/testdata/e2e/flaky TestFailsOften
6766
SEED: 0
6867

6968
=== FAIL: cmd/testdata/e2e/flaky TestFailsOften/subtest_may_fail (re-run 1)
7069
flaky_test.go:68: not this time
71-
--- FAIL: TestFailsOften/subtest_may_fail
7270

7371
=== FAIL: cmd/testdata/e2e/flaky TestFailsOften (re-run 1)
7472
SEED: 3
7573

7674
=== FAIL: cmd/testdata/e2e/flaky TestFailsOften/subtest_may_fail (re-run 2)
7775
flaky_test.go:68: not this time
78-
--- FAIL: TestFailsOften/subtest_may_fail
7976

8077
=== FAIL: cmd/testdata/e2e/flaky TestFailsOften (re-run 2)
8178
SEED: 4

cmd/testdata/e2e/expected/TestE2E_RerunFails/reruns_until_success-go1.19 cmd/testdata/e2e/expected/TestE2E_RerunFails/reruns_until_success-go1.23

+4-8
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ FAIL cmd/testdata/e2e/flaky.TestFailsSometimes
1212
PASS cmd/testdata/e2e/flaky.TestFailsOften/subtest_always_passes
1313
=== RUN TestFailsOften/subtest_may_fail
1414
flaky_test.go:68: not this time
15-
--- FAIL: TestFailsOften/subtest_may_fail
15+
--- FAIL: TestFailsOften/subtest_may_fail
1616
FAIL cmd/testdata/e2e/flaky.TestFailsOften/subtest_may_fail
1717
=== RUN TestFailsOften
1818
SEED: 0
@@ -30,7 +30,7 @@ PASS cmd/testdata/e2e/flaky.TestFailsSometimes (re-run 1)
3030
PASS cmd/testdata/e2e/flaky
3131
=== RUN TestFailsOften/subtest_may_fail
3232
flaky_test.go:68: not this time
33-
--- FAIL: TestFailsOften/subtest_may_fail
33+
--- FAIL: TestFailsOften/subtest_may_fail
3434
FAIL cmd/testdata/e2e/flaky.TestFailsOften/subtest_may_fail (re-run 1)
3535
=== RUN TestFailsOften
3636
SEED: 3
@@ -42,7 +42,7 @@ DONE 2 runs, 12 tests, 6 failures
4242

4343
=== RUN TestFailsOften/subtest_may_fail
4444
flaky_test.go:68: not this time
45-
--- FAIL: TestFailsOften/subtest_may_fail
45+
--- FAIL: TestFailsOften/subtest_may_fail
4646
FAIL cmd/testdata/e2e/flaky.TestFailsOften/subtest_may_fail (re-run 2)
4747
=== RUN TestFailsOften
4848
SEED: 4
@@ -54,7 +54,7 @@ DONE 3 runs, 14 tests, 8 failures
5454

5555
=== RUN TestFailsOften/subtest_may_fail
5656
flaky_test.go:68: not this time
57-
--- FAIL: TestFailsOften/subtest_may_fail
57+
--- FAIL: TestFailsOften/subtest_may_fail
5858
FAIL cmd/testdata/e2e/flaky.TestFailsOften/subtest_may_fail (re-run 3)
5959
=== RUN TestFailsOften
6060
SEED: 5
@@ -79,28 +79,24 @@ SEED: 0
7979

8080
=== FAIL: cmd/testdata/e2e/flaky TestFailsOften/subtest_may_fail
8181
flaky_test.go:68: not this time
82-
--- FAIL: TestFailsOften/subtest_may_fail
8382

8483
=== FAIL: cmd/testdata/e2e/flaky TestFailsOften
8584
SEED: 0
8685

8786
=== FAIL: cmd/testdata/e2e/flaky TestFailsOften/subtest_may_fail (re-run 1)
8887
flaky_test.go:68: not this time
89-
--- FAIL: TestFailsOften/subtest_may_fail
9088

9189
=== FAIL: cmd/testdata/e2e/flaky TestFailsOften (re-run 1)
9290
SEED: 3
9391

9492
=== FAIL: cmd/testdata/e2e/flaky TestFailsOften/subtest_may_fail (re-run 2)
9593
flaky_test.go:68: not this time
96-
--- FAIL: TestFailsOften/subtest_may_fail
9794

9895
=== FAIL: cmd/testdata/e2e/flaky TestFailsOften (re-run 2)
9996
SEED: 4
10097

10198
=== FAIL: cmd/testdata/e2e/flaky TestFailsOften/subtest_may_fail (re-run 3)
10299
flaky_test.go:68: not this time
103-
--- FAIL: TestFailsOften/subtest_may_fail
104100

105101
=== FAIL: cmd/testdata/e2e/flaky TestFailsOften (re-run 3)
106102
SEED: 5
+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
2+
=== Failed
3+
=== FAIL: example.com/internal/cacher (0.00s)
4+
FAIL example.com/internal/cacher [build failed]
5+
6+
=== Errors
7+
./directory_test.go:321:10: undefined: assert.foo
8+
9+
10+
DONE 0 tests, 1 failure, 1 error
+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
2+
=== Failed
3+
=== FAIL: example.com/internal/cacher (0.00s)
4+
FAIL example.com/internal/cacher [setup failed]
5+
6+
=== FAIL: example.com/internal/cacher/subpkg (0.00s)
7+
FAIL example.com/internal/cacher/subpkg [setup failed]
8+
9+
=== Errors
10+
directory_test.go:321:13: expected ';', found o
11+
12+
subpkg/main_test.go:1:1: expected 'package', found aldfjadskfs
13+
14+
15+
DONE 0 tests, 2 failures, 2 errors
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{"ImportPath":"example.com/internal/cacher [example.com/internal/cacher.test]","Action":"build-output","Output":"# example.com/internal/cacher [example.com/internal/cacher.test]\n"}
2+
{"ImportPath":"example.com/internal/cacher [example.com/internal/cacher.test]","Action":"build-output","Output":"./directory_test.go:321:10: undefined: assert.foo\n"}
3+
{"ImportPath":"example.com/internal/cacher [example.com/internal/cacher.test]","Action":"build-fail"}
4+
{"Time":"2025-03-10T17:34:31.493978-07:00","Action":"start","Package":"example.com/internal/cacher"}
5+
{"Time":"2025-03-10T17:34:31.494027-07:00","Action":"output","Package":"example.com/internal/cacher","Output":"FAIL\texample.com/internal/cacher [build failed]\n"}
6+
{"Time":"2025-03-10T17:34:31.494039-07:00","Action":"fail","Package":"example.com/internal/cacher","Elapsed":0,"FailedBuild":"example.com/internal/cacher [example.com/internal/cacher.test]"}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{"ImportPath":"example.com/internal/cacher.test","Action":"build-output","Output":"# example.com/internal/cacher\n"}
2+
{"ImportPath":"example.com/internal/cacher.test","Action":"build-output","Output":"directory_test.go:321:13: expected ';', found o\n"}
3+
{"ImportPath":"example.com/internal/cacher.test","Action":"build-fail"}
4+
{"Time":"2025-03-11T10:08:34.978868-07:00","Action":"start","Package":"example.com/internal/cacher"}
5+
{"Time":"2025-03-11T10:08:34.978905-07:00","Action":"output","Package":"example.com/internal/cacher","Output":"FAIL\texample.com/internal/cacher [setup failed]\n"}
6+
{"Time":"2025-03-11T10:08:34.978914-07:00","Action":"fail","Package":"example.com/internal/cacher","Elapsed":0,"FailedBuild":"example.com/internal/cacher.test"}
7+
{"ImportPath":"example.com/internal/cacher/subpkg","Action":"build-output","Output":"# example.com/internal/cacher/subpkg\n"}
8+
{"ImportPath":"example.com/internal/cacher/subpkg","Action":"build-output","Output":"subpkg/main_test.go:1:1: expected 'package', found aldfjadskfs\n"}
9+
{"ImportPath":"example.com/internal/cacher/subpkg","Action":"build-fail"}
10+
{"Time":"2025-03-11T10:08:34.978928-07:00","Action":"start","Package":"example.com/internal/cacher/subpkg"}
11+
{"Time":"2025-03-11T10:08:34.979019-07:00","Action":"output","Package":"example.com/internal/cacher/subpkg","Output":"FAIL\texample.com/internal/cacher/subpkg [setup failed]\n"}
12+
{"Time":"2025-03-11T10:08:34.979028-07:00","Action":"fail","Package":"example.com/internal/cacher/subpkg","Elapsed":0,"FailedBuild":"example.com/internal/cacher/subpkg"}

testjson/execution.go

+10-4
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ const (
2828
ActionFail Action = "fail"
2929
ActionOutput Action = "output"
3030
ActionSkip Action = "skip"
31+
ActionBuild Action = "build-output"
3132
)
3233

3334
// IsTerminal returns true if the Action is one of: pass, fail, skip.
@@ -43,10 +44,11 @@ func (a Action) IsTerminal() bool {
4344
// TestEvent is a structure output by go tool test2json and go test -json.
4445
type TestEvent struct {
4546
// Time encoded as an RFC3339-format string
46-
Time time.Time
47-
Action Action
48-
Package string
49-
Test string
47+
Time time.Time
48+
Action Action
49+
Package string
50+
Test string
51+
ImportPath string
5052
// Elapsed time in seconds
5153
Elapsed float64
5254
// Output of test or benchmark
@@ -358,6 +360,10 @@ func (e *Execution) add(event TestEvent) {
358360
pkg = newPackage()
359361
e.packages[event.Package] = pkg
360362
}
363+
if event.Action == ActionBuild {
364+
e.addError(event.Output)
365+
return
366+
}
361367
if event.PackageEvent() {
362368
pkg.addEvent(event)
363369
return

0 commit comments

Comments
 (0)