From f2e583c6e4acaa30851fe2fe103c109902c4c633 Mon Sep 17 00:00:00 2001 From: 0xste_bd Date: Mon, 27 Nov 2023 17:45:22 +0000 Subject: [PATCH] fix: issue#25 recursive glob pattern for features directory --- .../subdirectories/features/one/one.feature | 6 ++++ .../subdirectories/features/two/two.feature | 6 ++++ .../subdirectories/features/zero.feature | 6 ++++ _examples/subdirectories/runner_test.go | 31 +++++++++++++++++++ go.mod | 1 + go.sum | 2 ++ run.go | 6 ++-- 7 files changed, 55 insertions(+), 3 deletions(-) create mode 100644 _examples/subdirectories/features/one/one.feature create mode 100644 _examples/subdirectories/features/two/two.feature create mode 100644 _examples/subdirectories/features/zero.feature create mode 100644 _examples/subdirectories/runner_test.go diff --git a/_examples/subdirectories/features/one/one.feature b/_examples/subdirectories/features/one/one.feature new file mode 100644 index 0000000..2e6e31f --- /dev/null +++ b/_examples/subdirectories/features/one/one.feature @@ -0,0 +1,6 @@ +Feature: one + + Scenario: eat cukes + Given I have 10 cukes + When I eat 1 + Then I have 9 left diff --git a/_examples/subdirectories/features/two/two.feature b/_examples/subdirectories/features/two/two.feature new file mode 100644 index 0000000..b3dc48e --- /dev/null +++ b/_examples/subdirectories/features/two/two.feature @@ -0,0 +1,6 @@ +Feature: two + + Scenario: eat cukes + Given I have 10 cukes + When I eat 2 + Then I have 8 left diff --git a/_examples/subdirectories/features/zero.feature b/_examples/subdirectories/features/zero.feature new file mode 100644 index 0000000..25c4504 --- /dev/null +++ b/_examples/subdirectories/features/zero.feature @@ -0,0 +1,6 @@ +Feature: zero + + Scenario: eat cukes + Given I have 10 cukes + When I eat 0 + Then I have 10 left diff --git a/_examples/subdirectories/runner_test.go b/_examples/subdirectories/runner_test.go new file mode 100644 index 0000000..c8f53d6 --- /dev/null +++ b/_examples/subdirectories/runner_test.go @@ -0,0 +1,31 @@ +package main + +import ( + "testing" + + "github.com/regen-network/gocuke" +) + +// should recursively load scenarios from features directory +func TestSimple(t *testing.T) { + gocuke.NewRunner(t, &simpleSuite{}).Run() +} + +type simpleSuite struct { + gocuke.TestingT + cukes int64 +} + +func (s *simpleSuite) IHaveCukes(a int64) { + s.cukes = a +} + +func (s *simpleSuite) IEat(a int64) { + s.cukes -= a +} + +func (s *simpleSuite) IHaveLeft(a int64) { + if a != s.cukes { + s.Fatalf("expected %d cukes, have %d", a, s.cukes) + } +} diff --git a/go.mod b/go.mod index e434757..e43d75c 100644 --- a/go.mod +++ b/go.mod @@ -3,6 +3,7 @@ module github.com/regen-network/gocuke go 1.21 require ( + github.com/bmatcuk/doublestar/v4 v4.6.1 github.com/cockroachdb/apd/v3 v3.2.1 github.com/cucumber/common/messages/go/v19 v19.1.2 github.com/cucumber/gherkin/go/v26 v26.2.0 diff --git a/go.sum b/go.sum index a8a35ed..925ddea 100644 --- a/go.sum +++ b/go.sum @@ -1,3 +1,5 @@ +github.com/bmatcuk/doublestar/v4 v4.6.1 h1:FH9SifrbvJhnlQpztAx++wlkk70QBf0iBWDwNy7PA4I= +github.com/bmatcuk/doublestar/v4 v4.6.1/go.mod h1:xBQ8jztBU6kakFMg+8WGxn0c6z1fTSPVIjEY1Wr7jzc= github.com/cockroachdb/apd/v3 v3.2.1 h1:U+8j7t0axsIgvQUqthuNm82HIrYXodOV2iWLWtEaIwg= github.com/cockroachdb/apd/v3 v3.2.1/go.mod h1:klXJcjp+FffLTHlhIG69tezTDvdP065naDsHzKhYSqc= github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= diff --git a/run.go b/run.go index 8b2f8fb..2e60dd3 100644 --- a/run.go +++ b/run.go @@ -2,11 +2,11 @@ package gocuke import ( "os" - "path/filepath" "reflect" "strings" "testing" + "github.com/bmatcuk/doublestar/v4" gherkin "github.com/cucumber/gherkin/go/v26" "gotest.tools/v3/assert" ) @@ -17,7 +17,7 @@ func (r *Runner) Run() { paths := r.paths if len(paths) == 0 { - paths = []string{"features/*.feature"} + paths = []string{"features/**/*.feature"} } haveTests := false @@ -29,7 +29,7 @@ func (r *Runner) Run() { // not doing this allows mis-spellings in exact paths to be skipped silently if strings.Contains(path, "*") { var err error - files, err = filepath.Glob(path) + files, err = doublestar.FilepathGlob(path) assert.NilError(r.topLevelT, err) } else { files = []string{path}