gotestsum icon indicating copy to clipboard operation
gotestsum copied to clipboard

support reading stdout/stderr from streams

Open pohly opened this issue 1 year ago • 1 comments

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 avatar Jun 15 '24 09:06 pohly

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

pohly avatar Jun 16 '24 13:06 pohly