From 7b4f70ae626e30e9c955a13c666c021c57d6e717 Mon Sep 17 00:00:00 2001 From: Vincent LALANNE Date: Thu, 23 Nov 2023 08:20:11 +0000 Subject: [PATCH 1/2] feat: Add support for step argument (go-bdd#149) --- .github/workflows/ci.yml | 4 ++-- features/argument.feature | 21 +++++++++++++++++++++ gobdd.go | 3 +++ gobdd_test.go | 8 ++++++++ 4 files changed, 34 insertions(+), 2 deletions(-) create mode 100644 features/argument.feature diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 83db2dc..b1838a1 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -18,14 +18,14 @@ jobs: uses: golangci/golangci-lint-action@v3 with: # Required: the version of golangci-lint is required and must be specified without patch version: we always use the latest patch version. - version: v1.47 + version: v1.55 coverage: name: Build runs-on: ubuntu-latest strategy: matrix: - go: ['1.12', '1.13', '1.14', '1.15', '1.16', '1.17', '1.18'] + go: ['1.12', '1.13', '1.14', '1.15', '1.16', '1.17', '1.18', '1.19', '1.20', '1.21'] env: GOFLAGS: -mod=readonly GOPROXY: https://proxy.golang.org diff --git a/features/argument.feature b/features/argument.feature new file mode 100644 index 0000000..2e2807e --- /dev/null +++ b/features/argument.feature @@ -0,0 +1,21 @@ +Feature: Argument feature + Scenario: compare text with argument + When I concat text "Hello " and argument: + """ + World! + """ + Then the result should equal argument: + """ + Hello World! + """ + Scenario: compare text with multiline argument + When I concat text "Hello " and argument: + """ + New + World! + """ + Then the result should equal argument: + """ + Hello New + World! + """ diff --git a/gobdd.go b/gobdd.go index 28edfe8..22b410f 100644 --- a/gobdd.go +++ b/gobdd.go @@ -541,6 +541,9 @@ 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)) + } t.Run(fmt.Sprintf("%s %s", strings.TrimSpace(step.Keyword), step.Text), func(t *testing.T) { // NOTE consider passing t as argument to step hooks ctx.Set(TestingTKey{}, t) diff --git a/gobdd_test.go b/gobdd_test.go index 0b915d8..3764619 100644 --- a/gobdd_test.go +++ b/gobdd_test.go @@ -68,6 +68,14 @@ func TestParameterTypes(t *testing.T) { suite.Run() } +func TestArguments(t *testing.T) { + suite := NewSuite(t, WithFeaturesPath("features/argument.feature")) + suite.AddStep(`the result should equal argument:`, checkt) + suite.AddStep(`I concat text {text} and argument:`, concat) + + suite.Run() +} + func TestScenarioOutlineExecutesAllTests(t *testing.T) { c := 0 suite := NewSuite(t, WithFeaturesPath("features/outline.feature")) From 9c80b5bf8e98f500af7808c5652bafa4483a6e9b Mon Sep 17 00:00:00 2001 From: Vincent LALANNE Date: Thu, 23 Nov 2023 10:52:22 +0000 Subject: [PATCH 2/2] style: update linter --- .golangci.yml | 1 + context_test.go | 6 +++--- gobdd.go | 13 +++++++------ gobdd_go1_16.go | 2 +- 4 files changed, 12 insertions(+), 10 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index ed35fda..8cc2654 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -16,6 +16,7 @@ linters: - golint - scopelint - gosec + - depguard # Disabled after upgrading golangci-lint # Enable them after issues are resolved diff --git a/context_test.go b/context_test.go index e58065d..9c77696 100644 --- a/context_test.go +++ b/context_test.go @@ -3,7 +3,7 @@ package gobdd import ( "testing" - "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" ) func TestContextNilInGetError(t *testing.T) { @@ -11,6 +11,6 @@ func TestContextNilInGetError(t *testing.T) { ctx.Set("err", nil) res, err := ctx.GetError("err") - assert.NoError(t, err) - assert.Nil(t, res) + require.NoError(t, err) + require.NoError(t, res) } diff --git a/gobdd.go b/gobdd.go index 22b410f..99853d2 100644 --- a/gobdd.go +++ b/gobdd.go @@ -152,12 +152,12 @@ type stepDef struct { } type StepTest interface { - Log(...interface{}) - Logf(string, ...interface{}) - Fatal(...interface{}) - Fatalf(string, ...interface{}) - Errorf(string, ...interface{}) - Error(...interface{}) + Log(args ...interface{}) + Logf(format string, args ...interface{}) + Fatal(args ...interface{}) + Fatalf(format string, args ...interface{}) + Errorf(format string, args ...interface{}) + Error(args ...interface{}) Fail() FailNow() @@ -544,6 +544,7 @@ func (s *Suite) runStep(ctx Context, t *testing.T, step *msgs.GherkinDocument_Fe if argument, ok := step.Argument.(*msgs.GherkinDocument_Feature_Step_DocString_); ok { params = append(params, []byte(argument.DocString.Content)) } + t.Run(fmt.Sprintf("%s %s", strings.TrimSpace(step.Keyword), step.Text), func(t *testing.T) { // NOTE consider passing t as argument to step hooks ctx.Set(TestingTKey{}, t) diff --git a/gobdd_go1_16.go b/gobdd_go1_16.go index 8b3ceb2..2e4d4f4 100644 --- a/gobdd_go1_16.go +++ b/gobdd_go1_16.go @@ -13,7 +13,7 @@ import ( func WithFeaturesFS(fs fs.FS, path string) func(*SuiteOptions) { return func(options *SuiteOptions) { options.featureSource = fsFeatureSource{ - fs: fs, + fs: fs, path: path, } }