mirror of
https://github.com/jstemmer/go-junit-report.git
synced 2025-05-20 10:54:28 -05:00
gtr: Also look at failures in benchmarks when creating a package
When we encounter a failure but there was not failing test, we create a failing dummy test in the report. This is to prevent the failure from being overlooked. The case where the output contained a failing benchmark was not handled correctly, resulting in a dummy test failure being added to the report unnecessarily.
This commit is contained in:
parent
d05abd4130
commit
46e0aed494
@ -236,7 +236,7 @@ func (b *reportBuilder) CreatePackage(name, result string, duration time.Duratio
|
|||||||
|
|
||||||
// If the summary result says we failed, but there were no failing tests
|
// If the summary result says we failed, but there were no failing tests
|
||||||
// then something else must have failed.
|
// then something else must have failed.
|
||||||
if parseResult(result) == gtr.Fail && (len(b.tests) > 0 || len(b.benchmarks) > 0) && !b.containsFailingTest() {
|
if parseResult(result) == gtr.Fail && (len(b.tests) > 0 || len(b.benchmarks) > 0) && !b.containsFailures() {
|
||||||
pkg.RunError = gtr.Error{
|
pkg.RunError = gtr.Error{
|
||||||
Name: name,
|
Name: name,
|
||||||
Output: b.output.Get(globalID),
|
Output: b.output.Get(globalID),
|
||||||
@ -348,14 +348,19 @@ func (b *reportBuilder) findBenchmark(name string) (int, bool) {
|
|||||||
return 0, false
|
return 0, false
|
||||||
}
|
}
|
||||||
|
|
||||||
// containsFailingTest return true if the current list of tests contains at
|
// containsFailures return true if the current list of tests or benchmarks
|
||||||
// least one failing test or an unknown result.
|
// contains at least one failing test or an unknown result.
|
||||||
func (b *reportBuilder) containsFailingTest() bool {
|
func (b *reportBuilder) containsFailures() bool {
|
||||||
for _, test := range b.tests {
|
for _, test := range b.tests {
|
||||||
if test.Result == gtr.Fail || test.Result == gtr.Unknown {
|
if test.Result == gtr.Fail || test.Result == gtr.Unknown {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
for _, bm := range b.benchmarks {
|
||||||
|
if bm.Result == gtr.Fail || bm.Result == gtr.Unknown {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
10
testdata/036-report.xml
vendored
10
testdata/036-report.xml
vendored
@ -1,6 +1,6 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<testsuites tests="4" errors="1" failures="2" skipped="1">
|
<testsuites tests="3" failures="2" skipped="1">
|
||||||
<testsuite name="package/name/benchfail" tests="4" failures="2" errors="1" id="0" hostname="hostname" skipped="1" time="0.002" timestamp="2022-01-01T00:00:00Z">
|
<testsuite name="package/name/benchfail" tests="3" failures="2" errors="0" id="0" hostname="hostname" skipped="1" time="0.002" timestamp="2022-01-01T00:00:00Z">
|
||||||
<properties>
|
<properties>
|
||||||
<property name="go.version" value="1.0"></property>
|
<property name="go.version" value="1.0"></property>
|
||||||
</properties>
|
</properties>
|
||||||
@ -13,11 +13,9 @@
|
|||||||
<testcase name="BenchmarkSkip" classname="package/name/benchfail" time="0.000">
|
<testcase name="BenchmarkSkip" classname="package/name/benchfail" time="0.000">
|
||||||
<skipped message="Skipped"><![CDATA[ bench_test.go:14: skip message]]></skipped>
|
<skipped message="Skipped"><![CDATA[ bench_test.go:14: skip message]]></skipped>
|
||||||
</testcase>
|
</testcase>
|
||||||
<testcase name="Failure" classname="package/name/benchfail" time="0.000">
|
<system-out><![CDATA[goos: linux
|
||||||
<error message="Runtime error"><![CDATA[goos: linux
|
|
||||||
goarch: amd64
|
goarch: amd64
|
||||||
pkg: package/name/benchfail
|
pkg: package/name/benchfail
|
||||||
exit status 1]]></error>
|
exit status 1]]></system-out>
|
||||||
</testcase>
|
|
||||||
</testsuite>
|
</testsuite>
|
||||||
</testsuites>
|
</testsuites>
|
||||||
|
10
testdata/110-report.xml
vendored
10
testdata/110-report.xml
vendored
@ -1,6 +1,6 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<testsuites tests="4" errors="1" failures="2" skipped="1">
|
<testsuites tests="3" failures="2" skipped="1">
|
||||||
<testsuite name="package/name/benchfail" tests="4" failures="2" errors="1" id="0" hostname="hostname" skipped="1" time="0.002" timestamp="2022-01-01T00:00:00Z">
|
<testsuite name="package/name/benchfail" tests="3" failures="2" errors="0" id="0" hostname="hostname" skipped="1" time="0.002" timestamp="2022-01-01T00:00:00Z">
|
||||||
<properties>
|
<properties>
|
||||||
<property name="go.version" value="1.0"></property>
|
<property name="go.version" value="1.0"></property>
|
||||||
</properties>
|
</properties>
|
||||||
@ -13,11 +13,9 @@
|
|||||||
<testcase name="BenchmarkSkip" classname="package/name/benchfail" time="0.000">
|
<testcase name="BenchmarkSkip" classname="package/name/benchfail" time="0.000">
|
||||||
<skipped message="Skipped"><![CDATA[ bench_test.go:14: skip message]]></skipped>
|
<skipped message="Skipped"><![CDATA[ bench_test.go:14: skip message]]></skipped>
|
||||||
</testcase>
|
</testcase>
|
||||||
<testcase name="Failure" classname="package/name/benchfail" time="0.000">
|
<system-out><![CDATA[goos: linux
|
||||||
<error message="Runtime error"><![CDATA[goos: linux
|
|
||||||
goarch: amd64
|
goarch: amd64
|
||||||
pkg: package/name/benchfail
|
pkg: package/name/benchfail
|
||||||
exit status 1]]></error>
|
exit status 1]]></system-out>
|
||||||
</testcase>
|
|
||||||
</testsuite>
|
</testsuite>
|
||||||
</testsuites>
|
</testsuites>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user