From 8bfac9c57db94efebd6eb16c139f3b2e82b2e27e Mon Sep 17 00:00:00 2001 From: achitu Date: Tue, 4 Oct 2022 11:24:33 +0100 Subject: [PATCH 1/8] feat(*): create keyword functions --- formatters/fmt.go | 2 ++ internal/models/stepdef.go | 9 +++++++++ test_context.go | 29 +++++++++++++++++++++++++++++ 3 files changed, 40 insertions(+) diff --git a/formatters/fmt.go b/formatters/fmt.go index 2e112806..2dc52d35 100644 --- a/formatters/fmt.go +++ b/formatters/fmt.go @@ -4,6 +4,7 @@ import ( "io" "regexp" + "github.com/cucumber/godog/internal/models" "github.com/cucumber/messages-go/v16" ) @@ -88,4 +89,5 @@ type FormatterFunc func(string, io.Writer) Formatter type StepDefinition struct { Expr *regexp.Regexp Handler interface{} + Keyword models.Keyword } diff --git a/internal/models/stepdef.go b/internal/models/stepdef.go index 24ea706e..ea29f2e2 100644 --- a/internal/models/stepdef.go +++ b/internal/models/stepdef.go @@ -33,6 +33,15 @@ type StepDefinition struct { Undefined []string } +type Keyword int64 + +const ( + Given Keyword = iota + When + Then + None +) + var typeOfContext = reflect.TypeOf((*context.Context)(nil)).Elem() // Run a step with the matched arguments using reflect diff --git a/test_context.go b/test_context.go index fbbe981f..96bbc0b0 100644 --- a/test_context.go +++ b/test_context.go @@ -251,6 +251,34 @@ func (ctx *ScenarioContext) AfterStep(fn func(st *Step, err error)) { // ErrUndefined error will be returned when // running steps. func (ctx *ScenarioContext) Step(expr, stepFunc interface{}) { + ctx.stepWithKeyword(expr, stepFunc, models.None) +} + +// Given functions identically to Step, but the *StepDefinition +// will only be matched if the step starts with "Given". "And" +// and "But" keywords copy the keyword of the last step for the +// purpose of matching. +func (ctx *ScenarioContext) Given(expr, stepFunc interface{}) { + ctx.stepWithKeyword(expr, stepFunc, models.Given) +} + +// When functions identically to Step, but the *StepDefinition +// will only be matched if the step starts with "When". "And" +// and "But" keywords copy the keyword of the last step for the +// purpose of matching. +func (ctx *ScenarioContext) When(expr, stepFunc interface{}) { + ctx.stepWithKeyword(expr, stepFunc, models.When) +} + +// Then functions identically to Step, but the *StepDefinition +// will only be matched if the step starts with "Then". "And" +// and "But" keywords copy the keyword of the last step for the +// purpose of matching. +func (ctx *ScenarioContext) Then(expr, stepFunc interface{}) { + ctx.stepWithKeyword(expr, stepFunc, models.Then) +} + +func (ctx *ScenarioContext) stepWithKeyword(expr interface{}, stepFunc interface{}, keyword models.Keyword) { var regex *regexp.Regexp switch t := expr.(type) { @@ -278,6 +306,7 @@ func (ctx *ScenarioContext) Step(expr, stepFunc interface{}) { StepDefinition: formatters.StepDefinition{ Handler: stepFunc, Expr: regex, + Keyword: keyword, }, HandlerValue: v, } From 1ce07db50db9e50a50443b8035ce57c6dde87b49 Mon Sep 17 00:00:00 2001 From: otrava7 Date: Tue, 4 Oct 2022 17:11:35 +0100 Subject: [PATCH 2/8] chore(*): update messages and gherkin, relocate Keyword chore(*): update messages and gherkin, relocate Keyword chore(*): update messages and gherkin, relocate Keyword --- _examples/go.mod | 6 ++--- _examples/go.sum | 16 ++++++------- formatters/fmt.go | 14 ++++++++--- go.mod | 9 +++---- go.sum | 16 ++++++------- internal/formatters/fmt.go | 2 +- internal/formatters/fmt_base.go | 2 +- internal/formatters/fmt_cucumber.go | 2 +- internal/formatters/fmt_events.go | 2 +- internal/formatters/fmt_multi.go | 2 +- internal/formatters/fmt_pretty.go | 2 +- internal/formatters/fmt_progress.go | 2 +- internal/formatters/undefined_snippets_gen.go | 2 +- internal/models/feature.go | 2 +- internal/models/stepdef.go | 12 +--------- internal/models/stepdef_test.go | 2 +- internal/parser/parser.go | 5 ++-- internal/storage/storage.go | 2 +- internal/storage/storage_test.go | 2 +- internal/tags/tag_filter.go | 2 +- internal/tags/tag_filter_test.go | 2 +- internal/testutils/utils.go | 4 ++-- run.go | 2 +- run_progress_test.go | 5 ++-- run_test.go | 4 ++-- suite.go | 2 +- suite_context_test.go | 4 ++-- test_context.go | 24 +++++++++---------- 28 files changed, 73 insertions(+), 78 deletions(-) diff --git a/_examples/go.mod b/_examples/go.mod index 618e7f6e..6c768147 100644 --- a/_examples/go.mod +++ b/_examples/go.mod @@ -9,12 +9,12 @@ require ( github.com/cucumber/godog v0.0.0-00010101000000-000000000000 github.com/go-sql-driver/mysql v1.6.0 github.com/spf13/pflag v1.0.5 - github.com/stretchr/testify v1.7.1 + github.com/stretchr/testify v1.7.4 ) require ( - github.com/cucumber/gherkin-go/v19 v19.0.3 // indirect - github.com/cucumber/messages-go/v16 v16.0.1 // indirect + github.com/cucumber/common/gherkin/go/v24 v24.0.0 // indirect + github.com/cucumber/common/messages/go/v19 v19.1.2 // indirect github.com/davecgh/go-spew v1.1.1 // indirect github.com/gofrs/uuid v4.2.0+incompatible // indirect github.com/hashicorp/go-immutable-radix v1.3.1 // indirect diff --git a/_examples/go.sum b/_examples/go.sum index 9339f559..8b5c8df6 100644 --- a/_examples/go.sum +++ b/_examples/go.sum @@ -2,17 +2,16 @@ github.com/DATA-DOG/go-txdb v0.1.4 h1:6On4TAD6V33/QlE6Y5l0A4KngRzYrUQ7bgPsDrFrtQ github.com/DATA-DOG/go-txdb v0.1.4/go.mod h1:DhAhxMXZpUJVGnT+p9IbzJoRKvlArO2pkHjnGX7o0n0= github.com/cpuguy83/go-md2man/v2 v2.0.1/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= -github.com/cucumber/gherkin-go/v19 v19.0.3 h1:mMSKu1077ffLbTJULUfM5HPokgeBcIGboyeNUof1MdE= -github.com/cucumber/gherkin-go/v19 v19.0.3/go.mod h1:jY/NP6jUtRSArQQJ5h1FXOUgk5fZK24qtE7vKi776Vw= -github.com/cucumber/messages-go/v16 v16.0.0/go.mod h1:EJcyR5Mm5ZuDsKJnT2N9KRnBK30BGjtYotDKpwQ0v6g= -github.com/cucumber/messages-go/v16 v16.0.1 h1:fvkpwsLgnIm0qugftrw2YwNlio+ABe2Iu94Ap8GMYIY= -github.com/cucumber/messages-go/v16 v16.0.1/go.mod h1:EJcyR5Mm5ZuDsKJnT2N9KRnBK30BGjtYotDKpwQ0v6g= +github.com/cucumber/common/gherkin/go/v24 v24.0.0 h1:ppb74NSYmsySEbck0hpvnINHkn9PQPwyG+kK2bm3xLg= +github.com/cucumber/common/gherkin/go/v24 v24.0.0/go.mod h1:qtxmXJsRMJmRh+ZX49Ez8cYvtK1Il9E+B0YdYcPsDPg= +github.com/cucumber/common/messages/go/v19 v19.0.0/go.mod h1:O6WWH/SrhgAh1tKsKoYufycU9iTso4FSYH2xur+zruY= +github.com/cucumber/common/messages/go/v19 v19.1.2 h1:8/ZkW9rj3KQo/regmI8kcy48tk57m427Olb7Y0lXcN4= +github.com/cucumber/common/messages/go/v19 v19.1.2/go.mod h1:0KLDvMVmmkEZcWUSKxFHSUSLS1gjujBbPN0p41IwwJ4= 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-sql-driver/mysql v1.6.0 h1:BCTh4TKNUYmOmMUcQ3IipzF5prigylS7XXjEkfCHuOE= github.com/go-sql-driver/mysql v1.6.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg= -github.com/gofrs/uuid v4.0.0+incompatible/go.mod h1:b2aQJv3Z4Fp6yNu3cdSllBxTCLRxnplIgP/c0N/04lM= github.com/gofrs/uuid v4.2.0+incompatible h1:yyYWMnhkhrKwwr8gAOcOCYxOOscHgDS9yZgBrnJfGa0= github.com/gofrs/uuid v4.2.0+incompatible/go.mod h1:b2aQJv3Z4Fp6yNu3cdSllBxTCLRxnplIgP/c0N/04lM= github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1 h1:EGx4pi6eqNxGaHF6qqu48+N2wcFQ5qg5FXgOdqsJ5d8= @@ -54,9 +53,10 @@ github.com/spf13/cobra v1.4.0/go.mod h1:Wo4iy3BUC+X2Fybo0PDqwJIv3dNRiZLHQymsfxlB github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA= github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= -github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= -github.com/stretchr/testify v1.7.1 h1:5TQK59W5E3v0r2duFAb7P95B6hEeOyEnHRa8MjYSMTY= +github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/stretchr/testify v1.7.4 h1:wZRexSlwd7ZXfKINDLsO4r7WBt3gTKONc6K/VesHvHM= +github.com/stretchr/testify v1.7.4/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= diff --git a/formatters/fmt.go b/formatters/fmt.go index 2dc52d35..ee0782b3 100644 --- a/formatters/fmt.go +++ b/formatters/fmt.go @@ -4,8 +4,7 @@ import ( "io" "regexp" - "github.com/cucumber/godog/internal/models" - "github.com/cucumber/messages-go/v16" + "github.com/cucumber/common/messages/go/v19" ) type registeredFormatter struct { @@ -89,5 +88,14 @@ type FormatterFunc func(string, io.Writer) Formatter type StepDefinition struct { Expr *regexp.Regexp Handler interface{} - Keyword models.Keyword + Keyword Keyword } + +type Keyword int64 + +const ( + Given Keyword = iota + When + Then + None +) diff --git a/go.mod b/go.mod index 235aea2d..97314475 100644 --- a/go.mod +++ b/go.mod @@ -3,20 +3,17 @@ module github.com/cucumber/godog go 1.16 require ( - github.com/cucumber/gherkin-go/v19 v19.0.3 - github.com/cucumber/messages-go/v16 v16.0.1 + github.com/cucumber/common/gherkin/go/v24 v24.0.0 + github.com/cucumber/common/messages/go/v19 v19.1.2 github.com/hashicorp/go-memdb v1.3.2 github.com/smartystreets/goconvey v1.6.4 github.com/spf13/cobra v1.4.0 github.com/spf13/pflag v1.0.5 - github.com/stretchr/testify v1.7.1 + github.com/stretchr/testify v1.7.4 ) require ( - github.com/davecgh/go-spew v1.1.1 // indirect - github.com/gofrs/uuid v4.2.0+incompatible // indirect github.com/hashicorp/go-immutable-radix v1.3.1 // indirect github.com/hashicorp/go-uuid v1.0.2 // indirect gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect - gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/go.sum b/go.sum index 1e2e0059..0ca29649 100644 --- a/go.sum +++ b/go.sum @@ -1,13 +1,12 @@ github.com/cpuguy83/go-md2man/v2 v2.0.1/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= -github.com/cucumber/gherkin-go/v19 v19.0.3 h1:mMSKu1077ffLbTJULUfM5HPokgeBcIGboyeNUof1MdE= -github.com/cucumber/gherkin-go/v19 v19.0.3/go.mod h1:jY/NP6jUtRSArQQJ5h1FXOUgk5fZK24qtE7vKi776Vw= -github.com/cucumber/messages-go/v16 v16.0.0/go.mod h1:EJcyR5Mm5ZuDsKJnT2N9KRnBK30BGjtYotDKpwQ0v6g= -github.com/cucumber/messages-go/v16 v16.0.1 h1:fvkpwsLgnIm0qugftrw2YwNlio+ABe2Iu94Ap8GMYIY= -github.com/cucumber/messages-go/v16 v16.0.1/go.mod h1:EJcyR5Mm5ZuDsKJnT2N9KRnBK30BGjtYotDKpwQ0v6g= +github.com/cucumber/common/gherkin/go/v24 v24.0.0 h1:ppb74NSYmsySEbck0hpvnINHkn9PQPwyG+kK2bm3xLg= +github.com/cucumber/common/gherkin/go/v24 v24.0.0/go.mod h1:qtxmXJsRMJmRh+ZX49Ez8cYvtK1Il9E+B0YdYcPsDPg= +github.com/cucumber/common/messages/go/v19 v19.0.0/go.mod h1:O6WWH/SrhgAh1tKsKoYufycU9iTso4FSYH2xur+zruY= +github.com/cucumber/common/messages/go/v19 v19.1.2 h1:8/ZkW9rj3KQo/regmI8kcy48tk57m427Olb7Y0lXcN4= +github.com/cucumber/common/messages/go/v19 v19.1.2/go.mod h1:0KLDvMVmmkEZcWUSKxFHSUSLS1gjujBbPN0p41IwwJ4= 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/gofrs/uuid v4.0.0+incompatible/go.mod h1:b2aQJv3Z4Fp6yNu3cdSllBxTCLRxnplIgP/c0N/04lM= github.com/gofrs/uuid v4.2.0+incompatible h1:yyYWMnhkhrKwwr8gAOcOCYxOOscHgDS9yZgBrnJfGa0= github.com/gofrs/uuid v4.2.0+incompatible/go.mod h1:b2aQJv3Z4Fp6yNu3cdSllBxTCLRxnplIgP/c0N/04lM= github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1 h1:EGx4pi6eqNxGaHF6qqu48+N2wcFQ5qg5FXgOdqsJ5d8= @@ -44,9 +43,10 @@ github.com/spf13/cobra v1.4.0/go.mod h1:Wo4iy3BUC+X2Fybo0PDqwJIv3dNRiZLHQymsfxlB github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA= github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= -github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= -github.com/stretchr/testify v1.7.1 h1:5TQK59W5E3v0r2duFAb7P95B6hEeOyEnHRa8MjYSMTY= +github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/stretchr/testify v1.7.4 h1:wZRexSlwd7ZXfKINDLsO4r7WBt3gTKONc6K/VesHvHM= +github.com/stretchr/testify v1.7.4/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= diff --git a/internal/formatters/fmt.go b/internal/formatters/fmt.go index df96aaff..f9a89792 100644 --- a/internal/formatters/fmt.go +++ b/internal/formatters/fmt.go @@ -9,7 +9,7 @@ import ( "strconv" "strings" - "github.com/cucumber/messages-go/v16" + "github.com/cucumber/common/messages/go/v19" "github.com/cucumber/godog/colors" "github.com/cucumber/godog/internal/models" diff --git a/internal/formatters/fmt_base.go b/internal/formatters/fmt_base.go index c95a97f9..f3e218d0 100644 --- a/internal/formatters/fmt_base.go +++ b/internal/formatters/fmt_base.go @@ -11,7 +11,7 @@ import ( "sync" "unicode" - "github.com/cucumber/messages-go/v16" + "github.com/cucumber/common/messages/go/v19" "github.com/cucumber/godog/colors" "github.com/cucumber/godog/formatters" diff --git a/internal/formatters/fmt_cucumber.go b/internal/formatters/fmt_cucumber.go index fee855a7..eedc0484 100644 --- a/internal/formatters/fmt_cucumber.go +++ b/internal/formatters/fmt_cucumber.go @@ -18,7 +18,7 @@ import ( "sort" "strings" - "github.com/cucumber/messages-go/v16" + "github.com/cucumber/common/messages/go/v19" "github.com/cucumber/godog/formatters" "github.com/cucumber/godog/internal/models" diff --git a/internal/formatters/fmt_events.go b/internal/formatters/fmt_events.go index 879a3c27..28168779 100644 --- a/internal/formatters/fmt_events.go +++ b/internal/formatters/fmt_events.go @@ -5,7 +5,7 @@ import ( "fmt" "io" - "github.com/cucumber/messages-go/v16" + "github.com/cucumber/common/messages/go/v19" "github.com/cucumber/godog/formatters" "github.com/cucumber/godog/internal/utils" diff --git a/internal/formatters/fmt_multi.go b/internal/formatters/fmt_multi.go index aa206ff3..2f9f2379 100644 --- a/internal/formatters/fmt_multi.go +++ b/internal/formatters/fmt_multi.go @@ -3,9 +3,9 @@ package formatters import ( "io" + "github.com/cucumber/common/messages/go/v19" "github.com/cucumber/godog/formatters" "github.com/cucumber/godog/internal/storage" - "github.com/cucumber/messages-go/v16" ) // MultiFormatter passes test progress to multiple formatters. diff --git a/internal/formatters/fmt_pretty.go b/internal/formatters/fmt_pretty.go index 070627a3..af09823e 100644 --- a/internal/formatters/fmt_pretty.go +++ b/internal/formatters/fmt_pretty.go @@ -8,7 +8,7 @@ import ( "strings" "unicode/utf8" - "github.com/cucumber/messages-go/v16" + "github.com/cucumber/common/messages/go/v19" "github.com/cucumber/godog/colors" "github.com/cucumber/godog/formatters" diff --git a/internal/formatters/fmt_progress.go b/internal/formatters/fmt_progress.go index 86dbdf6a..3623837b 100644 --- a/internal/formatters/fmt_progress.go +++ b/internal/formatters/fmt_progress.go @@ -7,7 +7,7 @@ import ( "sort" "strings" - "github.com/cucumber/messages-go/v16" + "github.com/cucumber/common/messages/go/v19" "github.com/cucumber/godog/formatters" ) diff --git a/internal/formatters/undefined_snippets_gen.go b/internal/formatters/undefined_snippets_gen.go index 5b5721ee..52184f83 100644 --- a/internal/formatters/undefined_snippets_gen.go +++ b/internal/formatters/undefined_snippets_gen.go @@ -7,7 +7,7 @@ import ( "strings" "text/template" - "github.com/cucumber/messages-go/v16" + "github.com/cucumber/common/messages/go/v19" ) // some snippet formatting regexps diff --git a/internal/models/feature.go b/internal/models/feature.go index 4edd65da..cbc1df0e 100644 --- a/internal/models/feature.go +++ b/internal/models/feature.go @@ -1,7 +1,7 @@ package models import ( - "github.com/cucumber/messages-go/v16" + "github.com/cucumber/common/messages/go/v19" ) // Feature is an internal object to group together diff --git a/internal/models/stepdef.go b/internal/models/stepdef.go index ea29f2e2..ce2a9da5 100644 --- a/internal/models/stepdef.go +++ b/internal/models/stepdef.go @@ -7,8 +7,7 @@ import ( "reflect" "strconv" - "github.com/cucumber/messages-go/v16" - + "github.com/cucumber/common/messages/go/v19" "github.com/cucumber/godog/formatters" ) @@ -33,15 +32,6 @@ type StepDefinition struct { Undefined []string } -type Keyword int64 - -const ( - Given Keyword = iota - When - Then - None -) - var typeOfContext = reflect.TypeOf((*context.Context)(nil)).Elem() // Run a step with the matched arguments using reflect diff --git a/internal/models/stepdef_test.go b/internal/models/stepdef_test.go index db2eee7b..ccaa5b11 100644 --- a/internal/models/stepdef_test.go +++ b/internal/models/stepdef_test.go @@ -8,7 +8,7 @@ import ( "strings" "testing" - "github.com/cucumber/messages-go/v16" + "github.com/cucumber/common/messages/go/v19" "github.com/stretchr/testify/assert" "github.com/cucumber/godog" diff --git a/internal/parser/parser.go b/internal/parser/parser.go index e5d945d2..0b7ba4cc 100644 --- a/internal/parser/parser.go +++ b/internal/parser/parser.go @@ -10,9 +10,8 @@ import ( "strconv" "strings" - "github.com/cucumber/gherkin-go/v19" - "github.com/cucumber/messages-go/v16" - + gherkin "github.com/cucumber/common/gherkin/go/v24" + "github.com/cucumber/common/messages/go/v19" "github.com/cucumber/godog/internal/flags" "github.com/cucumber/godog/internal/models" "github.com/cucumber/godog/internal/tags" diff --git a/internal/storage/storage.go b/internal/storage/storage.go index 80358dae..eb0f27f6 100644 --- a/internal/storage/storage.go +++ b/internal/storage/storage.go @@ -4,7 +4,7 @@ import ( "fmt" "sync" - "github.com/cucumber/messages-go/v16" + "github.com/cucumber/common/messages/go/v19" "github.com/hashicorp/go-memdb" "github.com/cucumber/godog/internal/models" diff --git a/internal/storage/storage_test.go b/internal/storage/storage_test.go index dcc9107a..f022ff01 100644 --- a/internal/storage/storage_test.go +++ b/internal/storage/storage_test.go @@ -4,7 +4,7 @@ import ( "testing" "time" - "github.com/cucumber/messages-go/v16" + "github.com/cucumber/common/messages/go/v19" "github.com/stretchr/testify/assert" "github.com/cucumber/godog/internal/models" diff --git a/internal/tags/tag_filter.go b/internal/tags/tag_filter.go index 06801b21..79cd0723 100644 --- a/internal/tags/tag_filter.go +++ b/internal/tags/tag_filter.go @@ -3,7 +3,7 @@ package tags import ( "strings" - "github.com/cucumber/messages-go/v16" + "github.com/cucumber/common/messages/go/v19" ) // ApplyTagFilter will apply a filter string on the diff --git a/internal/tags/tag_filter_test.go b/internal/tags/tag_filter_test.go index 47430b65..9bc51984 100644 --- a/internal/tags/tag_filter_test.go +++ b/internal/tags/tag_filter_test.go @@ -3,7 +3,7 @@ package tags_test import ( "testing" - "github.com/cucumber/messages-go/v16" + "github.com/cucumber/common/messages/go/v19" "github.com/stretchr/testify/assert" "github.com/cucumber/godog/internal/tags" diff --git a/internal/testutils/utils.go b/internal/testutils/utils.go index 4c1c8afe..2539b65b 100644 --- a/internal/testutils/utils.go +++ b/internal/testutils/utils.go @@ -4,8 +4,8 @@ import ( "strings" "testing" - "github.com/cucumber/gherkin-go/v19" - "github.com/cucumber/messages-go/v16" + "github.com/cucumber/common/gherkin/go/v24" + "github.com/cucumber/common/messages/go/v19" "github.com/stretchr/testify/require" "github.com/cucumber/godog/internal/models" diff --git a/run.go b/run.go index c49607af..ed325a5b 100644 --- a/run.go +++ b/run.go @@ -15,7 +15,7 @@ import ( "sync" "testing" - "github.com/cucumber/messages-go/v16" + "github.com/cucumber/common/messages/go/v19" "github.com/cucumber/godog/colors" "github.com/cucumber/godog/formatters" diff --git a/run_progress_test.go b/run_progress_test.go index 95854204..af3f082f 100644 --- a/run_progress_test.go +++ b/run_progress_test.go @@ -2,11 +2,12 @@ package godog import ( "bytes" - "github.com/cucumber/messages-go/v16" "strings" "testing" - "github.com/cucumber/gherkin-go/v19" + "github.com/cucumber/common/messages/go/v19" + + "github.com/cucumber/common/gherkin/go/v24" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" diff --git a/run_test.go b/run_test.go index 9c07a6dd..ba56454f 100644 --- a/run_test.go +++ b/run_test.go @@ -13,8 +13,8 @@ import ( "strings" "testing" - "github.com/cucumber/gherkin-go/v19" - "github.com/cucumber/messages-go/v16" + "github.com/cucumber/common/gherkin/go/v24" + "github.com/cucumber/common/messages/go/v19" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" diff --git a/suite.go b/suite.go index 05860526..0f31c128 100644 --- a/suite.go +++ b/suite.go @@ -7,7 +7,7 @@ import ( "strings" "testing" - "github.com/cucumber/messages-go/v16" + "github.com/cucumber/common/messages/go/v19" "github.com/cucumber/godog/formatters" "github.com/cucumber/godog/internal/models" diff --git a/suite_context_test.go b/suite_context_test.go index 7a2fc7fa..8d72d4aa 100644 --- a/suite_context_test.go +++ b/suite_context_test.go @@ -12,8 +12,8 @@ import ( "strconv" "strings" - "github.com/cucumber/gherkin-go/v19" - "github.com/cucumber/messages-go/v16" + gherkin "github.com/cucumber/common/gherkin/go/v24" + "github.com/cucumber/common/messages/go/v19" "github.com/stretchr/testify/assert" "github.com/cucumber/godog/colors" diff --git a/test_context.go b/test_context.go index 96bbc0b0..d1692092 100644 --- a/test_context.go +++ b/test_context.go @@ -6,11 +6,11 @@ import ( "reflect" "regexp" + "github.com/cucumber/common/messages/go/v19" "github.com/cucumber/godog/formatters" "github.com/cucumber/godog/internal/builder" "github.com/cucumber/godog/internal/flags" "github.com/cucumber/godog/internal/models" - "github.com/cucumber/messages-go/v16" ) // GherkinDocument represents gherkin document. @@ -26,12 +26,12 @@ type Step = messages.PickleStep // instead of returning an error in step func // it is possible to return combined steps: // -// func multistep(name string) godog.Steps { -// return godog.Steps{ -// fmt.Sprintf(`an user named "%s"`, name), -// fmt.Sprintf(`user "%s" is authenticated`, name), -// } -// } +// func multistep(name string) godog.Steps { +// return godog.Steps{ +// fmt.Sprintf(`an user named "%s"`, name), +// fmt.Sprintf(`user "%s" is authenticated`, name), +// } +// } // // These steps will be matched and executed in // sequential order. The first one which fails @@ -251,7 +251,7 @@ func (ctx *ScenarioContext) AfterStep(fn func(st *Step, err error)) { // ErrUndefined error will be returned when // running steps. func (ctx *ScenarioContext) Step(expr, stepFunc interface{}) { - ctx.stepWithKeyword(expr, stepFunc, models.None) + ctx.stepWithKeyword(expr, stepFunc, formatters.None) } // Given functions identically to Step, but the *StepDefinition @@ -259,7 +259,7 @@ func (ctx *ScenarioContext) Step(expr, stepFunc interface{}) { // and "But" keywords copy the keyword of the last step for the // purpose of matching. func (ctx *ScenarioContext) Given(expr, stepFunc interface{}) { - ctx.stepWithKeyword(expr, stepFunc, models.Given) + ctx.stepWithKeyword(expr, stepFunc, formatters.Given) } // When functions identically to Step, but the *StepDefinition @@ -267,7 +267,7 @@ func (ctx *ScenarioContext) Given(expr, stepFunc interface{}) { // and "But" keywords copy the keyword of the last step for the // purpose of matching. func (ctx *ScenarioContext) When(expr, stepFunc interface{}) { - ctx.stepWithKeyword(expr, stepFunc, models.When) + ctx.stepWithKeyword(expr, stepFunc, formatters.When) } // Then functions identically to Step, but the *StepDefinition @@ -275,10 +275,10 @@ func (ctx *ScenarioContext) When(expr, stepFunc interface{}) { // and "But" keywords copy the keyword of the last step for the // purpose of matching. func (ctx *ScenarioContext) Then(expr, stepFunc interface{}) { - ctx.stepWithKeyword(expr, stepFunc, models.Then) + ctx.stepWithKeyword(expr, stepFunc, formatters.Then) } -func (ctx *ScenarioContext) stepWithKeyword(expr interface{}, stepFunc interface{}, keyword models.Keyword) { +func (ctx *ScenarioContext) stepWithKeyword(expr interface{}, stepFunc interface{}, keyword formatters.Keyword) { var regex *regexp.Regexp switch t := expr.(type) { From f906c9302cb009a9f98a24682536e9dfac842ca3 Mon Sep 17 00:00:00 2001 From: otrava7 Date: Mon, 24 Oct 2022 20:21:41 +0100 Subject: [PATCH 3/8] feat(*): mandate keyword type when unambiguous keyword function is used --- features/events.feature | 6 ++--- features/formatter/pretty.feature | 43 ++++++++++++++++++++++++++++--- run_test.go | 12 ++++----- suite.go | 35 ++++++++++++++++++++----- suite_context_test.go | 9 +++++++ 5 files changed, 85 insertions(+), 20 deletions(-) diff --git a/features/events.feature b/features/events.feature index 8985914c..2b63767c 100644 --- a/features/events.feature +++ b/features/events.feature @@ -121,17 +121,17 @@ Feature: suite events Feature: scenario hook errors Scenario: failing before and after scenario # normal.feature:3 - Then adding step state to context # suite_context_test.go:0 -> InitializeScenario.func12 + Then adding step state to context # suite_context_test.go:0 -> InitializeScenario.func15 after scenario hook failed: failed in after scenario hook, step error: before scenario hook failed: failed in before scenario hook And passing step # suite_context_test.go:0 -> InitializeScenario.func2 Scenario: failing before scenario # normal.feature:7 - Then adding step state to context # suite_context_test.go:0 -> InitializeScenario.func12 + Then adding step state to context # suite_context_test.go:0 -> InitializeScenario.func15 before scenario hook failed: failed in before scenario hook And passing step # suite_context_test.go:0 -> InitializeScenario.func2 Scenario: failing after scenario # normal.feature:11 - Then adding step state to context # suite_context_test.go:0 -> InitializeScenario.func12 + Then adding step state to context # suite_context_test.go:0 -> InitializeScenario.func15 And passing step # suite_context_test.go:0 -> InitializeScenario.func2 after scenario hook failed: failed in after scenario hook diff --git a/features/formatter/pretty.feature b/features/formatter/pretty.feature index 86d10a89..333f63c5 100644 --- a/features/formatter/pretty.feature +++ b/features/formatter/pretty.feature @@ -332,11 +332,11 @@ Feature: pretty formatter Feature: inject long value Scenario: test scenario # features/inject.feature:3 - Given Ignore I save some value X under key Y # suite_context.go:0 -> SuiteContext.func7 + Given Ignore I save some value X under key Y # suite_context.go:0 -> SuiteContext.func10 And I allow variable injection # suite_context.go:0 -> *suiteContext - When Ignore I use value someverylonginjectionsoweacanbesureitsurpasstheinitiallongeststeplenghtanditwillhelptestsmethodsafety # suite_context.go:0 -> SuiteContext.func7 - Then Ignore Godog rendering should not break # suite_context.go:0 -> SuiteContext.func7 - And Ignore test # suite_context.go:0 -> SuiteContext.func7 + When Ignore I use value someverylonginjectionsoweacanbesureitsurpasstheinitiallongeststeplenghtanditwillhelptestsmethodsafety # suite_context.go:0 -> SuiteContext.func10 + Then Ignore Godog rendering should not break # suite_context.go:0 -> SuiteContext.func10 + And Ignore test # suite_context.go:0 -> SuiteContext.func10 | key | val | | 1 | 2 | | 3 | 4 | @@ -548,3 +548,38 @@ Feature: pretty formatter 2 steps (1 passed, 1 failed) 0s """ + + Scenario: Use 'given' keyword on a declared 'when' step + Given a feature "features/simple.feature" file: + """ + Feature: simple feature with a rule + simple feature description + Rule: simple rule + simple rule description + Example: simple scenario + simple scenario description + Given a when step + """ + When I run feature suite with formatter "pretty" + Then the rendered output will be as follows: + """ + Feature: simple feature with a rule + simple feature description + + Example: simple scenario # features/simple.feature:5 + Given a when step + + 1 scenarios (1 undefined) + 1 steps (1 undefined) + 0s + + You can implement step definitions for undefined steps with these snippets: + + func aWhenStep() error { + return godog.ErrPending + } + + func InitializeScenario(ctx *godog.ScenarioContext) { + ctx.Step(`^a when step$`, aWhenStep) + } + """ \ No newline at end of file diff --git a/run_test.go b/run_test.go index ba56454f..f5b5e214 100644 --- a/run_test.go +++ b/run_test.go @@ -518,11 +518,11 @@ func Test_AllFeaturesRun(t *testing.T) { ...................................................................... 140 ...................................................................... 210 ...................................................................... 280 -....................................................... 335 +.......................................................... 338 -88 scenarios (88 passed) -335 steps (335 passed) +89 scenarios (89 passed) +338 steps (338 passed) 0s ` @@ -545,11 +545,11 @@ func Test_AllFeaturesRunAsSubtests(t *testing.T) { ...................................................................... 140 ...................................................................... 210 ...................................................................... 280 -....................................................... 335 +.......................................................... 338 -88 scenarios (88 passed) -335 steps (335 passed) +89 scenarios (89 passed) +338 steps (338 passed) 0s ` diff --git a/suite.go b/suite.go index 0f31c128..1e58336d 100644 --- a/suite.go +++ b/suite.go @@ -65,7 +65,7 @@ type suite struct { } func (s *suite) matchStep(step *messages.PickleStep) *models.StepDefinition { - def := s.matchStepText(step.Text) + def := s.matchStepTextAndType(step.Text, step.Type) if def != nil && step.Argument != nil { def.Args = append(def.Args, step.Argument) } @@ -147,7 +147,7 @@ func (s *suite) runStep(ctx context.Context, pickle *Scenario, step *Step, prevS return ctx, err } - if ctx, undef, err := s.maybeUndefined(ctx, step.Text, step.Argument); err != nil { + if ctx, undef, err := s.maybeUndefined(ctx, step.Text, step.Argument, step.Type); err != nil { return ctx, err } else if len(undef) > 0 { if match != nil { @@ -155,6 +155,7 @@ func (s *suite) runStep(ctx context.Context, pickle *Scenario, step *Step, prevS StepDefinition: formatters.StepDefinition{ Expr: match.Expr, Handler: match.Handler, + Keyword: match.Keyword, }, Args: match.Args, HandlerValue: match.HandlerValue, @@ -297,8 +298,8 @@ func (s *suite) runAfterScenarioHooks(ctx context.Context, pickle *messages.Pick return ctx, err } -func (s *suite) maybeUndefined(ctx context.Context, text string, arg interface{}) (context.Context, []string, error) { - step := s.matchStepText(text) +func (s *suite) maybeUndefined(ctx context.Context, text string, arg interface{}, stepType messages.PickleStepType) (context.Context, []string, error) { + step := s.matchStepTextAndType(text, stepType) if nil == step { return ctx, []string{text}, nil } @@ -323,7 +324,7 @@ func (s *suite) maybeUndefined(ctx context.Context, text string, arg interface{} if len(lines[0]) > 0 && lines[0][len(lines[0])-1] == ':' { return ctx, undefined, fmt.Errorf("nested steps cannot be multiline and have table or content body argument") } - ctx, undef, err := s.maybeUndefined(ctx, next, nil) + ctx, undef, err := s.maybeUndefined(ctx, next, nil, messages.PickleStepType_UNKNOWN) if err != nil { return ctx, undefined, err } @@ -349,7 +350,7 @@ func (s *suite) maybeSubSteps(ctx context.Context, result interface{}) (context. var err error for _, text := range steps { - if def := s.matchStepText(text); def == nil { + if def := s.matchStepTextAndType(text, messages.PickleStepType_UNKNOWN); def == nil { return ctx, ErrUndefined } else if ctx, err = s.maybeSubSteps(def.Run(ctx)); err != nil { return ctx, fmt.Errorf("%s: %+v", text, err) @@ -358,9 +359,12 @@ func (s *suite) maybeSubSteps(ctx context.Context, result interface{}) (context. return ctx, nil } -func (s *suite) matchStepText(text string) *models.StepDefinition { +func (s *suite) matchStepTextAndType(text string, stepType messages.PickleStepType) *models.StepDefinition { for _, h := range s.steps { if m := h.Expr.FindStringSubmatch(text); len(m) > 0 { + if !keywordMatches(h.Keyword, stepType) { + continue + } var args []interface{} for _, m := range m[1:] { args = append(args, m) @@ -372,6 +376,7 @@ func (s *suite) matchStepText(text string) *models.StepDefinition { StepDefinition: formatters.StepDefinition{ Expr: h.Expr, Handler: h.Handler, + Keyword: h.Keyword, }, Args: args, HandlerValue: h.HandlerValue, @@ -382,6 +387,22 @@ func (s *suite) matchStepText(text string) *models.StepDefinition { return nil } +func keywordMatches(k formatters.Keyword, stepType messages.PickleStepType) bool { + if k == formatters.None { + return true + } + switch stepType { + case messages.PickleStepType_CONTEXT: + return k == formatters.Given + case messages.PickleStepType_ACTION: + return k == formatters.When + case messages.PickleStepType_OUTCOME: + return k == formatters.Then + default: + return true + } +} + func (s *suite) runSteps(ctx context.Context, pickle *Scenario, steps []*Step) (context.Context, error) { var ( stepErr, err error diff --git a/suite_context_test.go b/suite_context_test.go index 8d72d4aa..22c1e0a3 100644 --- a/suite_context_test.go +++ b/suite_context_test.go @@ -73,6 +73,15 @@ func InitializeScenario(ctx *ScenarioContext) { ctx.Step(`^(?:a )?passing step$`, func() error { return nil }) + ctx.Given(`^(?:a )?given step$`, func() error { + return nil + }) + ctx.When(`^(?:a )?when step$`, func() error { + return nil + }) + ctx.Then(`^(?:a )?then step$`, func() error { + return nil + }) // Introduced to test formatter/cucumber.feature ctx.Step(`^the rendered json will be as follows:$`, tc.theRenderJSONWillBe) From 1abde6f0e4298b0b1bb13e6e35592ba665bb0af5 Mon Sep 17 00:00:00 2001 From: otrava7 Date: Tue, 25 Oct 2022 14:26:30 +0100 Subject: [PATCH 4/8] test(*): keyword type in feature files --- features/events.feature | 6 +- features/formatter/pretty.feature | 109 ++++++++++++++++++++++++++++-- features/multistep.feature | 37 ++++++++++ run_test.go | 14 ++-- suite_context_test.go | 8 +++ 5 files changed, 161 insertions(+), 13 deletions(-) diff --git a/features/events.feature b/features/events.feature index 2b63767c..caaca30f 100644 --- a/features/events.feature +++ b/features/events.feature @@ -121,17 +121,17 @@ Feature: suite events Feature: scenario hook errors Scenario: failing before and after scenario # normal.feature:3 - Then adding step state to context # suite_context_test.go:0 -> InitializeScenario.func15 + Then adding step state to context # suite_context_test.go:0 -> InitializeScenario.func17 after scenario hook failed: failed in after scenario hook, step error: before scenario hook failed: failed in before scenario hook And passing step # suite_context_test.go:0 -> InitializeScenario.func2 Scenario: failing before scenario # normal.feature:7 - Then adding step state to context # suite_context_test.go:0 -> InitializeScenario.func15 + Then adding step state to context # suite_context_test.go:0 -> InitializeScenario.func17 before scenario hook failed: failed in before scenario hook And passing step # suite_context_test.go:0 -> InitializeScenario.func2 Scenario: failing after scenario # normal.feature:11 - Then adding step state to context # suite_context_test.go:0 -> InitializeScenario.func15 + Then adding step state to context # suite_context_test.go:0 -> InitializeScenario.func17 And passing step # suite_context_test.go:0 -> InitializeScenario.func2 after scenario hook failed: failed in after scenario hook diff --git a/features/formatter/pretty.feature b/features/formatter/pretty.feature index 333f63c5..197c1f50 100644 --- a/features/formatter/pretty.feature +++ b/features/formatter/pretty.feature @@ -332,11 +332,11 @@ Feature: pretty formatter Feature: inject long value Scenario: test scenario # features/inject.feature:3 - Given Ignore I save some value X under key Y # suite_context.go:0 -> SuiteContext.func10 + Given Ignore I save some value X under key Y # suite_context.go:0 -> SuiteContext.func12 And I allow variable injection # suite_context.go:0 -> *suiteContext - When Ignore I use value someverylonginjectionsoweacanbesureitsurpasstheinitiallongeststeplenghtanditwillhelptestsmethodsafety # suite_context.go:0 -> SuiteContext.func10 - Then Ignore Godog rendering should not break # suite_context.go:0 -> SuiteContext.func10 - And Ignore test # suite_context.go:0 -> SuiteContext.func10 + When Ignore I use value someverylonginjectionsoweacanbesureitsurpasstheinitiallongeststeplenghtanditwillhelptestsmethodsafety # suite_context.go:0 -> SuiteContext.func12 + Then Ignore Godog rendering should not break # suite_context.go:0 -> SuiteContext.func12 + And Ignore test # suite_context.go:0 -> SuiteContext.func12 | key | val | | 1 | 2 | | 3 | 4 | @@ -582,4 +582,105 @@ Feature: pretty formatter func InitializeScenario(ctx *godog.ScenarioContext) { ctx.Step(`^a when step$`, aWhenStep) } + """ + + Scenario: Use 'when' keyword on a declared 'then' step + Given a feature "features/simple.feature" file: + """ + Feature: simple feature with a rule + simple feature description + Rule: simple rule + simple rule description + Example: simple scenario + simple scenario description + When a then step + """ + When I run feature suite with formatter "pretty" + Then the rendered output will be as follows: + """ + Feature: simple feature with a rule + simple feature description + + Example: simple scenario # features/simple.feature:5 + When a then step + + 1 scenarios (1 undefined) + 1 steps (1 undefined) + 0s + + You can implement step definitions for undefined steps with these snippets: + + func aThenStep() error { + return godog.ErrPending + } + + func InitializeScenario(ctx *godog.ScenarioContext) { + ctx.Step(`^a then step$`, aThenStep) + } + """ + + Scenario: Use 'then' keyword on a declared 'given' step + Given a feature "features/simple.feature" file: + """ + Feature: simple feature with a rule + simple feature description + Rule: simple rule + simple rule description + Example: simple scenario + simple scenario description + Then a given step + """ + When I run feature suite with formatter "pretty" + Then the rendered output will be as follows: + """ + Feature: simple feature with a rule + simple feature description + + Example: simple scenario # features/simple.feature:5 + Then a given step + + 1 scenarios (1 undefined) + 1 steps (1 undefined) + 0s + + You can implement step definitions for undefined steps with these snippets: + + func aGivenStep() error { + return godog.ErrPending + } + + func InitializeScenario(ctx *godog.ScenarioContext) { + ctx.Step(`^a given step$`, aGivenStep) + } + """ + + Scenario: Match keyword functions correctly + Given a feature "features/simple.feature" file: + """ + Feature: simple feature with a rule + simple feature description + Rule: simple rule + simple rule description + Example: simple scenario + simple scenario description + Given a given step + When a when step + Then a then step + And a then step + """ + When I run feature suite with formatter "pretty" + Then the rendered output will be as follows: + """ + Feature: simple feature with a rule + simple feature description + + Example: simple scenario # features/simple.feature:5 + Given a given step # suite_context_test.go:0 -> InitializeScenario.func3 + When a when step # suite_context_test.go:0 -> InitializeScenario.func4 + Then a then step # suite_context_test.go:0 -> InitializeScenario.func5 + And a then step # suite_context_test.go:0 -> InitializeScenario.func5 + + 1 scenarios (1 passed) + 4 steps (4 passed) + 0s """ \ No newline at end of file diff --git a/features/multistep.feature b/features/multistep.feature index a9726788..0681b159 100644 --- a/features/multistep.feature +++ b/features/multistep.feature @@ -161,3 +161,40 @@ Feature: run features with nested steps """ When I run feature suite Then the suite should have passed + + Scenario: should run passing multistep using keyword function successfully + Given a feature "normal.feature" file: + """ + Feature: normal feature + + Scenario: run passing multistep + Given passing step + Then passing multistep using 'then' function + """ + When I run feature suite + Then the suite should have passed + And the following steps should be passed: + """ + passing step + passing multistep using 'then' function + """ + + Scenario: should identify undefined multistep using keyword function + Given a feature "normal.feature" file: + """ + Feature: normal feature + + Scenario: run passing multistep + Given passing step + Then undefined multistep using 'then' function + """ + When I run feature suite + Then the suite should have passed + And the following steps should be passed: + """ + passing step + """ + And the following step should be undefined: + """ + undefined multistep using 'then' function + """ diff --git a/run_test.go b/run_test.go index f5b5e214..ad8c1331 100644 --- a/run_test.go +++ b/run_test.go @@ -518,11 +518,12 @@ func Test_AllFeaturesRun(t *testing.T) { ...................................................................... 140 ...................................................................... 210 ...................................................................... 280 -.......................................................... 338 +...................................................................... 350 +...... 356 -89 scenarios (89 passed) -338 steps (338 passed) +94 scenarios (94 passed) +356 steps (356 passed) 0s ` @@ -545,11 +546,12 @@ func Test_AllFeaturesRunAsSubtests(t *testing.T) { ...................................................................... 140 ...................................................................... 210 ...................................................................... 280 -.......................................................... 338 +...................................................................... 350 +...... 356 -89 scenarios (89 passed) -338 steps (338 passed) +94 scenarios (94 passed) +356 steps (356 passed) 0s ` diff --git a/suite_context_test.go b/suite_context_test.go index 22c1e0a3..296cf6db 100644 --- a/suite_context_test.go +++ b/suite_context_test.go @@ -100,10 +100,18 @@ func InitializeScenario(ctx *ScenarioContext) { return Steps{"passing step", "undefined step", "passing step"} }) + ctx.Then(`^(?:a |an )?undefined multistep using 'then' function$`, func() Steps { + return Steps{"passing step", "undefined step", "passing step"} + }) + ctx.Step(`^(?:a )?passing multistep$`, func() Steps { return Steps{"passing step", "passing step", "passing step"} }) + ctx.Then(`^(?:a )?passing multistep using 'then' function$`, func() Steps { + return Steps{"passing step", "passing step", "passing step"} + }) + ctx.Step(`^(?:a )?failing nested multistep$`, func() Steps { return Steps{"passing step", "passing multistep", "failing multistep"} }) From acc6cc802b729144ed9c39f401ee724cabc76f29 Mon Sep 17 00:00:00 2001 From: otrava7 Date: Tue, 25 Oct 2022 15:30:55 +0100 Subject: [PATCH 5/8] docs(*): update step-by-step walkthrough to mention the option of using keyword functions --- README.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/README.md b/README.md index 1679f490..b3e1cafc 100644 --- a/README.md +++ b/README.md @@ -164,6 +164,15 @@ func InitializeScenario(ctx *godog.ScenarioContext) { } ``` +Alternatively, you can also specify the keyword (Given, When, Then...) when creating the step definitions: +``` go +func InitializeScenario(ctx *godog.ScenarioContext) { + ctx.Given(`^I eat (\d+)$`, iEat) + ctx.When(`^there are (\d+) godogs$`, thereAreGodogs) + ctx.Then(`^there should be (\d+) remaining$`, thereShouldBeRemaining) +} +``` + Our module should now look like this: ``` godogs From 1c796a465d695c5a6cc58217dae96974d9588283 Mon Sep 17 00:00:00 2001 From: otrava7 Date: Fri, 28 Oct 2022 12:25:46 +0100 Subject: [PATCH 6/8] docs(*): update CHANGELOG.md --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index dfdd8d9c..68dfa85d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,9 @@ This document is formatted according to the principles of [Keep A CHANGELOG](htt ## Unreleased +### Added +- Added keyword functions. ([509](https://github.com/cucumber/godog/pull/509) - [otrava7](https://github.com/otrava7)) + ### Changed - README example is updated with `context.Context` and `go test` usage. ([477](https://github.com/cucumber/godog/pull/477) - [vearutop](https://github.com/vearutop)) - Removed deprecation of `godog.BindFlags` ([498](https://github.com/cucumber/godog/pull/498) - [vearutop](https://github.com/vearutop)) From b9c9aabe766957baf6b5520df0261abca07397ab Mon Sep 17 00:00:00 2001 From: otrava7 Date: Mon, 31 Oct 2022 12:40:52 +0000 Subject: [PATCH 7/8] test(*): keyword substeps --- suite_context_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/suite_context_test.go b/suite_context_test.go index 296cf6db..e8fa90d1 100644 --- a/suite_context_test.go +++ b/suite_context_test.go @@ -101,7 +101,7 @@ func InitializeScenario(ctx *ScenarioContext) { }) ctx.Then(`^(?:a |an )?undefined multistep using 'then' function$`, func() Steps { - return Steps{"passing step", "undefined step", "passing step"} + return Steps{"given step", "undefined step", "then step"} }) ctx.Step(`^(?:a )?passing multistep$`, func() Steps { @@ -109,7 +109,7 @@ func InitializeScenario(ctx *ScenarioContext) { }) ctx.Then(`^(?:a )?passing multistep using 'then' function$`, func() Steps { - return Steps{"passing step", "passing step", "passing step"} + return Steps{"given step", "when step", "then step"} }) ctx.Step(`^(?:a )?failing nested multistep$`, func() Steps { From 5d6dcfd9449c35c8d465d44334e781acf664b5b0 Mon Sep 17 00:00:00 2001 From: otrava7 Date: Thu, 5 Jan 2023 12:46:34 +0000 Subject: [PATCH 8/8] chore(*): go mod --- go.mod | 1 - 1 file changed, 1 deletion(-) diff --git a/go.mod b/go.mod index 5b43293f..c4c3b460 100644 --- a/go.mod +++ b/go.mod @@ -16,5 +16,4 @@ require ( github.com/hashicorp/go-immutable-radix v1.3.1 // indirect github.com/hashicorp/go-uuid v1.0.2 // indirect gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect - gopkg.in/yaml.v3 v3.0.1 // indirect )