gotestyourself / gotestsum

'go test' runner with output optimized for humans, JUnit XML for CI integration, and a summary of the test results.
Apache License 2.0
1.99k stars 118 forks source link

support reading stdout/stderr from streams #415

Open pohly opened 1 month ago

pohly commented 1 month ago

It can be useful to let the user run the test command(s) itself, for example when complex shell scripts are involved which need to invoke go test multiple times.

With -stdin, the go test stdout is expected on stdin of gotestsum, so it can be used in a pipe. To detect abnormal termination of the test commands, bash with "set -o pipefail" should be used. Beware that such failures are not detected by gotestsum.

To also capture stderr with gotestsum, stderr must get redirected like this:

mkfifo /tmp/pipe
go test ... 2>/tmp/pipe | gotestsum -stdin -stderr 3 3</tmp/pipe

Fixes: https://github.com/gotestyourself/gotestsum/issues/414

pohly commented 1 month ago

I added documentation and unit tests. I also checked that this really works for Kubernetes: https://github.com/kubernetes/kubernetes/pull/125534.