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
This commit is contained in:
Joël Stemmer
2022-09-17 01:05:30 +01:00
parent 81e5aaaaf1
commit 97e0285183
4 changed files with 36 additions and 1 deletions

View File

@ -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

View File

@ -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 {