read "go test" output from stdin
In Kubernetes, we run fairly complex commands to execute our unit tests. gotestsum is then used for post-processing with --raw-command cat <filename>.
It might be possible to turn those complex commands into a script (I'm trying...) but the shell quoting is nasty.
Would you accept a patch that makes gotestsum read input from stdin?
Work in progress, feedback on command line flags welcome: https://github.com/gotestyourself/gotestsum/pull/415
Hello! I believe it is possible to run from stdin. The readme has this example:
Example: accept intput from stdin
cat out.json | gotestsum --raw-command -- cat
I've generally suggested against running using stdin for a couple reasons:
- you lose the output that is sent to stderr (or force the tool to have to demux both streams from stdout)
- if you are not very careful with shell options you lose the status code from the
go testprocess. There have been enough bugs withtest2jsonparsing that relying on the test output for status code is too risky.
That said, I think build failures were added to go test stdout output in a relatively recent release, so maybe capturing stderr isn't as critical anymore. And It also seems like your PR has a new flag to consume that stream, which is great!
The status code I think is still a risk, so I wouldn't want to suggest this approach in general, but for a sufficient complex setup (as I imagine is the case for kubernetes) that's probably a fine tradeoff.
I've been very busy with life outside of github lately, but I will find some time to review your PR. Thank you!
Indeed, these are the two drawbacks. The documentation in https://github.com/gotestyourself/gotestsum/pull/415 addresses both.
For reference, this is the shell code which I found too hard to convert into a generated script:
https://github.com/kubernetes/kubernetes/blob/ef9965ebc66dafda37800bb04f5e284535bbba10/hack/make-rules/test.sh#L254-L266
A bash script which currently contains a bash script would have to be turned into a bash script which generates a bash script which contains a bash script...
I'm checking whether we want to go the --raw-command <script> route after all (https://github.com/kubernetes/kubernetes/pull/125534/files#r1642283167).