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