Skip to content

Commit e39e965

Browse files
committed
cmd/go: drop FailedBuild field if gotestjsonbuildtext=1
go test -json has two new effects in Go 1.24: it implies go build -json, and it adds a FailedBuild field in test events. For compatibility, CL 629335 added gotestjsonbuildtext=1, which disables the implicit go build -json, but that CL didn't affect the FailedBuild field. In principle this shouldn't matter because it's just another JSON field, but just so we don't have to worry about some intermediate behavior, this CL makes gotestjsonbuildtext=1 disable the FailedBuild field as well. Updates #62067 Updates #70402 Change-Id: I006d1ea0468980ee2564495324e8b4ed082898af Reviewed-on: https://go-review.googlesource.com/c/go/+/635899 Auto-Submit: Austin Clements <austin@google.com> Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
1 parent 08770a5 commit e39e965

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

src/cmd/go/internal/test/test.go

+12-2
Original file line numberDiff line numberDiff line change
@@ -1009,7 +1009,13 @@ func runTest(ctx context.Context, cmd *base.Command, args []string) {
10091009
json.Exited(err)
10101010
json.Close()
10111011
}()
1012-
json.SetFailedBuild(perr.Desc())
1012+
if gotestjsonbuildtext.Value() == "1" {
1013+
// While this flag is about go build -json, the other effect
1014+
// of that change was to include "FailedBuild" in the test JSON.
1015+
gotestjsonbuildtext.IncNonDefault()
1016+
} else {
1017+
json.SetFailedBuild(perr.Desc())
1018+
}
10131019
stdout = json
10141020
}
10151021
fmt.Fprintf(stdout, "FAIL\t%s [setup failed]\n", p.ImportPath)
@@ -1437,7 +1443,11 @@ func (r *runTestActor) Act(b *work.Builder, ctx context.Context, a *work.Action)
14371443
if a.Failed != nil {
14381444
// We were unable to build the binary.
14391445
if json != nil && a.Failed.Package != nil {
1440-
json.SetFailedBuild(a.Failed.Package.Desc())
1446+
if gotestjsonbuildtext.Value() == "1" {
1447+
gotestjsonbuildtext.IncNonDefault()
1448+
} else {
1449+
json.SetFailedBuild(a.Failed.Package.Desc())
1450+
}
14411451
}
14421452
a.Failed = nil
14431453
fmt.Fprintf(stdout, "FAIL\t%s [build failed]\n", a.Package.ImportPath)

src/cmd/go/testdata/script/test_json_build.txt

+3-2
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,9 @@ stderr '# m/builderror \[m/builderror.test\]\n'
5858
stderr 'builderror'${/}'main_test.go:3:11: undefined: y\n'
5959
stdout '"Action":"start","Package":"m/builderror"'
6060
stdout '"Action":"output","Package":"m/builderror","Output":"FAIL\\tm/builderror \[build failed\]\\n"'
61-
stdout '"Action":"fail","Package":"m/builderror","Elapsed":.*,"FailedBuild":"m/builderror \[m/builderror\.test\]"'
62-
61+
stdout '"Action":"fail","Package":"m/builderror","Elapsed":[0-9.]+\}'
62+
# FailedBuild should NOT appear in the output in this mode.
63+
! stdout '"FailedBuild"'
6364

6465
-- go.mod --
6566
module m

0 commit comments

Comments
 (0)