diff --git a/CHANGELOG.md b/CHANGELOG.md index 081c6ec..c91dae2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,14 @@ # Change LOG +**2017-08-31** +- added **BeforeFeature** and **AfterFeature** hooks. +- failed multistep error is now prepended with a parent step text in order + to determine failed nested step. +- pretty format now removes the step definition location package name in + comment next to step if the step definition matches tested package. If + step definition is imported from other package, full package name will + be printed. + **2017-05-04** - added **--strict** option in order to fail suite when there are pending or undefined steps. By default, suite passes and treats pending or diff --git a/builder.go b/builder.go index 7ce40cb..0089418 100644 --- a/builder.go +++ b/builder.go @@ -35,6 +35,7 @@ import ( func main() { status := godog.Run("{{ .Name }}", func (suite *godog.Suite) { + os.Setenv("GODOG_TESTED_PACKAGE", "{{.ImportPath}}") {{range .Contexts}} _test.{{ . }}(suite) {{end}} diff --git a/examples/api/version.feature b/examples/api/version.feature index c09d5ff..244028c 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.7.2" + "version": "v0.7.4" } """ diff --git a/fmt_progress_test.go b/fmt_progress_test.go index 4fd289b..d34a3af 100644 --- a/fmt_progress_test.go +++ b/fmt_progress_test.go @@ -184,13 +184,14 @@ Error: sub2: sub-sub: errored 1 scenarios (1 failed) 2 steps (1 passed, 1 failed) -0s +%s Randomized with seed: %s ` expected = trimAllLines(expected) - expected = fmt.Sprintf(expected, os.Getenv("GODOG_SEED")) + var zeroDuration time.Duration + expected = fmt.Sprintf(expected, zeroDuration.String(), os.Getenv("GODOG_SEED")) actual := trimAllLines(buf.String()) shouldMatchOutput(expected, actual, t) diff --git a/godog.go b/godog.go index 8d093a4..5a93d9c 100644 --- a/godog.go +++ b/godog.go @@ -39,4 +39,4 @@ Godog was inspired by Behat and Cucumber the above description is taken from it' package godog // Version of package - based on Semantic Versioning 2.0.0 http://semver.org/ -const Version = "v0.7.3" +const Version = "v0.7.4" diff --git a/run.go b/run.go index 01448fb..c1c488f 100644 --- a/run.go +++ b/run.go @@ -4,6 +4,8 @@ import ( "fmt" "io" "os" + "path/filepath" + "runtime" "strconv" "strings" @@ -154,6 +156,9 @@ func RunWithOptions(suite string, contextInitializer func(suite *Suite), opt Opt // store chosen seed in environment, so it could be seen in formatter summary report os.Setenv("GODOG_SEED", strconv.FormatInt(r.randomSeed, 10)) + // determine tested package + _, filename, _, _ := runtime.Caller(1) + os.Setenv("GODOG_TESTED_PACKAGE", runsFromPackage(filename)) var failed bool if opt.Concurrency > 1 { @@ -167,6 +172,17 @@ func RunWithOptions(suite string, contextInitializer func(suite *Suite), opt Opt return exitSuccess } +func runsFromPackage(fp string) string { + dir := filepath.Dir(fp) + for _, gp := range gopaths { + gp = filepath.Join(gp, "src") + if strings.Index(dir, gp) == 0 { + return strings.TrimLeft(strings.Replace(dir, gp, "", 1), string(filepath.Separator)) + } + } + return dir +} + // Run creates and runs the feature suite. // Reads all configuration options from flags. // uses contextInitializer to register contexts diff --git a/run_test.go b/run_test.go index f30a418..8cb5032 100644 --- a/run_test.go +++ b/run_test.go @@ -33,7 +33,7 @@ func TestPrintsStepDefinitions(t *testing.T) { s.printStepDefinitions(w) out := buf.String() - ref := `github.com/DATA-DOG/godog.okStep` + ref := `okStep` for i, def := range strings.Split(strings.TrimSpace(out), "\n") { if idx := strings.Index(def, steps[i]); idx == -1 { t.Fatalf(`step "%s" was not found in output`, steps[i]) diff --git a/stepdef.go b/stepdef.go index 1241b55..952c954 100644 --- a/stepdef.go +++ b/stepdef.go @@ -2,6 +2,7 @@ package godog import ( "fmt" + "os" "path/filepath" "reflect" "regexp" @@ -68,6 +69,12 @@ func (sd *StepDef) definitionID() string { fn = strings.Trim(fn, "_.") } + if pkg := os.Getenv("GODOG_TESTED_PACKAGE"); len(pkg) > 0 { + fn = strings.Replace(fn, pkg, "", 1) + fn = strings.TrimLeft(fn, ".") + fn = strings.Replace(fn, "..", ".", -1) + } + return fmt.Sprintf("%s:%d -> %s", filepath.Base(file), line, fn) }