Skip to content

Commit 97e0285

Browse files
committed
parser/gotest: Handle build errors in test packages with _test suffix
It's possible for test files to declare a package with the "_test" suffix. If these packages contain build errors, they were not correctly matched to the package without the "_test" suffix. Refs #145
1 parent 81e5aaa commit 97e0285

File tree

4 files changed

+36
-1
lines changed

4 files changed

+36
-1
lines changed

parser/gotest/report_builder.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ func (b *reportBuilder) CreatePackage(packageName, newPackageName, result string
150150
// First check if this package contained a build error. If that's the case,
151151
// we won't find any tests in this package.
152152
for id, buildErr := range b.buildErrors {
153-
if buildErr.Name == newPackageName {
153+
if buildErr.Name == newPackageName || strings.TrimSuffix(buildErr.Name, "_test") == newPackageName {
154154
pkg.BuildError = buildErr
155155
pkg.BuildError.ID = id
156156
pkg.BuildError.Duration = duration

parser/gotest/report_builder_test.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,26 @@ func TestReportSpecialCases(t *testing.T) {
392392
},
393393
},
394394
},
395+
{
396+
"build error in package with _test suffix",
397+
[]Event{
398+
{Type: "build_output", Name: "package/name_test"},
399+
{Type: "summary", Name: "package/name", Result: "FAIL", Data: "[build failed]"},
400+
},
401+
gtr.Report{
402+
Packages: []gtr.Package{
403+
{
404+
Name: "package/name",
405+
Timestamp: testTimestamp,
406+
BuildError: gtr.Error{
407+
ID: 1,
408+
Name: "package/name_test",
409+
Cause: "[build failed]",
410+
},
411+
},
412+
},
413+
},
414+
},
395415
}
396416

397417
for _, test := range tests {

testdata/038-report.xml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<testsuites tests="1" errors="1">
3+
<testsuite name="package/testpkg/pkg" tests="1" failures="0" errors="1" id="0" hostname="hostname" time="0.000" timestamp="2022-01-01T00:00:00Z">
4+
<properties>
5+
<property name="go.version" value="1.0"></property>
6+
</properties>
7+
<testcase name="[build failed]" classname="package/testpkg/pkg_test" time="0.000">
8+
<error message="Build error"><![CDATA[pkg/pkg_test.go:5:2: imported and not used: "fmt"]]></error>
9+
</testcase>
10+
</testsuite>
11+
</testsuites>

testdata/038-test-pkg-name.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# package/testpkg/pkg_test [package/testpkg/pkg.test]
2+
pkg/pkg_test.go:5:2: imported and not used: "fmt"
3+
FAIL package/testpkg/pkg [build failed]
4+
FAIL

0 commit comments

Comments
 (0)