closes #96
Этот коммит содержится в:
родитель
0b4523c009
коммит
4dc98b0e2b
8 изменённых файлов: 39 добавлений и 5 удалений
|
@ -1,5 +1,14 @@
|
||||||
# Change LOG
|
# 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**
|
**2017-05-04**
|
||||||
- added **--strict** option in order to fail suite when there are pending
|
- added **--strict** option in order to fail suite when there are pending
|
||||||
or undefined steps. By default, suite passes and treats pending or
|
or undefined steps. By default, suite passes and treats pending or
|
||||||
|
|
|
@ -35,6 +35,7 @@ import (
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
status := godog.Run("{{ .Name }}", func (suite *godog.Suite) {
|
status := godog.Run("{{ .Name }}", func (suite *godog.Suite) {
|
||||||
|
os.Setenv("GODOG_TESTED_PACKAGE", "{{.ImportPath}}")
|
||||||
{{range .Contexts}}
|
{{range .Contexts}}
|
||||||
_test.{{ . }}(suite)
|
_test.{{ . }}(suite)
|
||||||
{{end}}
|
{{end}}
|
||||||
|
|
|
@ -20,6 +20,6 @@ Feature: get version
|
||||||
And the response should match json:
|
And the response should match json:
|
||||||
"""
|
"""
|
||||||
{
|
{
|
||||||
"version": "v0.7.2"
|
"version": "v0.7.4"
|
||||||
}
|
}
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -184,13 +184,14 @@ Error: sub2: sub-sub: errored
|
||||||
|
|
||||||
1 scenarios (1 failed)
|
1 scenarios (1 failed)
|
||||||
2 steps (1 passed, 1 failed)
|
2 steps (1 passed, 1 failed)
|
||||||
0s
|
%s
|
||||||
|
|
||||||
Randomized with seed: %s
|
Randomized with seed: %s
|
||||||
`
|
`
|
||||||
|
|
||||||
expected = trimAllLines(expected)
|
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())
|
actual := trimAllLines(buf.String())
|
||||||
|
|
||||||
shouldMatchOutput(expected, actual, t)
|
shouldMatchOutput(expected, actual, t)
|
||||||
|
|
2
godog.go
2
godog.go
|
@ -39,4 +39,4 @@ Godog was inspired by Behat and Cucumber the above description is taken from it'
|
||||||
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.7.3"
|
const Version = "v0.7.4"
|
||||||
|
|
16
run.go
16
run.go
|
@ -4,6 +4,8 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"os"
|
"os"
|
||||||
|
"path/filepath"
|
||||||
|
"runtime"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"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
|
// store chosen seed in environment, so it could be seen in formatter summary report
|
||||||
os.Setenv("GODOG_SEED", strconv.FormatInt(r.randomSeed, 10))
|
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
|
var failed bool
|
||||||
if opt.Concurrency > 1 {
|
if opt.Concurrency > 1 {
|
||||||
|
@ -167,6 +172,17 @@ func RunWithOptions(suite string, contextInitializer func(suite *Suite), opt Opt
|
||||||
return exitSuccess
|
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.
|
// Run creates and runs the feature suite.
|
||||||
// Reads all configuration options from flags.
|
// Reads all configuration options from flags.
|
||||||
// uses contextInitializer to register contexts
|
// uses contextInitializer to register contexts
|
||||||
|
|
|
@ -33,7 +33,7 @@ func TestPrintsStepDefinitions(t *testing.T) {
|
||||||
s.printStepDefinitions(w)
|
s.printStepDefinitions(w)
|
||||||
|
|
||||||
out := buf.String()
|
out := buf.String()
|
||||||
ref := `github.com/DATA-DOG/godog.okStep`
|
ref := `okStep`
|
||||||
for i, def := range strings.Split(strings.TrimSpace(out), "\n") {
|
for i, def := range strings.Split(strings.TrimSpace(out), "\n") {
|
||||||
if idx := strings.Index(def, steps[i]); idx == -1 {
|
if idx := strings.Index(def, steps[i]); idx == -1 {
|
||||||
t.Fatalf(`step "%s" was not found in output`, steps[i])
|
t.Fatalf(`step "%s" was not found in output`, steps[i])
|
||||||
|
|
|
@ -2,6 +2,7 @@ package godog
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"reflect"
|
"reflect"
|
||||||
"regexp"
|
"regexp"
|
||||||
|
@ -68,6 +69,12 @@ func (sd *StepDef) definitionID() string {
|
||||||
fn = strings.Trim(fn, "_.")
|
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)
|
return fmt.Sprintf("%s:%d -> %s", filepath.Base(file), line, fn)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Загрузка…
Создание таблицы
Сослаться в новой задаче