diff --git a/fmt.go b/fmt.go index 00686ce..3c7ad6e 100644 --- a/fmt.go +++ b/fmt.go @@ -221,7 +221,9 @@ func (f *basefmt) Summary() { total++ case *gherkin.ScenarioOutline: for _, ex := range t.Examples { - total += len(ex.TableBody) + if examples, hasExamples := examples(ex); hasExamples { + total += len(examples.TableBody) + } } } } diff --git a/fmt_pretty.go b/fmt_pretty.go index 9354c3a..0fc83e6 100644 --- a/fmt_pretty.go +++ b/fmt_pretty.go @@ -122,7 +122,13 @@ func (f *pretty) printOutlineExample(outline *gherkin.ScenarioOutline) { var msg string clr := green - example := outline.Examples[f.outlineNumExample] + ex := outline.Examples[f.outlineNumExample] + example, hasExamples := examples(ex) + if !hasExamples { + // do not print empty examples + return + } + firstExample := f.outlineNumExamples == len(example.TableBody) printSteps := firstExample && f.outlineNumExample == 0 diff --git a/gherkin.go b/gherkin.go new file mode 100644 index 0000000..80c6b36 --- /dev/null +++ b/gherkin.go @@ -0,0 +1,10 @@ +package godog + +import "gopkg.in/cucumber/gherkin-go.v3" + +// examples is a helper func to cast gherkin.Examples +// or gherkin.BaseExamples if its empty +func examples(ex interface{}) (*gherkin.Examples, bool) { + t, ok := ex.(*gherkin.Examples) + return t, ok +} diff --git a/suite.go b/suite.go index d2df014..ce359dd 100644 --- a/suite.go +++ b/suite.go @@ -265,9 +265,16 @@ func (s *Suite) skipSteps(steps []*gherkin.Step) { func (s *Suite) runOutline(outline *gherkin.ScenarioOutline, b *gherkin.Background) (failErr error) { s.fmt.Node(outline) - for _, example := range outline.Examples { - s.fmt.Node(example) + for _, ex := range outline.Examples { + example, hasExamples := examples(ex) + if !hasExamples { + // @TODO: may need to print empty example node, but + // for backward compatibility, cannot cast to *gherkin.ExamplesBase + // at the moment + continue + } + s.fmt.Node(example) placeholders := example.TableHeader.Cells groups := example.TableBody