Skip to content

Commit cb3436f

Browse files
committed
parser/gotest: Do not ignore failures in a test summary
The ReportBuilder ignores summary results if we never collected any events for that package. While under normal circumstances we wouldn't expect this to happen (unless some output was lost or due to a bug in go-junit-report), we should at the very least make sure that failed results are not ignored. Refs #145
1 parent 77475bf commit cb3436f

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

parser/gotest/report_builder.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,16 @@ func (b *reportBuilder) CreatePackage(packageName, newPackageName, result string
164164
delete(b.packageBuilders, packageName)
165165
pb.output.SetActiveID(0)
166166

167+
// If the packageBuilder is empty, we never received any events for this
168+
// package so there's no need to continue.
167169
if pb.IsEmpty() {
170+
// However, we should at least report an error if the result says we
171+
// failed.
172+
if parseResult(result) == gtr.Fail {
173+
pkg.RunError = gtr.Error{
174+
Name: newPackageName,
175+
}
176+
}
168177
return pkg
169178
}
170179

parser/gotest/report_builder_test.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -349,3 +349,31 @@ func TestGroupBenchmarksByName(t *testing.T) {
349349
})
350350
}
351351
}
352+
353+
func TestReportFailedSummary(t *testing.T) {
354+
events := []Event{
355+
{Type: "summary", Result: "FAIL", Name: "package/name", Duration: 1 * time.Millisecond},
356+
}
357+
want := gtr.Report{
358+
Packages: []gtr.Package{
359+
{
360+
Name: "package/name",
361+
Duration: 1 * time.Millisecond,
362+
Timestamp: testTimestamp,
363+
RunError: gtr.Error{
364+
Name: "package/name",
365+
},
366+
},
367+
},
368+
}
369+
370+
rb := newReportBuilder()
371+
rb.timestampFunc = testTimestampFunc
372+
for _, ev := range events {
373+
rb.ProcessEvent(ev)
374+
}
375+
got := rb.Build()
376+
if diff := cmp.Diff(want, got); diff != "" {
377+
t.Errorf("Incorrect report created, diff (-want, +got):\n%v\n", diff)
378+
}
379+
}

0 commit comments

Comments
 (0)