Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add AddSpecialSuiteFailureReasons to reduce boilerplate #1411

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions ginkgo/internal/profiles_and_reports.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,13 +107,13 @@ func FinalizeProfilesAndReportsForSuites(suites TestSuites, cliConfig types.CLIC
}
switch suite.State {
case TestSuiteStateFailedToCompile:
report.SpecialSuiteFailureReasons = append(report.SpecialSuiteFailureReasons, suite.CompilationError.Error())
report.AddSpecialSuiteFailureReasons(suite.CompilationError.Error())
case TestSuiteStateFailedDueToTimeout:
report.SpecialSuiteFailureReasons = append(report.SpecialSuiteFailureReasons, TIMEOUT_ELAPSED_FAILURE_REASON)
report.AddSpecialSuiteFailureReasons(TIMEOUT_ELAPSED_FAILURE_REASON)
case TestSuiteStateSkippedDueToPriorFailures:
report.SpecialSuiteFailureReasons = append(report.SpecialSuiteFailureReasons, PRIOR_FAILURES_FAILURE_REASON)
report.AddSpecialSuiteFailureReasons(PRIOR_FAILURES_FAILURE_REASON)
case TestSuiteStateSkippedDueToEmptyCompilation:
report.SpecialSuiteFailureReasons = append(report.SpecialSuiteFailureReasons, EMPTY_SKIP_FAILURE_REASON)
report.AddSpecialSuiteFailureReasons(EMPTY_SKIP_FAILURE_REASON)
report.SuiteSucceeded = true
}

Expand Down
12 changes: 6 additions & 6 deletions internal/suite.go
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,7 @@ func (suite *Suite) runSpecs(description string, suiteLabels Labels, suitePath s
for {
groupedSpecIdx, err := nextIndex()
if err != nil {
suite.report.SpecialSuiteFailureReasons = append(suite.report.SpecialSuiteFailureReasons, fmt.Sprintf("Failed to iterate over specs:\n%s", err.Error()))
suite.report.AddSpecialSuiteFailureReasons(fmt.Sprintf("Failed to iterate over specs:\n%s", err.Error()))
suite.report.SuiteSucceeded = false
break
}
Expand All @@ -490,12 +490,12 @@ func (suite *Suite) runSpecs(description string, suiteLabels Labels, suitePath s
}

if suite.config.FailOnPending && specs.HasAnySpecsMarkedPending() {
suite.report.SpecialSuiteFailureReasons = append(suite.report.SpecialSuiteFailureReasons, "Detected pending specs and --fail-on-pending is set")
suite.report.AddSpecialSuiteFailureReasons("Detected pending specs and --fail-on-pending is set")
suite.report.SuiteSucceeded = false
}

if suite.config.FailOnEmpty && specs.CountWithoutSkip() == 0 {
suite.report.SpecialSuiteFailureReasons = append(suite.report.SpecialSuiteFailureReasons, "Detected no specs ran and --fail-on-empty is set")
suite.report.AddSpecialSuiteFailureReasons("Detected no specs ran and --fail-on-empty is set")
suite.report.SuiteSucceeded = false
}
}
Expand All @@ -506,13 +506,13 @@ func (suite *Suite) runSpecs(description string, suiteLabels Labels, suitePath s

interruptStatus := suite.interruptHandler.Status()
if interruptStatus.Interrupted() {
suite.report.SpecialSuiteFailureReasons = append(suite.report.SpecialSuiteFailureReasons, interruptStatus.Cause.String())
suite.report.AddSpecialSuiteFailureReasons(interruptStatus.Cause.String())
suite.report.SuiteSucceeded = false
}
suite.report.EndTime = time.Now()
suite.report.RunTime = suite.report.EndTime.Sub(suite.report.StartTime)
if !suite.deadline.IsZero() && suite.report.EndTime.After(suite.deadline) {
suite.report.SpecialSuiteFailureReasons = append(suite.report.SpecialSuiteFailureReasons, "Suite Timeout Elapsed")
suite.report.AddSpecialSuiteFailureReasons("Suite Timeout Elapsed")
suite.report.SuiteSucceeded = false
}

Expand Down Expand Up @@ -540,7 +540,7 @@ func (suite *Suite) runBeforeSuite(numSpecsThatWillBeRun int) {
suite.reporter.WillRun(suite.currentSpecReport)
suite.runSuiteNode(beforeSuiteNode)
if suite.currentSpecReport.State.Is(types.SpecStateSkipped) {
suite.report.SpecialSuiteFailureReasons = append(suite.report.SpecialSuiteFailureReasons, "Suite skipped in BeforeSuite")
suite.report.AddSpecialSuiteFailureReasons("Suite skipped in BeforeSuite")
suite.skipAll = true
}
suite.processCurrentSpecReport()
Expand Down
24 changes: 16 additions & 8 deletions types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,17 +72,21 @@ type PreRunStats struct {

// Add is used by Ginkgo's parallel aggregation mechanisms to combine test run reports form individual parallel processes
// to form a complete final report.
func (report Report) Add(other Report) Report {
report.SuiteSucceeded = report.SuiteSucceeded && other.SuiteSucceeded
func (report *Report) Add(other Report) Report {
newReport := *report
newReport.SuiteSucceeded = report.SuiteSucceeded && other.SuiteSucceeded

if other.StartTime.Before(report.StartTime) {
report.StartTime = other.StartTime
newReport.StartTime = other.StartTime
}

if other.EndTime.After(report.EndTime) {
report.EndTime = other.EndTime
newReport.EndTime = other.EndTime
}

newReport.RunTime = newReport.EndTime.Sub(newReport.StartTime)

// combine specialSuiteFailureReasons without duplicates
specialSuiteFailureReasons := []string{}
reasonsLookup := map[string]bool{}
for _, reasons := range [][]string{report.SpecialSuiteFailureReasons, other.SpecialSuiteFailureReasons} {
Expand All @@ -93,18 +97,22 @@ func (report Report) Add(other Report) Report {
}
}
}
report.SpecialSuiteFailureReasons = specialSuiteFailureReasons
report.RunTime = report.EndTime.Sub(report.StartTime)
newReport.SpecialSuiteFailureReasons = specialSuiteFailureReasons

// combine reports
reports := make(SpecReports, len(report.SpecReports)+len(other.SpecReports))
copy(reports, report.SpecReports)
offset := len(report.SpecReports)
for i := range other.SpecReports {
reports[i+offset] = other.SpecReports[i]
}
newReport.SpecReports = reports

return newReport
}

report.SpecReports = reports
return report
func (report *Report) AddSpecialSuiteFailureReasons(reason string) {
report.SpecialSuiteFailureReasons = append(report.SpecialSuiteFailureReasons, reason)
}

// SpecReport captures information about a Ginkgo spec.
Expand Down
Loading