jstemmer / go-junit-report

Convert Go test output to JUnit XML
MIT License
776 stars 224 forks source link

Allow output to be written to file and input to go to stdout. #37

Closed rynbrd closed 2 years ago

rynbrd commented 8 years ago

I'd like to have the option to print the go test output as well as generate the report. This does that.

This functionality is important because the regular go test output includes more details.

willdurand commented 8 years ago

:+1:

willdurand commented 8 years ago

@BlueDragonX with your last commit, if the file does not already exist, an error is raised:

Error opening file: open /tmp/circle-junit.7fwGXom/go-report.xml: no such file or directory
rmmh commented 7 years ago

The normal usage is:

go test -v | go-junit-report > report.xml

Why not use tee for this?

go test -v | tee report.txt | go-junit-report > report.xml

Or

go test -v | tee -a report.txt | go-junit-report > report.xml
rynbrd commented 7 years ago

Your usage of tee outputs to a file. My update outputs to stdout.

Doesn't matter much. I'm now tee'ing to an intermediate file and cat'ing that to this tool.

rmmh commented 7 years ago

Oh, that makes sense. You can use bash process substitution for this:

go test -v | tee >(go-junit-report > report.xml)

We can add that to the README.

sagikazarmark commented 5 years ago

The problem with that solution is that exit codes will travel through the pipe.

set -o pipefail fixes that too

jhg03a commented 5 years ago

A full example without pipefail might look like:

(go test -v 2>&1 | tee tests.log && exit ${PIPESTATUS[0]}) | ./go-junit-report --package-name=golang.test.unit --set-exit-code > tests.junit.xml
janisz commented 4 years ago

How to use this on Windows builds? I think flag to print input to stdout will help with cross platform scripts. Eg /dev/stderr does not exist on Windows.

jstemmer commented 2 years ago

Thanks for the PR. The recently released v2.0.0 supports writing output to a file and writing the input to stdout. I no longer intend to maintain the old v1 branch, so I'm closing this PR.