Skip to content

Commit

Permalink
parser/gotest: Handle build errors in test packages with _test suffix
Browse files Browse the repository at this point in the history
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
  • Loading branch information
jstemmer committed Sep 17, 2022
1 parent 81e5aaa commit 97e0285
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 1 deletion.
2 changes: 1 addition & 1 deletion parser/gotest/report_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ func (b *reportBuilder) CreatePackage(packageName, newPackageName, result string
// First check if this package contained a build error. If that's the case,
// we won't find any tests in this package.
for id, buildErr := range b.buildErrors {
if buildErr.Name == newPackageName {
if buildErr.Name == newPackageName || strings.TrimSuffix(buildErr.Name, "_test") == newPackageName {
pkg.BuildError = buildErr
pkg.BuildError.ID = id
pkg.BuildError.Duration = duration
Expand Down
20 changes: 20 additions & 0 deletions parser/gotest/report_builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,26 @@ func TestReportSpecialCases(t *testing.T) {
},
},
},
{
"build error in package with _test suffix",
[]Event{
{Type: "build_output", Name: "package/name_test"},
{Type: "summary", Name: "package/name", Result: "FAIL", Data: "[build failed]"},
},
gtr.Report{
Packages: []gtr.Package{
{
Name: "package/name",
Timestamp: testTimestamp,
BuildError: gtr.Error{
ID: 1,
Name: "package/name_test",
Cause: "[build failed]",
},
},
},
},
},
}

for _, test := range tests {
Expand Down
11 changes: 11 additions & 0 deletions testdata/038-report.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<testsuites tests="1" errors="1">
<testsuite name="package/testpkg/pkg" tests="1" failures="0" errors="1" id="0" hostname="hostname" time="0.000" timestamp="2022-01-01T00:00:00Z">
<properties>
<property name="go.version" value="1.0"></property>
</properties>
<testcase name="[build failed]" classname="package/testpkg/pkg_test" time="0.000">
<error message="Build error"><![CDATA[pkg/pkg_test.go:5:2: imported and not used: "fmt"]]></error>
</testcase>
</testsuite>
</testsuites>
4 changes: 4 additions & 0 deletions testdata/038-test-pkg-name.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# package/testpkg/pkg_test [package/testpkg/pkg.test]
pkg/pkg_test.go:5:2: imported and not used: "fmt"
FAIL package/testpkg/pkg [build failed]
FAIL

0 comments on commit 97e0285

Please sign in to comment.