jstemmer / go-junit-report

Convert Go test output to JUnit XML
MIT License
764 stars 222 forks source link

`go test` without `-v` still gets partially parsed, and returns 0 failures #109

Closed nickatsegment closed 2 years ago

nickatsegment commented 4 years ago

I forgot that this tool apparently only parses go test -v, not go test without -v. But the error handling of this is abysmal! It simply reports 0 failures.

$ docker run golang:1.13 bash -c 'GO111MODULE=off go get -u github.com/jstemmer/go-junit-report
cd /tmp
cat > broken_test.go <<!
package main
import "testing"

func TestAlwaysFail(t *testing.T) {
        t.FailNow()
}
!
go test .
go test . | go-junit-report
'
Unable to find image 'golang:1.13' locally
1.13: Pulling from library/golang
376057ac6fa1: Already exists
5a63a0a859d8: Already exists
496548a8c952: Already exists
2adae3950d4d: Already exists
039b991354af: Already exists
036abadca78f: Pull complete
0514917ef7dc: Pull complete
Digest: sha256:c56dbb28a169f9bccdf398dc9d4bc8d41463352843dbcf03b6ef2fb3472c1794
Status: Downloaded newer image for golang:1.13
--- FAIL: TestAlwaysFail (0.00s)
FAIL
FAIL    _/tmp   0.002s
FAIL
<?xml version="1.0" encoding="UTF-8"?>
<testsuites>
    <testsuite tests="0" failures="0" time="0.002" name="_/tmp">
        <properties>
            <property name="go.version" value="go1.13.12"></property>
        </properties>
    </testsuite>
</testsuites>

vs working:

... -v
=== RUN   TestAlwaysFail
--- FAIL: TestAlwaysFail (0.00s)
FAIL
FAIL    _/tmp   0.003s
FAIL
<?xml version="1.0" encoding="UTF-8"?>
<testsuites>
    <testsuite tests="1" failures="1" time="0.002" name="_/tmp">
        <properties>
            <property name="go.version" value="go1.13.12"></property>
        </properties>
        <testcase classname="tmp" name="TestAlwaysFail" time="0.000">
            <failure message="Failed" type=""></failure>
        </testcase>
    </testsuite>
</testsuites>

Could we detect when it's in the wrong format and throw an error?

jstemmer commented 2 years ago

This has been fixed in v2.0.0-beta.