diff --git a/Makefile b/Makefile index 6fa7bd0..042067d 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,6 @@ -.PHONY: test gherkin +.PHONY: test gherkin bump + +VERS := $(shell grep 'const Version' -m 1 godog.go | awk -F\" '{print $$2}') test: @echo "running all tests" @@ -16,3 +18,10 @@ gherkin: @mkdir gherkin @curl -s -L https://github.com/cucumber/gherkin-go/tarball/$(VERS) | tar -C gherkin -zx --strip-components 1 @rm -rf gherkin/{.travis.yml,.gitignore,*_test.go,gherkin-generate*,*.razor,*.jq,Makefile,CONTRIBUTING.md} + +bump: + @if [ -z "$(VERSION)" ]; then echo "Provide version like: 'VERSION=$(VERS) make bump'"; exit 1; fi + @echo "bumping version from: $(VERS) to $(VERSION)" + @sed -i.bak 's/$(VERS)/$(VERSION)/g' godog.go + @sed -i.bak 's/$(VERS)/$(VERSION)/g' examples/api/version.feature + @find . -name '*.bak' | xargs rm diff --git a/README.md b/README.md index 8fc0fb0..6e1c576 100644 --- a/README.md +++ b/README.md @@ -157,9 +157,13 @@ See implementation examples: ### Changes +**2016-05-28** +- show nicely formatted called step func name and file path + **2016-05-26** - pack gherkin dependency in a subpackage to prevent compatibility - conflicts. + conflicts in the future. If recently upgraded, probably you will need to + reference gherkin as `github.com/DATA-DOG/godog/gherkin` instead. **2016-05-25** - refactored test suite build tooling in order to use standard **go test** diff --git a/examples/api/README.md b/examples/api/README.md index ca50967..3d56896 100644 --- a/examples/api/README.md +++ b/examples/api/README.md @@ -57,7 +57,7 @@ package main import ( "github.com/DATA-DOG/godog" - "gopkg.in/cucumber/gherkin-go.v3" + "github.com/DATA-DOG/godog/gherkin" ) type apiFeature struct { diff --git a/examples/api/api_test.go b/examples/api/api_test.go index 5d47498..ab2af6b 100644 --- a/examples/api/api_test.go +++ b/examples/api/api_test.go @@ -8,7 +8,7 @@ import ( "net/http/httptest" "github.com/DATA-DOG/godog" - "gopkg.in/cucumber/gherkin-go.v3" + "github.com/DATA-DOG/godog/gherkin" ) type apiFeature struct { diff --git a/examples/api/version.feature b/examples/api/version.feature index 1acfd7c..93d8e0f 100644 --- a/examples/api/version.feature +++ b/examples/api/version.feature @@ -20,6 +20,6 @@ Feature: get version And the response should match json: """ { - "version": "v0.2.0" + "version": "v0.4.2" } """ diff --git a/examples/db/api_test.go b/examples/db/api_test.go index 2557135..ef48102 100644 --- a/examples/db/api_test.go +++ b/examples/db/api_test.go @@ -8,8 +8,9 @@ import ( "net/http/httptest" "strings" + "github.com/DATA-DOG/go-txdb" "github.com/DATA-DOG/godog" - "gopkg.in/cucumber/gherkin-go.v3" + "github.com/DATA-DOG/godog/gherkin" ) func init() { diff --git a/godog.go b/godog.go index fcf96ed..d221f1b 100644 --- a/godog.go +++ b/godog.go @@ -44,4 +44,4 @@ Godog was inspired by Behat and the above description is taken from it's documen package godog // Version of package - based on Semantic Versioning 2.0.0 http://semver.org/ -const Version = "v0.4.0" +const Version = "v0.4.2" diff --git a/stepdef.go b/stepdef.go index 70bc2b3..6ce06ce 100644 --- a/stepdef.go +++ b/stepdef.go @@ -2,14 +2,18 @@ package godog import ( "fmt" + "path/filepath" "reflect" "regexp" "runtime" "strconv" + "strings" "github.com/DATA-DOG/godog/gherkin" ) +var matchFuncDefRef = regexp.MustCompile(`\(([^\)]+)\)`) + // StepDef is a registered step definition // contains a StepHandler and regexp which // is used to match a step. Args which @@ -26,7 +30,25 @@ type StepDef struct { } func (sd *StepDef) funcName() string { - return runtime.FuncForPC(sd.hv.Pointer()).Name() + ptr := sd.hv.Pointer() + f := runtime.FuncForPC(ptr) + file, line := f.FileLine(ptr) + dir := filepath.Dir(file) + + fn := strings.Replace(f.Name(), dir, "", -1) + var parts []string + for _, gr := range matchFuncDefRef.FindAllStringSubmatch(fn, -1) { + parts = append(parts, strings.Trim(gr[1], "_.")) + } + if len(parts) > 0 { + // case when suite is a structure with methods + fn = strings.Join(parts, ".") + } else { + // case when steps are just plain funcs + fn = strings.Trim(fn, "_.") + } + + return fmt.Sprintf("%s:%d -> %s", filepath.Base(file), line, fn) } // run a step with the matched arguments using @@ -153,6 +175,7 @@ func (sd *StepDef) run() error { if nil == ret { return nil } + return ret.(error) }