Skip to content

Commit 46e0aed

Browse files
committed
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.
1 parent d05abd4 commit 46e0aed

File tree

3 files changed

+17
-16
lines changed

3 files changed

+17
-16
lines changed

parser/gotest/report_builder.go

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ func (b *reportBuilder) CreatePackage(name, result string, duration time.Duratio
236236

237237
// If the summary result says we failed, but there were no failing tests
238238
// then something else must have failed.
239-
if parseResult(result) == gtr.Fail && (len(b.tests) > 0 || len(b.benchmarks) > 0) && !b.containsFailingTest() {
239+
if parseResult(result) == gtr.Fail && (len(b.tests) > 0 || len(b.benchmarks) > 0) && !b.containsFailures() {
240240
pkg.RunError = gtr.Error{
241241
Name: name,
242242
Output: b.output.Get(globalID),
@@ -348,14 +348,19 @@ func (b *reportBuilder) findBenchmark(name string) (int, bool) {
348348
return 0, false
349349
}
350350

351-
// containsFailingTest return true if the current list of tests contains at
352-
// least one failing test or an unknown result.
353-
func (b *reportBuilder) containsFailingTest() bool {
351+
// containsFailures return true if the current list of tests or benchmarks
352+
// contains at least one failing test or an unknown result.
353+
func (b *reportBuilder) containsFailures() bool {
354354
for _, test := range b.tests {
355355
if test.Result == gtr.Fail || test.Result == gtr.Unknown {
356356
return true
357357
}
358358
}
359+
for _, bm := range b.benchmarks {
360+
if bm.Result == gtr.Fail || bm.Result == gtr.Unknown {
361+
return true
362+
}
363+
}
359364
return false
360365
}
361366

testdata/036-report.xml

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<testsuites tests="4" errors="1" failures="2" skipped="1">
3-
<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">
2+
<testsuites tests="3" failures="2" skipped="1">
3+
<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">
44
<properties>
55
<property name="go.version" value="1.0"></property>
66
</properties>
@@ -13,11 +13,9 @@
1313
<testcase name="BenchmarkSkip" classname="package/name/benchfail" time="0.000">
1414
<skipped message="Skipped"><![CDATA[ bench_test.go:14: skip message]]></skipped>
1515
</testcase>
16-
<testcase name="Failure" classname="package/name/benchfail" time="0.000">
17-
<error message="Runtime error"><![CDATA[goos: linux
16+
<system-out><![CDATA[goos: linux
1817
goarch: amd64
1918
pkg: package/name/benchfail
20-
exit status 1]]></error>
21-
</testcase>
19+
exit status 1]]></system-out>
2220
</testsuite>
2321
</testsuites>

testdata/110-report.xml

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<testsuites tests="4" errors="1" failures="2" skipped="1">
3-
<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">
2+
<testsuites tests="3" failures="2" skipped="1">
3+
<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">
44
<properties>
55
<property name="go.version" value="1.0"></property>
66
</properties>
@@ -13,11 +13,9 @@
1313
<testcase name="BenchmarkSkip" classname="package/name/benchfail" time="0.000">
1414
<skipped message="Skipped"><![CDATA[ bench_test.go:14: skip message]]></skipped>
1515
</testcase>
16-
<testcase name="Failure" classname="package/name/benchfail" time="0.000">
17-
<error message="Runtime error"><![CDATA[goos: linux
16+
<system-out><![CDATA[goos: linux
1817
goarch: amd64
1918
pkg: package/name/benchfail
20-
exit status 1]]></error>
21-
</testcase>
19+
exit status 1]]></system-out>
2220
</testsuite>
2321
</testsuites>

0 commit comments

Comments
 (0)