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, ""))
}
// 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}
}

View File

@ -350,30 +350,61 @@ func TestGroupBenchmarksByName(t *testing.T) {
}
}
func TestReportFailedSummary(t *testing.T) {
events := []Event{
{Type: "summary", Result: "FAIL", Name: "package/name", Duration: 1 * time.Millisecond},
}
want := gtr.Report{
Packages: []gtr.Package{
{
Name: "package/name",
Duration: 1 * time.Millisecond,
Timestamp: testTimestamp,
RunError: gtr.Error{
Name: "package/name",
func TestReportSpecialCases(t *testing.T) {
tests := []struct {
name string
events []Event
want gtr.Report
}{
{
"failed-summary-only",
[]Event{{Type: "summary", Result: "FAIL", Name: "package/name", Duration: 1 * time.Millisecond}},
gtr.Report{
Packages: []gtr.Package{
{
Name: "package/name",
Duration: 1 * time.Millisecond,
Timestamp: testTimestamp,
RunError: gtr.Error{
Name: "package/name",
},
},
},
},
},
{
"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"},
},
},
},
},
},
}
rb := newReportBuilder()
rb.timestampFunc = testTimestampFunc
for _, ev := range events {
rb.ProcessEvent(ev)
}
got := rb.Build()
if diff := cmp.Diff(want, got); diff != "" {
t.Errorf("Incorrect report created, diff (-want, +got):\n%v\n", diff)
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
rb := newReportBuilder()
rb.timestampFunc = testTimestampFunc
for _, ev := range test.events {
rb.ProcessEvent(ev)
}
got := rb.Build()
if diff := cmp.Diff(test.want, got); diff != "" {
t.Errorf("Incorrect report created, diff (-want, +got):\n%v\n", diff)
}
})
}
}