Skip to content

Commit

Permalink
fix: recursive glob pattern for features directory (#26)
Browse files Browse the repository at this point in the history
Closes #25

---------

Co-authored-by: 0xste_bd <[email protected]>
  • Loading branch information
0xste and 0xste_bd authored Nov 30, 2023
1 parent d39ed9c commit 620b666
Show file tree
Hide file tree
Showing 8 changed files with 56 additions and 4 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ tests. `Runner.ShortTags` method can be used to select a set of tags to

`Runner` has the following methods for setting custom options

* `Path()` sets custom paths. The default is `features/*.feature`.
* `Path()` sets custom paths, and accepts `**` glob patterns making use of the [doublestar](https://github.com/bmatcuk/doublestar/tree/master) library. The default is `features/**/*.feature`
* `Step()` can be used to add custom steps with special regular expressions.
* `Before()`, `After()`, `BeforeStep()`, or and `AfterStep()` can be used to register custom hooks.
* `Tags` and `ShortTags` can be used with tag expressions as described above.
Expand Down
6 changes: 6 additions & 0 deletions _examples/subdirectories/features/one/one.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Feature: one

Scenario: eat cukes
Given I have 10 cukes
When I eat 1
Then I have 9 left
6 changes: 6 additions & 0 deletions _examples/subdirectories/features/two/two.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Feature: two

Scenario: eat cukes
Given I have 10 cukes
When I eat 2
Then I have 8 left
6 changes: 6 additions & 0 deletions _examples/subdirectories/features/zero.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Feature: zero

Scenario: eat cukes
Given I have 10 cukes
When I eat 0
Then I have 10 left
31 changes: 31 additions & 0 deletions _examples/subdirectories/runner_test.go
Original file line number Diff line number Diff line change
@@ -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)
}
}
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -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=
Expand Down
6 changes: 3 additions & 3 deletions run.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand All @@ -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
Expand All @@ -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}
Expand Down

0 comments on commit 620b666

Please sign in to comment.