matched step func name and reference in pretty printer

Этот коммит содержится в:
gedi 2016-05-28 20:20:17 +03:00
родитель f9fab51a1a
коммит f9eab9da27
8 изменённых файлов: 45 добавлений и 8 удалений

Просмотреть файл

@ -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: test:
@echo "running all tests" @echo "running all tests"
@ -16,3 +18,10 @@ gherkin:
@mkdir gherkin @mkdir gherkin
@curl -s -L https://github.com/cucumber/gherkin-go/tarball/$(VERS) | tar -C gherkin -zx --strip-components 1 @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} @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

Просмотреть файл

@ -157,9 +157,13 @@ See implementation examples:
### Changes ### Changes
**2016-05-28**
- show nicely formatted called step func name and file path
**2016-05-26** **2016-05-26**
- pack gherkin dependency in a subpackage to prevent compatibility - 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** **2016-05-25**
- refactored test suite build tooling in order to use standard **go test** - refactored test suite build tooling in order to use standard **go test**

Просмотреть файл

@ -57,7 +57,7 @@ package main
import ( import (
"github.com/DATA-DOG/godog" "github.com/DATA-DOG/godog"
"gopkg.in/cucumber/gherkin-go.v3" "github.com/DATA-DOG/godog/gherkin"
) )
type apiFeature struct { type apiFeature struct {

Просмотреть файл

@ -8,7 +8,7 @@ import (
"net/http/httptest" "net/http/httptest"
"github.com/DATA-DOG/godog" "github.com/DATA-DOG/godog"
"gopkg.in/cucumber/gherkin-go.v3" "github.com/DATA-DOG/godog/gherkin"
) )
type apiFeature struct { type apiFeature struct {

Просмотреть файл

@ -20,6 +20,6 @@ Feature: get version
And the response should match json: And the response should match json:
""" """
{ {
"version": "v0.2.0" "version": "v0.4.2"
} }
""" """

Просмотреть файл

@ -8,8 +8,9 @@ import (
"net/http/httptest" "net/http/httptest"
"strings" "strings"
"github.com/DATA-DOG/go-txdb"
"github.com/DATA-DOG/godog" "github.com/DATA-DOG/godog"
"gopkg.in/cucumber/gherkin-go.v3" "github.com/DATA-DOG/godog/gherkin"
) )
func init() { func init() {

Просмотреть файл

@ -44,4 +44,4 @@ Godog was inspired by Behat and the above description is taken from it's documen
package godog package godog
// Version of package - based on Semantic Versioning 2.0.0 http://semver.org/ // Version of package - based on Semantic Versioning 2.0.0 http://semver.org/
const Version = "v0.4.0" const Version = "v0.4.2"

Просмотреть файл

@ -2,14 +2,18 @@ package godog
import ( import (
"fmt" "fmt"
"path/filepath"
"reflect" "reflect"
"regexp" "regexp"
"runtime" "runtime"
"strconv" "strconv"
"strings"
"github.com/DATA-DOG/godog/gherkin" "github.com/DATA-DOG/godog/gherkin"
) )
var matchFuncDefRef = regexp.MustCompile(`\(([^\)]+)\)`)
// StepDef is a registered step definition // StepDef is a registered step definition
// contains a StepHandler and regexp which // contains a StepHandler and regexp which
// is used to match a step. Args which // is used to match a step. Args which
@ -26,7 +30,25 @@ type StepDef struct {
} }
func (sd *StepDef) funcName() string { 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 // run a step with the matched arguments using
@ -153,6 +175,7 @@ func (sd *StepDef) run() error {
if nil == ret { if nil == ret {
return nil return nil
} }
return ret.(error) return ret.(error)
} }