parser/gotest: Make sure every build error is processed

Make sure we don't ignore any build error that did not belong to a
package. This isn't expected to normally happen, but we need to handle
it anyway to prevent accidentally ignoring potential errors.

Refs #145
This commit is contained in:
Joël Stemmer 2022-09-17 00:57:10 +01:00
parent cb3436fc5f
commit 81e5aaaaf1
2 changed files with 56 additions and 20 deletions

View File

@ -120,6 +120,11 @@ func (b *reportBuilder) Build() gtr.Report {
} }
b.packages = append(b.packages, b.CreatePackage(name, b.packageName, "", 0, "")) b.packages = append(b.packages, b.CreatePackage(name, b.packageName, "", 0, ""))
} }
// Create packages for any leftover build errors.
for _, buildErr := range b.buildErrors {
b.packages = append(b.packages, b.CreatePackage("", buildErr.Name, "", 0, ""))
}
return gtr.Report{Packages: b.packages} return gtr.Report{Packages: b.packages}
} }

View File

@ -350,11 +350,16 @@ func TestGroupBenchmarksByName(t *testing.T) {
} }
} }
func TestReportFailedSummary(t *testing.T) { func TestReportSpecialCases(t *testing.T) {
events := []Event{ tests := []struct {
{Type: "summary", Result: "FAIL", Name: "package/name", Duration: 1 * time.Millisecond}, name string
} events []Event
want := gtr.Report{ want gtr.Report
}{
{
"failed-summary-only",
[]Event{{Type: "summary", Result: "FAIL", Name: "package/name", Duration: 1 * time.Millisecond}},
gtr.Report{
Packages: []gtr.Package{ Packages: []gtr.Package{
{ {
Name: "package/name", Name: "package/name",
@ -365,15 +370,41 @@ func TestReportFailedSummary(t *testing.T) {
}, },
}, },
}, },
},
},
{
"leftover-builderror",
[]Event{
{Type: "build_output", Name: "package/name"},
{Type: "output", Data: "error message"},
},
gtr.Report{
Packages: []gtr.Package{
{
Name: "package/name",
Timestamp: testTimestamp,
BuildError: gtr.Error{
ID: 1,
Name: "package/name",
Output: []string{"error message"},
},
},
},
},
},
} }
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
rb := newReportBuilder() rb := newReportBuilder()
rb.timestampFunc = testTimestampFunc rb.timestampFunc = testTimestampFunc
for _, ev := range events { for _, ev := range test.events {
rb.ProcessEvent(ev) rb.ProcessEvent(ev)
} }
got := rb.Build() got := rb.Build()
if diff := cmp.Diff(want, got); diff != "" { if diff := cmp.Diff(test.want, got); diff != "" {
t.Errorf("Incorrect report created, diff (-want, +got):\n%v\n", diff) t.Errorf("Incorrect report created, diff (-want, +got):\n%v\n", diff)
} }
})
}
} }