Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use jstemmer/go-junit-report/v2 to correctly parse the output of go test #22

Merged
merged 1 commit into from
Aug 20, 2023

Conversation

shibayu36
Copy link
Contributor

@shibayu36 shibayu36 commented Aug 19, 2023

Use jstemmer/go-junit-report/v2 to correctly parse go test output.

Problem

jstemmer/go-junit-report(v1) may not parse output correctly. For example, if I try to parse the following output, I want all the output to be put in the failure message, but only the first line is actually put in. The following output is generated by github.com/stretchr/testify/assert.

=== RUN   TestGetTestListFromPkgs
    /Users/shibayu36/development/src/github.com/Songmu/gotesplit/gotesplit_test.go:149:
        	Error Trace:	/Users/shibayu36/development/src/github.com/Songmu/gotesplit/gotesplit_test.go:149
        	Error:      	Should not be: []gotesplit.testList{gotesplit.testList{pkg:"github.com/Songmu/gotesplit/testdata/withtags", list:[]string{"TestNoTag", "TestTagA"}}}
        	Test:       	TestGetTestListFromPkgs
--- FAIL: TestGetTestListFromPkgs (0.20s)
FAIL
FAIL	github.com/Songmu/gotesplit	0.287s
<?xml version="1.0" encoding="UTF-8"?>
<testsuites>
	<testsuite tests="1" failures="1" time="0.287" name="github.com/Songmu/gotesplit">
		<properties>
			<property name="go.version" value="go1.21.0"></property>
		</properties>
		<testcase classname="gotesplit" name="TestGetTestListFromPkgs" time="0.200">
			<failure message="Failed" type="">    /Users/shibayu36/development/src/github.com/Songmu/gotesplit/gotesplit_test.go:149:</failure>
		</testcase>
	</testsuite>
</testsuites>

Solution by PR

jstemmer/go-junit-report/v2 can correctly parse output. It outputs the following when it parses the same content above.

<testsuites tests="1" failures="1">
	<testsuite name="github.com/Songmu/gotesplit" tests="1" failures="1" errors="0" id="0" time="0.287" timestamp="2023-08-20T08:55:15+09:00">
		<testcase name="TestGetTestListFromPkgs" classname="github.com/Songmu/gotesplit" time="0.200">
			<failure message="Failed"><![CDATA[    /Users/shibayu36/development/src/github.com/Songmu/gotesplit/gotesplit_test.go:149:
        	Error Trace:	/Users/shibayu36/development/src/github.com/Songmu/gotesplit/gotesplit_test.go:149
        	Error:      	Should not be: []gotesplit.testList{gotesplit.testList{pkg:"github.com/Songmu/gotesplit/testdata/withtags", list:[]string{"TestNoTag", "TestTagA"}}}
        	Test:       	TestGetTestListFromPkgs]]></failure>
		</testcase>
	</testsuite>
</testsuites>

ret.report = &junitReport{
report: report,
err: err,
}
}
return ret
}

func writeJUnitReportXML(w io.Writer, report gtr.Report) error {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copied and pasted from https://github.com/jstemmer/go-junit-report/blob/v2.0.0/internal/gojunitreport/go-junit-report.go#L73-L93.

If the master branch of go-junit-report is released, https://github.com/jstemmer/go-junit-report/blob/master/junit/junit.go#L41 can be used, but it has not been but it has not been released for a while. ref: jstemmer/go-junit-report#164

@shibayu36 shibayu36 marked this pull request as ready for review August 20, 2023 00:09
@Songmu Songmu merged commit 06878fe into Songmu:main Aug 20, 2023
4 checks passed
@Songmu
Copy link
Owner

Songmu commented Aug 20, 2023

Thanks!

@github-actions github-actions bot mentioned this pull request Aug 20, 2023
@Songmu Songmu added the minor label Aug 20, 2023
@Songmu
Copy link
Owner

Songmu commented Aug 20, 2023

I released it as v0.3.0.

@shibayu36 shibayu36 deleted the use-junit-report-v2 branch August 21, 2023 01:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants