Skip to content

cmd/go: add build -json, to report build failures in JSON #23037

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
zolotov opened this issue Dec 7, 2017 · 9 comments
Closed

cmd/go: add build -json, to report build failures in JSON #23037

zolotov opened this issue Dec 7, 2017 · 9 comments
Labels
FeatureRequest Issues asking for a new feature that does not need a proposal. FrozenDueToAge GoCommand cmd/go NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@zolotov
Copy link
Contributor

zolotov commented Dec 7, 2017

If I run go test on a directory and one of the packages is failed to run, I won't get any json output for it.
It would be great to have at least a single package-fail json-message.

@ianlancetaylor
Copy link
Contributor

In general the go tool does not support multiple packages in a single directory.

Can you give a small complete example?

@zolotov
Copy link
Contributor Author

zolotov commented Dec 7, 2017

  • dir/compilablePackage/foo_test.go
  • dir/nonCompilablePackage/foo_test.go

run cd dir && go test -json ./...

@ianlancetaylor
Copy link
Contributor

Thanks. For future reference, when I ask for a small complete example, it really helps a lot if you can give a complete example, which means the exact files and the exact commands. Otherwise I have to guess what you mean when you say "nonCompilablePackage", and experience tells me that I often guess wrong.

Here is a complete example that may show the problem:

src/p1/p1.go

package p1

func F() {}

src/p1/p1_test.go

package p1

import "testing"

func TestF(t *testing.T) {
	F()
	t.Log("F")
}

src/p2/p2.go:

package p2

func F() {}

this file will not compile

src/p2/p2_test.go:

package p2

import "testing"

func TestF(t *testing.T) {
	F()
	t.Log("F")
}
go test -json ./...
# p2
src/p2/p2.go:5:1: syntax error: non-declaration statement outside function body
{"Time":"2017-12-15T13:38:12.885932037-08:00","Action":"run","Package":"p1","Test":"TestF"}
{"Time":"2017-12-15T13:38:12.886027694-08:00","Action":"output","Package":"p1","Test":"TestF","Output":"=== RUN   TestF\n"}
{"Time":"2017-12-15T13:38:12.88604052-08:00","Action":"output","Package":"p1","Test":"TestF","Output":"--- PASS: TestF (0.00s)\n"}
{"Time":"2017-12-15T13:38:12.886047376-08:00","Action":"output","Package":"p1","Test":"TestF","Output":"\tp1_test.go:7: F\n"}
{"Time":"2017-12-15T13:38:12.886054374-08:00","Action":"pass","Package":"p1","Test":"TestF","Elapsed":0}
{"Time":"2017-12-15T13:38:12.88607203-08:00","Action":"output","Package":"p1","Output":"PASS\n"}
{"Time":"2017-12-15T13:38:12.886112826-08:00","Action":"output","Package":"p1","Output":"ok  \tp1\t0.009s\n"}
{"Time":"2017-12-15T13:38:12.886135226-08:00","Action":"pass","Package":"p1","Elapsed":0.009}
FAIL	p2 [build failed]

If I understand you correctly, you are saying that you would like to have JSON output that reports that we were unable to build package p2. Is that correct?

CC @rsc

@ianlancetaylor ianlancetaylor changed the title cmd/test2json: add JSON output for building package failures while running go test on directory with several packages cmd/go: add JSON output for building package failures while running go test on directory with several packages Dec 15, 2017
@ianlancetaylor ianlancetaylor added NeedsDecision Feedback is required from experts, contributors, and/or the community before a change can be made. release-blocker labels Dec 15, 2017
@ianlancetaylor ianlancetaylor added this to the Go1.10 milestone Dec 15, 2017
@zolotov
Copy link
Contributor Author

zolotov commented Dec 15, 2017

Yes, that's correct.

@rsc
Copy link
Contributor

rsc commented Jan 4, 2018

You're asking for go build -json. We are only adding go test -json in this release. Maybe in a future release we could add go build -json and make go test imply that flag. Sorry.

@rsc rsc changed the title cmd/go: add JSON output for building package failures while running go test on directory with several packages cmd/go: add build -json, to report build failures in JSON Jan 4, 2018
@rsc rsc removed NeedsDecision Feedback is required from experts, contributors, and/or the community before a change can be made. release-blocker labels Jan 4, 2018
@rsc rsc modified the milestones: Go1.10, Go1.11 Jan 4, 2018
@rsc rsc added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Jan 4, 2018
sigma added a commit to sigma/go-junit-report that referenced this issue Mar 20, 2018
Unfortunately, there is no go build json output as of yet
(golang/go#23037)
sigma added a commit to sigma/go-junit-report that referenced this issue Mar 20, 2018
Unfortunately, there is no go build json output as of yet
(golang/go#23037)
@ianlancetaylor ianlancetaylor modified the milestones: Go1.11, Unplanned Jul 3, 2018
@ianlancetaylor ianlancetaylor added the FeatureRequest Issues asking for a new feature that does not need a proposal. label Jul 3, 2018
@magik6k
Copy link

magik6k commented May 14, 2019

@rsc It seems like the FAIL p2 [build failed] line is emitted by go test and not go build, so this shouldn't require go build -json

@aclements
Copy link
Member

I've filed a concrete proposal for go build -json: #62067 (There are a lot of cross-references above, so I figured I should call this out explicitly.)

@gopherbot
Copy link
Contributor

Change https://go.dev/cl/536397 mentions this issue: cmd/go: implement "go build -json"

@bcmills
Copy link
Contributor

bcmills commented Nov 28, 2023

Duplicate of #62067

@bcmills bcmills marked this as a duplicate of #62067 Nov 28, 2023
@bcmills bcmills closed this as not planned Won't fix, can't repro, duplicate, stale Nov 28, 2023
gopherbot pushed a commit that referenced this issue Nov 17, 2024
This adds support for a "-json" flag in all build-related go
subcommands. This causes build output and build failures to be
reported to stdout in a machine-readable way.

For #62067.
Fixes #23037.

Change-Id: Id045c5bd5dde9d16cc09dde6248a4b9637896a30
Reviewed-on: https://go-review.googlesource.com/c/go/+/536397
LUCI-TryBot-Result: Go LUCI <[email protected]>
Reviewed-by: Russ Cox <[email protected]>
@golang golang locked and limited conversation to collaborators Nov 27, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FeatureRequest Issues asking for a new feature that does not need a proposal. FrozenDueToAge GoCommand cmd/go NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

No branches or pull requests

7 participants