-
Notifications
You must be signed in to change notification settings - Fork 122
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
Add API to convert Execution
to JUnit XML when using gotestsum as a library
#193
Comments
Thank you for your interest in
I've been considering adding a new
I suspect the reason this isn't working is because in Another option is to use a named pipe. This seems to work for me, but is not something I've used very often.
Yup, exactly! I did not want to simply read from stdin (as other tools do) because when a package fails to build, that output goes to stderr, and I think it's important to capture that as part of the "output". Piping would either merge stderr with stdout making it harder to parse properly, or would miss the stderr entirely. So
The few times I've run the tests for the Go project I've been able to first build it with
That might allow you to run the tests with I'm also open to the idea of allowing
I'm not against that approach, but I would prefer to keep the exported API small. I'm particularly hesitant to expose the Junit XML code because it's not really standardized and it might need to change at some point to make it work better with other CI systems. I hope this helps! If for some reason none of these options work out and we can't get the |
This would be perfect! My current filter just attempts to parse each incoming line as a I tried writing this up locally, and it seems pretty simple to implement--I'll send a quick PR shortly to go further down this road and see if it'll work.
That would certainly let me filter/save JSON output to a file and send it though later without clutter. (Although I would prefer to show the nice
I'd kind of expect this to work the same way as reading from
Yeah, these reasons makes sense to me (as well as
I actually use
Very reasonable. FWIW, I got around this by creating a local module func Write(out io.Writer, exec *testjson.Execution) error {
return junitxml.Write(out, exec, junitxml.Config{})
} I think it would be fine for me to keep using that on my side so there's no pressure to add this export to |
Ah, the |
Sorry, I wasn't too clear about what I was thinking about when I wrote that--it was the idea that the stdout/stderr streams need to be kept separate and tracked for build errors:
I didn't think about some building happening during
Agreed. I think technically any Go project could create a testing tool that mixes in JSON with other output, but I don't expect many projects would want to do that. Probably only needed if there are extraordinary requirements (like Go itself has).
In case you didn't see, I submitted a quick PR for this: #194. 🙂 |
This is now merged with #194. Thanks for the quick review+feedback+fixup+merge! 😄 Closing. |
This is along the lines of #19: I'm trying to convert some
go test -json
output mixed with non-JSON lines into a format my CI server understands, and JUnit XML would work great.gotestsum
caught my eye--I don't see anything else that looks actively maintained and does this conversion.I'm able to get gotestsum to parse a filtered stream like this (
v1.6.4
):But I don't see how to turn that into JUnit XML with any existing API. This is what I think I should call next:
gotestsum/internal/junitxml/report.go
Line 74 in bb9679f
That works, but since it's
internal
, I had to copy the source code to my project or use module tricks to wrap the internal API in one that I can access. Having an exported function would help. (Or,internal/junitxml
could just be exposed and I could feed in the args myself.)More background on why I ended up at this point:
It works fine to filter the test output, save the JSON to a file, and use
gotestsum --junitxml testresults.xml --raw-command cat testoutput.json
(#19 (comment)), but:gotestsum
writes out a bunch of output I don't need. It takes a while to print and makes my build log cluttered.--hide-summary all
, but I don't see a way to disable the per-test/package lines.gotestsum
's nice output formatting, but I don't see a way to get the command line tool to accept a stream (stdin) rather than a file.cat /dev/stdin
, it terminates immediately. It's possible I'm doing something wrong, though. This has worked for me in the past for a different tool and I'm not sure what's different here. 😄My first thought was to try to get my tests to only emit JSON output, so I can plug my test command directly into
--raw-command
. I think this is whatgotestsum
is meant for. But, this seems complicated to do for my project in particular. (I'm building Go, and the project's test runner (dist
) has a lot of stuff going on I don't fully understand yet. I tried to get rid of non-JSON stdout, but it was very hard to know if I was covering all cases.)My second thought (where I am now) is to use
gotestsum
as a module dependency and use the API directly, so I can get a stream to work.I'm mentioning all of this in case I went wrong somewhere, corrections welcome. 🙂 I'm relatively new to Go.
The text was updated successfully, but these errors were encountered: