Skip to content

Commit

Permalink
closes #96
Browse files Browse the repository at this point in the history
  • Loading branch information
l3pp4rd committed Aug 31, 2017
1 parent 0b4523c commit 4dc98b0
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 5 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
1 change: 1 addition & 0 deletions builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -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}}
Expand Down
2 changes: 1 addition & 1 deletion examples/api/version.feature
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@ Feature: get version
And the response should match json:
"""
{
"version": "v0.7.2"
"version": "v0.7.4"
}
"""
5 changes: 3 additions & 2 deletions fmt_progress_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion godog.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
16 changes: 16 additions & 0 deletions run.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"fmt"
"io"
"os"
"path/filepath"
"runtime"
"strconv"
"strings"

Expand Down Expand Up @@ -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 {
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand Down
7 changes: 7 additions & 0 deletions stepdef.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package godog

import (
"fmt"
"os"
"path/filepath"
"reflect"
"regexp"
Expand Down Expand Up @@ -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)
}

Expand Down

0 comments on commit 4dc98b0

Please sign in to comment.