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
proposal: x/tools: add package for parsing go test JSON output #53893
Comments
For what it's worth, I have wanted a very similar thing for There are also a multitude of other similar All this to say: I think we should have a package or module to contain all of these, and not just |
We could publish a parser but it would be even better to fix the go command to make -json print only JSON. /cc @aclements who has been looking at JSON output in all.bash. |
This proposal has been added to the active column of the proposals project |
@rsc unfortunately there is some non-JSON printed to stdout, intermingled with the JSON. This is a little test module I put together to examine the various permutations:
|
Ideally all output would be printed as JSON when the |
I agree that a good first step would be to fix I think it would be fine to also publish a standard Go struct definition, but at that point the parser shouldn't need to be anything other than a standard JSON parser. |
Following up on the thought to publish a package, we briefly talked about this on today's tools call. Some points raised between Bryan and myself:
|
cc @aclements for visibility, who has been writing tooling parsing test JSON output. |
I would definitely consider emitting any non-json to be a bug that we should fix. Thanks for the reproducer example. I've been working on support for Once the output is purely JSON, I'm not clear that a standard parser is especially valuable. The struct is quite simple (especially compared to, e.g., the types emitted by |
Filed #54378 for fixing go test -json. I think we can probably hold this discussion until that's done. |
Actually, I take this back. This is easy to do with |
I agree that if #54378 is addressed then the proposed package is of little utility, or that it can live elsewhere outside the Go project itself. (I'll consider releasing my continuous build stuff as an open source project at some point.) I'll close this issue. If #54378 doesn't satisfactorily address the overall issues then we can revisit. Thanks all! |
Placed on hold. |
As part of my project's presubmit process we run our sizable suite of Go unit tests with
go test ./...
, and I wrote a package to parse the output ofgo test -json
into a hierarchy of Go structs, so that we can then return just the failing test's output as comments on the code review.Before I wrote the package I had a look around the ecosystem for a similar such package, and was surprised that I couldn't find one. It was non-trivial to write because the output of
go test -json
unfortunately is not entirely JSON; if there are build failures, for example, they are returned as plain text lines. My package handles these.Would it be worth adding such a package to
golang.org/x/tools
(or somewhere)? I'd be happy to design and implement it, based on my experience doing it for my project.The text was updated successfully, but these errors were encountered: