From 97e0285183f03a62dee963073e102f0aa08f1a90 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=ABl=20Stemmer?= Date: Sat, 17 Sep 2022 01:05:30 +0100 Subject: [PATCH] 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 --- parser/gotest/report_builder.go | 2 +- parser/gotest/report_builder_test.go | 20 ++++++++++++++++++++ testdata/038-report.xml | 11 +++++++++++ testdata/038-test-pkg-name.txt | 4 ++++ 4 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 testdata/038-report.xml create mode 100644 testdata/038-test-pkg-name.txt diff --git a/parser/gotest/report_builder.go b/parser/gotest/report_builder.go index 5d6b25b..5369d8b 100644 --- a/parser/gotest/report_builder.go +++ b/parser/gotest/report_builder.go @@ -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 diff --git a/parser/gotest/report_builder_test.go b/parser/gotest/report_builder_test.go index e4f2661..bd24bf5 100644 --- a/parser/gotest/report_builder_test.go +++ b/parser/gotest/report_builder_test.go @@ -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 { diff --git a/testdata/038-report.xml b/testdata/038-report.xml new file mode 100644 index 0000000..edb773a --- /dev/null +++ b/testdata/038-report.xml @@ -0,0 +1,11 @@ + + + + + + + + + + + diff --git a/testdata/038-test-pkg-name.txt b/testdata/038-test-pkg-name.txt new file mode 100644 index 0000000..2763c5a --- /dev/null +++ b/testdata/038-test-pkg-name.txt @@ -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