From cb3436fc5f5313516740d5dfe1926ebe6fad0b06 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=ABl=20Stemmer?= Date: Sat, 17 Sep 2022 00:06:11 +0100 Subject: [PATCH] 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 --- parser/gotest/report_builder.go | 9 +++++++++ parser/gotest/report_builder_test.go | 28 ++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+) diff --git a/parser/gotest/report_builder.go b/parser/gotest/report_builder.go index d53b323..bb4676c 100644 --- a/parser/gotest/report_builder.go +++ b/parser/gotest/report_builder.go @@ -164,7 +164,16 @@ func (b *reportBuilder) CreatePackage(packageName, newPackageName, result string delete(b.packageBuilders, packageName) pb.output.SetActiveID(0) + // If the packageBuilder is empty, we never received any events for this + // package so there's no need to continue. if pb.IsEmpty() { + // However, we should at least report an error if the result says we + // failed. + if parseResult(result) == gtr.Fail { + pkg.RunError = gtr.Error{ + Name: newPackageName, + } + } return pkg } diff --git a/parser/gotest/report_builder_test.go b/parser/gotest/report_builder_test.go index 99adfca..ac3ed53 100644 --- a/parser/gotest/report_builder_test.go +++ b/parser/gotest/report_builder_test.go @@ -349,3 +349,31 @@ 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", + }, + }, + }, + } + + 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) + } +}