Skip to content

Commit

Permalink
feat: output suggestions in the order they were encountered
Browse files Browse the repository at this point in the history
  • Loading branch information
aaronc committed Feb 12, 2024
1 parent d7d6b11 commit 52119f8
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 12 deletions.
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,22 +77,22 @@ type suite struct {
When you run the tests, they should fail and suggest that you add these
step definitions:
```go
func (s *suite) IEat(a int64) {
func (s *suite) IHaveCukes(a int64) {
panic("PENDING")
}

func (s *suite) IHaveLeft(a int64) {
func (s *suite) IEat(a int64) {
panic("PENDING")
}

func (s *suite) IHaveCukes(a int64) {
func (s *suite) IHaveLeft(a int64) {
panic("PENDING")
}

Steps can be manually registered with the runner for customization using this code:
Step(`^I\s+have\s+(-?\d+)\s+cukes$`, (*simpleSuite).IHaveCukes).
Step(`^I\s+eat\s+(-?\d+)$`, (*simpleSuite).IEat).
Step(`^I\s+have\s+(-?\d+)\s+left$`, (*simpleSuite).IHaveLeft)
Step(`^I\s+have\s+(-?\d+)\s+cukes$`, (*suite).IHaveCukes).
Step(`^I\s+eat\s+(-?\d+)$`, (*suite).IEat).
Step(`^I\s+have\s+(-?\d+)\s+left$`, (*suite).IHaveLeft)
```

Copy these definitions into `simple_test.go`.
Expand Down
5 changes: 4 additions & 1 deletion find_step.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@ func (r *Runner) findStep(t *testing.T, step *messages.PickleStep) *stepDef {
return r.addStepDef(t, sig.regex, method.Func)
}

r.suggestions[sig.name] = sig
if !r.haveSuggestion[sig.name] {
r.haveSuggestion[sig.name] = true
r.suggestions = append(r.suggestions, sig)
}
t.Errorf("can't find step definition for: %s", step.Text)

return nil
Expand Down
11 changes: 6 additions & 5 deletions runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ type Runner struct {
paths []string
parallel bool
stepDefs []*stepDef
suggestions map[string]methodSig
haveSuggestion map[string]bool
suggestions []methodSig
supportedSpecialArgs map[reflect.Type]specialArgGetter
suiteInjectors []*suiteInjector
beforeHooks []*stepDef
Expand Down Expand Up @@ -56,10 +57,10 @@ func NewRunner(t *testing.T, suiteType interface{}) *Runner {
initGlobalTagExpr()

r := &Runner{
topLevelT: t,
incr: &messages.Incrementing{},
parallel: false,
suggestions: map[string]methodSig{},
topLevelT: t,
incr: &messages.Incrementing{},
parallel: false,
haveSuggestion: map[string]bool{},
supportedSpecialArgs: map[reflect.Type]specialArgGetter{
// TestingT
reflect.TypeOf((*TestingT)(nil)).Elem(): func(runner *scenarioRunner) interface{} {
Expand Down

0 comments on commit 52119f8

Please sign in to comment.