Skip to content

Commit e9c3d69

Browse files
committed
be compatible with gherkin library changes
the downside is that if outline examples are empty it won't be pretty printed as node. But that does not make much difference anyway
1 parent 34899b4 commit e9c3d69

File tree

4 files changed

+29
-4
lines changed

4 files changed

+29
-4
lines changed

fmt.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,9 @@ func (f *basefmt) Summary() {
221221
total++
222222
case *gherkin.ScenarioOutline:
223223
for _, ex := range t.Examples {
224-
total += len(ex.TableBody)
224+
if examples, hasExamples := examples(ex); hasExamples {
225+
total += len(examples.TableBody)
226+
}
225227
}
226228
}
227229
}

fmt_pretty.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,13 @@ func (f *pretty) printOutlineExample(outline *gherkin.ScenarioOutline) {
122122
var msg string
123123
clr := green
124124

125-
example := outline.Examples[f.outlineNumExample]
125+
ex := outline.Examples[f.outlineNumExample]
126+
example, hasExamples := examples(ex)
127+
if !hasExamples {
128+
// do not print empty examples
129+
return
130+
}
131+
126132
firstExample := f.outlineNumExamples == len(example.TableBody)
127133
printSteps := firstExample && f.outlineNumExample == 0
128134

gherkin.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package godog
2+
3+
import "gopkg.in/cucumber/gherkin-go.v3"
4+
5+
// examples is a helper func to cast gherkin.Examples
6+
// or gherkin.BaseExamples if its empty
7+
func examples(ex interface{}) (*gherkin.Examples, bool) {
8+
t, ok := ex.(*gherkin.Examples)
9+
return t, ok
10+
}

suite.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -265,9 +265,16 @@ func (s *Suite) skipSteps(steps []*gherkin.Step) {
265265
func (s *Suite) runOutline(outline *gherkin.ScenarioOutline, b *gherkin.Background) (failErr error) {
266266
s.fmt.Node(outline)
267267

268-
for _, example := range outline.Examples {
269-
s.fmt.Node(example)
268+
for _, ex := range outline.Examples {
269+
example, hasExamples := examples(ex)
270+
if !hasExamples {
271+
// @TODO: may need to print empty example node, but
272+
// for backward compatibility, cannot cast to *gherkin.ExamplesBase
273+
// at the moment
274+
continue
275+
}
270276

277+
s.fmt.Node(example)
271278
placeholders := example.TableHeader.Cells
272279
groups := example.TableBody
273280

0 commit comments

Comments
 (0)