Skip to content

Commit

Permalink
chore: upgrading the gherkin cucumber version to v28
Browse files Browse the repository at this point in the history
  • Loading branch information
svandecappelle committed Apr 23, 2024
1 parent 9d41292 commit 3ebbd5f
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 62 deletions.
9 changes: 6 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@ module github.com/go-bdd/gobdd
go 1.16

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{}

Check failure on line 430 in gobdd.go

View workflow job for this annotation

GitHub Actions / Lint

assignments should only be cuddled with other assignments (wsl)

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 3ebbd5f

Please sign in to comment.