Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix issue #34 #35

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 18 additions & 5 deletions find_step.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ import (
func (r *Runner) findStep(t *testing.T, step *messages.PickleStep) *stepDef {
t.Helper()

for _, def := range r.stepDefs {
matches := def.regex.FindSubmatch([]byte(step.Text))
if len(matches) != 0 {
return def
}
r.stepDefsMutex.RLock()
def := findSubmatch(t, step.Text, r.stepDefs)
r.stepDefsMutex.RUnlock()
if def != nil {
return def
}

sig := guessMethodSig(step)
Expand All @@ -30,3 +30,16 @@ func (r *Runner) findStep(t *testing.T, step *messages.PickleStep) *stepDef {

return nil
}

func findSubmatch(t *testing.T, stepText string, stepDefs []*stepDef) *stepDef {
t.Helper()

for _, def := range stepDefs {
matches := def.regex.FindSubmatch([]byte(stepText))
if len(matches) != 0 {
return def
}
}

return nil
}
3 changes: 3 additions & 0 deletions runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package gocuke

import (
"reflect"
"sync"
"testing"

messages "github.com/cucumber/messages/go/v22"
Expand All @@ -17,6 +18,7 @@ type Runner struct {
paths []string
parallel bool
stepDefs []*stepDef
stepDefsMutex *sync.RWMutex
haveSuggestion map[string]bool
suggestions []methodSig
supportedSpecialArgs map[reflect.Type]specialArgGetter
Expand Down Expand Up @@ -84,6 +86,7 @@ func NewRunner(t *testing.T, suiteType interface{}) *Runner {
},
},
suiteUsesRapid: false,
stepDefsMutex: &sync.RWMutex{},
}

r.registerSuite(suiteType)
Expand Down
2 changes: 2 additions & 0 deletions step_def.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,9 @@ func (r *Runner) Step(step interface{}, definition interface{}) *Runner {

func (r *Runner) addStepDef(t *testing.T, exp *regexp.Regexp, definition reflect.Value) *stepDef {
t.Helper()
defer r.stepDefsMutex.Unlock()

r.stepDefsMutex.Lock()
def := r.newStepDefOrHook(t, exp, definition)
r.stepDefs = append(r.stepDefs, def)
return def
Expand Down
Loading