Skip to content

Commit

Permalink
feat: upgrading the gherkin cucumber version to v28 (#151)
Browse files Browse the repository at this point in the history
  • Loading branch information
svandecappelle authored Apr 29, 2024
1 parent 9d41292 commit 39e9e76
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 65 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
go: ['1.12', '1.13', '1.14', '1.15', '1.16', '1.17', '1.18', '1.19', '1.20', '1.21']
go: ['1.17', '1.18', '1.19', '1.20', '1.21', '1.22']
env:
GOFLAGS: -mod=readonly
GOPROXY: https://proxy.golang.org
Expand All @@ -47,7 +47,7 @@ jobs:

- name: Calc coverage
run: |
export PATH=$PATH:$(go env GOPATH)/bin
export PATH=$PATH:$(go env GOPATH)/bin
go test -v -covermode=count -coverprofile=coverage.out
- name: Convert coverage to lcov
Expand Down
11 changes: 7 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
module github.com/go-bdd/gobdd

go 1.16
go 1.17

require (
github.com/cucumber/gherkin-go/v13 v13.0.0
github.com/cucumber/messages-go/v12 v12.0.0
github.com/cucumber/gherkin/go/v28 v28.0.0
github.com/cucumber/messages/go/v24 v24.0.1
github.com/go-bdd/assert v0.0.0-20190820124234-20d47a68475d
github.com/stretchr/testify v1.5.1
github.com/kr/text v0.2.0 // indirect
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e // indirect
github.com/stretchr/testify v1.8.4
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f // indirect
)
35 changes: 15 additions & 20 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,38 +1,33 @@
github.com/aslakhellesoy/gox v1.0.100/go.mod h1:AJl542QsKKG96COVsv0N74HHzVQgDIQPceVUh1aeU2M=
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
github.com/cucumber/gherkin-go/v13 v13.0.0 h1:d09AwPZldyOFlCADAIZQMt7T+VHCrGdp5106+BCIfZU=
github.com/cucumber/gherkin-go/v13 v13.0.0/go.mod h1:pzMEPEIPcPOBDkE8HaWC+Ck6eDBtBmIWVksUkSin/2E=
github.com/cucumber/messages-go/v12 v12.0.0 h1:ZlZYZrYDDc35zCe0HK2y95GUcxHHqr8yB9kdrXCjnzU=
github.com/cucumber/messages-go/v12 v12.0.0/go.mod h1:5zuJu21U6rB+BBqyGoQr839a4h4GUElPnSozdHyhCOQ=
github.com/cucumber/gherkin/go/v28 v28.0.0 h1:SBqwscPOhe83JF0ukpEj+4QZ2ScOpPQByC0gD3cXBkg=
github.com/cucumber/gherkin/go/v28 v28.0.0/go.mod h1:HVwDrzWvtsVbkxHw6KVZFA79x5uSLb+ajzS0BXuHiE8=
github.com/cucumber/messages/go/v24 v24.0.1 h1:jajAQDk3fPa4RhIANE+NOxGdCKQdi7RYjd8wdKXnOu4=
github.com/cucumber/messages/go/v24 v24.0.1/go.mod h1:ns4Befq4c4n9/B5APpTlBu5kXL1DVE4+5bbe0vSV4fc=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/go-bdd/assert v0.0.0-20190820124234-20d47a68475d h1:zQazu3kApPoajWmXj9zFpCNE+UDefwwFRijKjzvHNCM=
github.com/go-bdd/assert v0.0.0-20190820124234-20d47a68475d/go.mod h1:dOoqt7g2I/fpR7/Pyz0P19J3xjDj5lsHn3v9EaFLRjM=
github.com/gofrs/uuid v3.2.0+incompatible h1:y12jRkkFxsd7GpqdSZ+/KCs/fJbqpEXSGd4+jfEaewE=
github.com/gofrs/uuid v3.2.0+incompatible/go.mod h1:b2aQJv3Z4Fp6yNu3cdSllBxTCLRxnplIgP/c0N/04lM=
github.com/gogo/protobuf v1.3.1 h1:DqDEcV5aeaTmdFBePNpYsp3FlcVH/2ISVVM9Qf8PSls=
github.com/gogo/protobuf v1.3.1/go.mod h1:SlYgWuQ5SjCEi6WLHjHCa1yvBfUnHcTbrrZtXPKa29o=
github.com/hashicorp/go-version v1.0.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA=
github.com/kisielk/errcheck v1.2.0/go.mod h1:/BMXB+zMLi60iA8Vv6Ksmxu/1UDYcXs4uQLJ+jE2L00=
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
github.com/gofrs/uuid v4.4.0+incompatible h1:3qXRTX8/NbyulANqlc0lchS1gqAVxRgsuW1YrTJupqA=
github.com/gofrs/uuid v4.4.0+incompatible/go.mod h1:b2aQJv3Z4Fp6yNu3cdSllBxTCLRxnplIgP/c0N/04lM=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/mitchellh/iochan v1.0.0/go.mod h1:JwYml1nuB7xOzsp52dPpHFffvOCDupsG0QubkSMEySY=
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e h1:fD57ERR4JtEqsWbfPhv4DMiApHyliiK5xCTNVSPiaAs=
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.5.1 h1:nOGnQDM7FYENwehXlg/kFVnos3rEvtKTjRvOWSzb6H4=
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
golang.org/x/tools v0.0.0-20181030221726-6c7e314b6563/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f h1:BLraFXnmrev5lT+xlilqcH8XK9/i0At2xKjWk4p6zsU=
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.8 h1:obN1ZagJSUGI0Ek/LBmuj4SNLPfIny3KsKFopxRdj10=
gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
74 changes: 40 additions & 34 deletions gobdd.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import (
"strings"
"testing"

gherkin "github.com/cucumber/gherkin-go/v13"
msgs "github.com/cucumber/messages-go/v12"
gherkin "github.com/cucumber/gherkin/go/v28"
msgs "github.com/cucumber/messages/go/v24"
)

// Suite holds all the information about the suite (options, steps to execute etc)
Expand Down Expand Up @@ -346,30 +346,30 @@ func (s *Suite) executeFeature(feature feature) error {
return s.runFeature(doc.Feature)
}

func (s *Suite) runFeature(feature *msgs.GherkinDocument_Feature) error {
for _, tag := range feature.GetTags() {
func (s *Suite) runFeature(feature *msgs.Feature) error {
for _, tag := range feature.Tags {
if contains(s.options.ignoreTags, tag.Name) {
s.t.Logf("the feature (%s) is ignored ", feature.GetName())
s.t.Logf("the feature (%s) is ignored ", feature.Name)
return nil
}
}

hasErrors := false

s.t.Run(fmt.Sprintf("%s %s", strings.TrimSpace(feature.Keyword), feature.Name), func(t *testing.T) {
var bkgSteps *msgs.GherkinDocument_Feature_Background
var bkgSteps *msgs.Background

for _, child := range feature.Children {
if child.GetBackground() != nil {
bkgSteps = child.GetBackground()
if child.Background != nil {
bkgSteps = child.Background
}

scenario := child.GetScenario()
scenario := child.Scenario
if scenario == nil {
continue
}

if s.skipScenario(append(feature.GetTags(), scenario.GetTags()...)) {
if s.skipScenario(append(feature.Tags, scenario.Tags...)) {
t.Log(fmt.Sprintf("Skipping scenario %s", scenario.Name))
continue
}
Expand All @@ -389,17 +389,18 @@ func (s *Suite) runFeature(feature *msgs.GherkinDocument_Feature) error {
}

func (s *Suite) getOutlineStep(
steps []*msgs.GherkinDocument_Feature_Step,
examples []*msgs.GherkinDocument_Feature_Scenario_Examples) []*msgs.GherkinDocument_Feature_Step {
stepsList := make([][]*msgs.GherkinDocument_Feature_Step, len(steps))
steps []*msgs.Step,
examples []*msgs.Examples,
) []*msgs.Step {
stepsList := make([][]*msgs.Step, len(steps))

for i, outlineStep := range steps {
for _, example := range examples {
stepsList[i] = append(stepsList[i], s.stepsFromExamples(outlineStep, example)...)
}
}

var newSteps []*msgs.GherkinDocument_Feature_Step
var newSteps []*msgs.Step

if len(stepsList) == 0 {
return newSteps
Expand All @@ -417,21 +418,25 @@ func (s *Suite) getOutlineStep(
}

func (s *Suite) stepsFromExamples(
sourceStep *msgs.GherkinDocument_Feature_Step,
example *msgs.GherkinDocument_Feature_Scenario_Examples) []*msgs.GherkinDocument_Feature_Step {
steps := []*msgs.GherkinDocument_Feature_Step{}
sourceStep *msgs.Step,
example *msgs.Examples,
) []*msgs.Step {
steps := []*msgs.Step{}

placeholders := example.GetTableHeader().GetCells()
placeholders := []*msgs.TableCell{}
if example.TableHeader != nil {
placeholders = example.TableHeader.Cells
}
placeholdersValues := []string{}

for _, placeholder := range placeholders {
ph := "<" + placeholder.GetValue() + ">"
ph := "<" + placeholder.Value + ">"
placeholdersValues = append(placeholdersValues, ph)
}

text := sourceStep.GetText()
text := sourceStep.Text

for _, row := range example.GetTableBody() {
for _, row := range example.TableBody {
// iterate over the cells and update the text
stepText, expr := s.stepFromExample(text, row, placeholdersValues)

Expand All @@ -445,11 +450,10 @@ func (s *Suite) stepsFromExamples(
s.AddStep(expr, def.f)

// clone a step
step := &msgs.GherkinDocument_Feature_Step{
step := &msgs.Step{
Location: sourceStep.Location,
Keyword: sourceStep.Keyword,
Text: stepText,
Argument: sourceStep.Argument,
}

steps = append(steps, step)
Expand All @@ -460,7 +464,8 @@ func (s *Suite) stepsFromExamples(

func (s *Suite) stepFromExample(
stepName string,
row *msgs.GherkinDocument_Feature_TableRow, placeholders []string) (string, string) {
row *msgs.TableRow, placeholders []string,
) (string, string) {
expr := stepName

for i, ph := range placeholders {
Expand Down Expand Up @@ -496,8 +501,9 @@ func (s *Suite) callAfterSteps(ctx Context) {
}
}

func (s *Suite) runScenario(ctx Context, scenario *msgs.GherkinDocument_Feature_Scenario,
bkg *msgs.GherkinDocument_Feature_Background, t *testing.T) {
func (s *Suite) runScenario(ctx Context, scenario *msgs.Scenario,
bkg *msgs.Background, t *testing.T,
) {
t.Run(fmt.Sprintf("%s %s", strings.TrimSpace(scenario.Keyword), scenario.Name), func(t *testing.T) {
// NOTE consider passing t as argument to scenario hooks
ctx.Set(TestingTKey{}, t)
Expand All @@ -511,9 +517,9 @@ func (s *Suite) runScenario(ctx Context, scenario *msgs.GherkinDocument_Feature_
s.runSteps(ctx, t, steps)
}
steps := scenario.Steps
if examples := scenario.GetExamples(); len(examples) > 0 {
if examples := scenario.Examples; len(examples) > 0 {
c := ctx.Clone()
steps = s.getOutlineStep(scenario.GetSteps(), examples)
steps = s.getOutlineStep(scenario.Steps, examples)
s.runSteps(c, t, steps)
} else {
c := ctx.Clone()
Expand All @@ -522,13 +528,13 @@ func (s *Suite) runScenario(ctx Context, scenario *msgs.GherkinDocument_Feature_
})
}

func (s *Suite) runSteps(ctx Context, t *testing.T, steps []*msgs.GherkinDocument_Feature_Step) {
func (s *Suite) runSteps(ctx Context, t *testing.T, steps []*msgs.Step) {
for _, step := range steps {
s.runStep(ctx, t, step)
}
}

func (s *Suite) runStep(ctx Context, t *testing.T, step *msgs.GherkinDocument_Feature_Step) {
func (s *Suite) runStep(ctx Context, t *testing.T, step *msgs.Step) {
defer func() {
if r := recover(); r != nil {
t.Error(r)
Expand All @@ -541,8 +547,8 @@ func (s *Suite) runStep(ctx Context, t *testing.T, step *msgs.GherkinDocument_Fe
}

params := def.expr.FindSubmatch([]byte(step.Text))[1:]
if argument, ok := step.Argument.(*msgs.GherkinDocument_Feature_Step_DocString_); ok {
params = append(params, []byte(argument.DocString.Content))
if step.DocString != nil {
params = append(params, []byte(step.DocString.Content))
}

t.Run(fmt.Sprintf("%s %s", strings.TrimSpace(step.Keyword), step.Text), func(t *testing.T) {
Expand Down Expand Up @@ -636,7 +642,7 @@ func (s *Suite) findStepDef(text string) (stepDef, error) {
return sd, nil
}

func (s *Suite) skipScenario(scenarioTags []*msgs.GherkinDocument_Feature_Tag) bool {
func (s *Suite) skipScenario(scenarioTags []*msgs.Tag) bool {
for _, tag := range scenarioTags {
if contains(s.options.ignoreTags, tag.Name) {
return true
Expand All @@ -656,7 +662,7 @@ func (s *Suite) skipScenario(scenarioTags []*msgs.GherkinDocument_Feature_Tag) b
return true
}

func (s *Suite) getBackgroundSteps(bkg *msgs.GherkinDocument_Feature_Background) []*msgs.GherkinDocument_Feature_Step {
func (s *Suite) getBackgroundSteps(bkg *msgs.Background) []*msgs.Step {
return bkg.Steps
}

Expand Down
11 changes: 6 additions & 5 deletions gobdd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"regexp"
"testing"

msgs "github.com/cucumber/messages-go/v12"
msgs "github.com/cucumber/messages/go/v24"
"github.com/go-bdd/assert"
"github.com/stretchr/testify/require"
)
Expand Down Expand Up @@ -94,8 +94,8 @@ func TestScenarioOutlineExecutesAllTests(t *testing.T) {

func TestStepFromExample(t *testing.T) {
s := NewSuite(t)
st, expr := s.stepFromExample("I add <d1> and <d2>", &msgs.GherkinDocument_Feature_TableRow{
Cells: []*msgs.GherkinDocument_Feature_TableRow_TableCell{
st, expr := s.stepFromExample("I add <d1> and <d2>", &msgs.TableRow{
Cells: []*msgs.TableCell{
{Value: "1"},
{Value: "2"},
},
Expand Down Expand Up @@ -178,14 +178,14 @@ func TestWithAfterStep(t *testing.T) {
// feature should be *msgs.GherkinDocument_Feature
feature, err := ctx.Get(FeatureKey{})
require.NoError(t, err)
if _, ok := feature.(*msgs.GherkinDocument_Feature); !ok {
if _, ok := feature.(*msgs.Feature); !ok {
t.Errorf("expected feature but got %T", feature)
}

// scenario should be *msgs.GherkinDocument_Feature_Scenario
scenario, err := ctx.Get(ScenarioKey{})
require.NoError(t, err)
if _, ok := scenario.(*msgs.GherkinDocument_Feature_Scenario); !ok {
if _, ok := scenario.(*msgs.Scenario); !ok {
t.Errorf("expected scenario but got %T", scenario)
}
}))
Expand Down Expand Up @@ -352,6 +352,7 @@ func (m *mockTester) Log(...interface{}) {

func (m *mockTester) Logf(string, ...interface{}) {
}

func (m *mockTester) Fatal(...interface{}) {
m.fatalCalled++
}
Expand Down

0 comments on commit 39e9e76

Please sign in to comment.