Skip to content

Commit

Permalink
Fix nil ptr access (#8)
Browse files Browse the repository at this point in the history
  • Loading branch information
vearutop authored Jul 7, 2023
1 parent b3fd3b6 commit 54a74a4
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions formatter.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,23 +191,29 @@ func (f *formatter) step(sc *godog.Scenario, st *godog.Step, status report.Statu
}
}

func statusDetails(prefix string, sd *godog.StepDefinition) *report.StatusDetails {
if sd == nil || sd.Expr == nil {
return nil
}

return &report.StatusDetails{
Message: prefix + sd.Expr.String(),
}
}

// Passed captures passed step.
func (f *formatter) Passed(sc *godog.Scenario, st *godog.Step, _ *godog.StepDefinition) {
f.step(sc, st, report.Passed, nil)
}

// Skipped captures skipped step.
func (f *formatter) Skipped(sc *godog.Scenario, st *godog.Step, sd *godog.StepDefinition) {
f.step(sc, st, report.Skipped, &report.StatusDetails{
Message: "Skipped: " + sd.Expr.String(),
})
f.step(sc, st, report.Skipped, statusDetails("Skipped: ", sd))
}

// Undefined captures undefined step.
func (f *formatter) Undefined(sc *godog.Scenario, st *godog.Step, sd *godog.StepDefinition) {
f.step(sc, st, report.Broken, &report.StatusDetails{
Message: "Undefined: " + sd.Expr.String(),
})
f.step(sc, st, report.Broken, statusDetails("Undefined: ", sd))
}

// Failed captures failed step.
Expand All @@ -219,9 +225,7 @@ func (f *formatter) Failed(sc *godog.Scenario, st *godog.Step, _ *godog.StepDefi

// Pending captures pending step.
func (f *formatter) Pending(sc *godog.Scenario, st *godog.Step, sd *godog.StepDefinition) {
f.step(sc, st, report.Unknown, &report.StatusDetails{
Message: "Pending: " + sd.Expr.String(),
})
f.step(sc, st, report.Unknown, statusDetails("Pending: ", sd))
}

// Summary finishes report.
Expand Down

0 comments on commit 54a74a4

Please sign in to comment.