Skip to content
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

read "go test" output from stdin #414

Open
pohly opened this issue Jun 14, 2024 · 4 comments · May be fixed by #415
Open

read "go test" output from stdin #414

pohly opened this issue Jun 14, 2024 · 4 comments · May be fixed by #415

Comments

@pohly
Copy link

pohly commented Jun 14, 2024

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?

@pohly
Copy link
Author

pohly commented Jun 15, 2024

Work in progress, feedback on command line flags welcome: #415

@pohly pohly linked a pull request Jun 16, 2024 that will close this issue
@dnephin
Copy link
Member

dnephin commented Jun 17, 2024

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:

  1. you lose the output that is sent to stderr (or force the tool to have to demux both streams from stdout)
  2. if you are not very careful with shell options you lose the status code from the go test process. There have been enough bugs with test2json parsing 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!

@pohly
Copy link
Author

pohly commented Jun 17, 2024

Indeed, these are the two drawbacks. The documentation in #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...

@pohly
Copy link
Author

pohly commented Jun 17, 2024

I'm checking whether we want to go the --raw-command <script> route after all (https://github.com/kubernetes/kubernetes/pull/125534/files#r1642283167).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants