closes #96
Этот коммит содержится в:
родитель
0b4523c009
коммит
4dc98b0e2b
8 изменённых файлов: 39 добавлений и 5 удалений
|
@ -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
|
||||
|
|
|
@ -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}}
|
||||
|
|
|
@ -20,6 +20,6 @@ Feature: get version
|
|||
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)
|
||||
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)
|
||||
|
|
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
|
||||
|
||||
// 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"
|
||||
"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
|
||||
|
|
|
@ -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])
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
||||
|
|
Загрузка…
Создание таблицы
Сослаться в новой задаче