jstemmer / go-junit-report

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

Whitespace trimmed from stack trace? #131

Closed alexec closed 2 years ago

alexec commented 2 years ago

I've been working on a project to convert junit.xml to HTML using Golang.

image

I've noted that the test seems to trim white-space:

panic: kaboom! [recovered]
    panic: kaboom!

goroutine 21 [running]:
testing.tRunner.func1.2({0x10fe060, 0x114a120})
    /usr/local/Cellar/go/1.18.1/libexec/src/testing/testing.go:1389 +0x24e
testing.tRunner.func1()
    /usr/local/Cellar/go/1.18.1/libexec/src/testing/testing.go:1392 +0x39f
panic({0x10fe060, 0x114a120})
    /usr/local/Cellar/go/1.18.1/libexec/src/runtime/panic.go:838 +0x207
github.com/alexec/junit2html/example.kaboom(...)
    /Users/acollins8/go/src/github.com/alexec/junit2html/example/example.go:10
github.com/alexec/junit2html/example.TestPanic(0x0?)
    /Users/acollins8/go/src/github.com/alexec/junit2html/example/example_test.go:18 +0x27
testing.tRunner(0xc000119a00, 0x1128fa8)
    /usr/local/Cellar/go/1.18.1/libexec/src/testing/testing.go:1439 +0x102
created by testing.(*T).Run
    /usr/local/Cellar/go/1.18.1/libexec/src/testing/testing.go:1486 +0x35f
FAIL    github.com/alexec/junit2html/example    0.566s
FAIL
<?xml version="1.0" encoding="UTF-8"?>
<testsuites>
    <testsuite tests="4" failures="2" time="0.168" name="github.com/alexec/junit2html/example">
        <properties>
            <property name="go.version" value="go1.18.1"></property>
        </properties>
        <testcase classname="example" name="TestPassing" time="0.000"></testcase>
        <testcase classname="example" name="TestFailing" time="0.000">
            <failure message="Failed" type="">    example_test.go:10: this test failed</failure>
        </testcase>
        <testcase classname="example" name="TestSkipped" time="0.000">
            <skipped message="    example_test.go:14: this test is skipped"></skipped>
        </testcase>
        <testcase classname="example" name="TestPanic" time="0.000">
            <failure message="Failed" type="">panic: kaboom!&#xA;/usr/local/Cellar/go/1.18.1/libexec/src/testing/testing.go:1389 +0x24e&#xA;/usr/local/Cellar/go/1.18.1/libexec/src/testing/testing.go:1392 +0x39f&#xA;/usr/local/Cellar/go/1.18.1/libexec/src/runtime/panic.go:838 +0x207&#xA;/Users/acollins8/go/src/github.com/alexec/junit2html/example/example.go:10&#xA;/Users/acollins8/go/src/github.com/alexec/junit2html/example/example_test.go:18 +0x31&#xA;/usr/local/Cellar/go/1.18.1/libexec/src/testing/testing.go:1439 +0x102&#xA;/usr/local/Cellar/go/1.18.1/libexec/src/testing/testing.go:1486 +0x35f</failure>
        </testcase>
    </testsuite>
</testsuites>
jstemmer commented 2 years ago

Thanks for the bug report.

I can see some missing lines in your example, so you must still be using the older version of go-junit-report (see #123). I'd recommend giving v2 a try (note that it's a beta, so the API could change until a v2 stable is released).

I'll disable whitespace trimming in v2 for now since it indeed doesn't work as intended in some cases.