pass in suite name - tested package name
Этот коммит содержится в:
родитель
c50c2dc368
коммит
1467bfd672
9 изменённых файлов: 23 добавлений и 23 удалений
|
@ -33,7 +33,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
status := godog.Run(func (suite *godog.Suite) {
|
status := godog.Run("{{ .Name }}", func (suite *godog.Suite) {
|
||||||
{{range .Contexts}}
|
{{range .Contexts}}
|
||||||
_test.{{ . }}(suite)
|
_test.{{ . }}(suite)
|
||||||
{{end}}
|
{{end}}
|
||||||
|
|
4
fmt.go
4
fmt.go
|
@ -98,8 +98,8 @@ type Formatter interface {
|
||||||
}
|
}
|
||||||
|
|
||||||
// FormatterFunc builds a formatter with given
|
// FormatterFunc builds a formatter with given
|
||||||
// io.Writer to record output.
|
// suite name and io.Writer to record output
|
||||||
type FormatterFunc func(io.Writer) Formatter
|
type FormatterFunc func(string, io.Writer) Formatter
|
||||||
|
|
||||||
type stepType int
|
type stepType int
|
||||||
|
|
||||||
|
|
|
@ -8,7 +8,7 @@ import (
|
||||||
"io"
|
"io"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"gopkg.in/cucumber/gherkin-go.v3"
|
"github.com/DATA-DOG/godog/gherkin"
|
||||||
)
|
)
|
||||||
|
|
||||||
const nanoSec = 1000000
|
const nanoSec = 1000000
|
||||||
|
@ -18,7 +18,7 @@ func init() {
|
||||||
Format("events", fmt.Sprintf("Produces JSON event stream, based on spec: %s.", spec), eventsFunc)
|
Format("events", fmt.Sprintf("Produces JSON event stream, based on spec: %s.", spec), eventsFunc)
|
||||||
}
|
}
|
||||||
|
|
||||||
func eventsFunc(out io.Writer) Formatter {
|
func eventsFunc(suite string, out io.Writer) Formatter {
|
||||||
data, err := json.Marshal(&struct {
|
data, err := json.Marshal(&struct {
|
||||||
Time int64
|
Time int64
|
||||||
Runner string
|
Runner string
|
||||||
|
@ -38,7 +38,7 @@ func eventsFunc(out io.Writer) Formatter {
|
||||||
out: out,
|
out: out,
|
||||||
},
|
},
|
||||||
runID: hex.EncodeToString(hasher.Sum(nil)),
|
runID: hex.EncodeToString(hasher.Sum(nil)),
|
||||||
suite: "main",
|
suite: suite,
|
||||||
}
|
}
|
||||||
|
|
||||||
formatter.event(&struct {
|
formatter.event(&struct {
|
||||||
|
@ -92,7 +92,7 @@ func (f *events) Node(n interface{}) {
|
||||||
}{
|
}{
|
||||||
"TestCaseStarted",
|
"TestCaseStarted",
|
||||||
f.runID,
|
f.runID,
|
||||||
"main",
|
f.suite,
|
||||||
fmt.Sprintf("%s:%d", f.path, t.Location.Line),
|
fmt.Sprintf("%s:%d", f.path, t.Location.Line),
|
||||||
time.Now().UnixNano() / nanoSec,
|
time.Now().UnixNano() / nanoSec,
|
||||||
})
|
})
|
||||||
|
@ -106,7 +106,7 @@ func (f *events) Node(n interface{}) {
|
||||||
}{
|
}{
|
||||||
"TestCaseStarted",
|
"TestCaseStarted",
|
||||||
f.runID,
|
f.runID,
|
||||||
"main",
|
f.suite,
|
||||||
fmt.Sprintf("%s:%d", f.path, t.Location.Line),
|
fmt.Sprintf("%s:%d", f.path, t.Location.Line),
|
||||||
time.Now().UnixNano() / nanoSec,
|
time.Now().UnixNano() / nanoSec,
|
||||||
})
|
})
|
||||||
|
@ -170,7 +170,7 @@ func (f *events) step(res *stepResult) {
|
||||||
}{
|
}{
|
||||||
"TestStepFinished",
|
"TestStepFinished",
|
||||||
f.runID,
|
f.runID,
|
||||||
"main",
|
f.suite,
|
||||||
fmt.Sprintf("%s:%d", f.path, res.step.Location.Line),
|
fmt.Sprintf("%s:%d", f.path, res.step.Location.Line),
|
||||||
time.Now().UnixNano() / nanoSec,
|
time.Now().UnixNano() / nanoSec,
|
||||||
res.typ.String(),
|
res.typ.String(),
|
||||||
|
@ -203,7 +203,7 @@ func (f *events) step(res *stepResult) {
|
||||||
}{
|
}{
|
||||||
"TestCaseFinished",
|
"TestCaseFinished",
|
||||||
f.runID,
|
f.runID,
|
||||||
"main",
|
f.suite,
|
||||||
fmt.Sprintf("%s:%d", f.path, line),
|
fmt.Sprintf("%s:%d", f.path, line),
|
||||||
time.Now().UnixNano() / nanoSec,
|
time.Now().UnixNano() / nanoSec,
|
||||||
f.stat.String(),
|
f.stat.String(),
|
||||||
|
@ -237,7 +237,7 @@ func (f *events) Defined(step *gherkin.Step, def *StepDef) {
|
||||||
}{
|
}{
|
||||||
"StepDefinitionFound",
|
"StepDefinitionFound",
|
||||||
f.runID,
|
f.runID,
|
||||||
"main",
|
f.suite,
|
||||||
fmt.Sprintf("%s:%d", f.path, step.Location.Line),
|
fmt.Sprintf("%s:%d", f.path, step.Location.Line),
|
||||||
def.definitionID(),
|
def.definitionID(),
|
||||||
args,
|
args,
|
||||||
|
@ -253,7 +253,7 @@ func (f *events) Defined(step *gherkin.Step, def *StepDef) {
|
||||||
}{
|
}{
|
||||||
"TestStepStarted",
|
"TestStepStarted",
|
||||||
f.runID,
|
f.runID,
|
||||||
"main",
|
f.suite,
|
||||||
fmt.Sprintf("%s:%d", f.path, step.Location.Line),
|
fmt.Sprintf("%s:%d", f.path, step.Location.Line),
|
||||||
time.Now().UnixNano() / nanoSec,
|
time.Now().UnixNano() / nanoSec,
|
||||||
})
|
})
|
||||||
|
|
|
@ -14,10 +14,10 @@ func init() {
|
||||||
Format("junit", "Prints junit compatible xml to stdout", junitFunc)
|
Format("junit", "Prints junit compatible xml to stdout", junitFunc)
|
||||||
}
|
}
|
||||||
|
|
||||||
func junitFunc(out io.Writer) Formatter {
|
func junitFunc(suite string, out io.Writer) Formatter {
|
||||||
return &junitFormatter{
|
return &junitFormatter{
|
||||||
suite: &junitPackageSuite{
|
suite: &junitPackageSuite{
|
||||||
Name: "main", // @TODO: it should extract package name
|
Name: suite,
|
||||||
TestSuites: make([]*junitTestSuite, 0),
|
TestSuites: make([]*junitTestSuite, 0),
|
||||||
},
|
},
|
||||||
out: out,
|
out: out,
|
||||||
|
|
|
@ -16,7 +16,7 @@ func init() {
|
||||||
Format("pretty", "Prints every feature with runtime statuses.", prettyFunc)
|
Format("pretty", "Prints every feature with runtime statuses.", prettyFunc)
|
||||||
}
|
}
|
||||||
|
|
||||||
func prettyFunc(out io.Writer) Formatter {
|
func prettyFunc(suite string, out io.Writer) Formatter {
|
||||||
return &pretty{
|
return &pretty{
|
||||||
basefmt: basefmt{
|
basefmt: basefmt{
|
||||||
started: time.Now(),
|
started: time.Now(),
|
||||||
|
|
|
@ -14,7 +14,7 @@ func init() {
|
||||||
Format("progress", "Prints a character per step.", progressFunc)
|
Format("progress", "Prints a character per step.", progressFunc)
|
||||||
}
|
}
|
||||||
|
|
||||||
func progressFunc(out io.Writer) Formatter {
|
func progressFunc(suite string, out io.Writer) Formatter {
|
||||||
return &progress{
|
return &progress{
|
||||||
basefmt: basefmt{
|
basefmt: basefmt{
|
||||||
started: time.Now(),
|
started: time.Now(),
|
||||||
|
|
|
@ -12,7 +12,7 @@ type testFormatter struct {
|
||||||
scenarios []interface{}
|
scenarios []interface{}
|
||||||
}
|
}
|
||||||
|
|
||||||
func testFormatterFunc(out io.Writer) Formatter {
|
func testFormatterFunc(suite string, out io.Writer) Formatter {
|
||||||
return &testFormatter{
|
return &testFormatter{
|
||||||
basefmt: basefmt{
|
basefmt: basefmt{
|
||||||
started: time.Now(),
|
started: time.Now(),
|
||||||
|
|
8
run.go
8
run.go
|
@ -68,7 +68,7 @@ func (r *runner) run() (failed bool) {
|
||||||
// This method is useful in case if you run
|
// This method is useful in case if you run
|
||||||
// godog in for example TestMain function together
|
// godog in for example TestMain function together
|
||||||
// with go tests
|
// with go tests
|
||||||
func RunWithOptions(contextInitializer func(suite *Suite), opt Options) int {
|
func RunWithOptions(suite string, contextInitializer func(suite *Suite), opt Options) int {
|
||||||
if opt.ShowStepDefinitions {
|
if opt.ShowStepDefinitions {
|
||||||
s := &Suite{}
|
s := &Suite{}
|
||||||
contextInitializer(s)
|
contextInitializer(s)
|
||||||
|
@ -93,7 +93,7 @@ func RunWithOptions(contextInitializer func(suite *Suite), opt Options) int {
|
||||||
fatal(err)
|
fatal(err)
|
||||||
|
|
||||||
r := runner{
|
r := runner{
|
||||||
fmt: formatter(os.Stdout),
|
fmt: formatter(suite, os.Stdout),
|
||||||
initializer: contextInitializer,
|
initializer: contextInitializer,
|
||||||
features: features,
|
features: features,
|
||||||
stopOnFailure: opt.StopOnFailure,
|
stopOnFailure: opt.StopOnFailure,
|
||||||
|
@ -123,7 +123,7 @@ func RunWithOptions(contextInitializer func(suite *Suite), opt Options) int {
|
||||||
//
|
//
|
||||||
// contextInitializer must be able to register
|
// contextInitializer must be able to register
|
||||||
// the step definitions and event handlers.
|
// the step definitions and event handlers.
|
||||||
func Run(contextInitializer func(suite *Suite)) int {
|
func Run(suite string, contextInitializer func(suite *Suite)) int {
|
||||||
var opt Options
|
var opt Options
|
||||||
flagSet := FlagSet(
|
flagSet := FlagSet(
|
||||||
&opt.Format,
|
&opt.Format,
|
||||||
|
@ -137,5 +137,5 @@ func Run(contextInitializer func(suite *Suite)) int {
|
||||||
fatal(err)
|
fatal(err)
|
||||||
opt.Paths = flagSet.Args()
|
opt.Paths = flagSet.Args()
|
||||||
|
|
||||||
return RunWithOptions(contextInitializer, opt)
|
return RunWithOptions(suite, contextInitializer, opt)
|
||||||
}
|
}
|
||||||
|
|
|
@ -79,7 +79,7 @@ func (s *suiteContext) iRunFeatureSuiteWithFormatter(name string) error {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
s.testedSuite.fmt = f(&s.out)
|
s.testedSuite.fmt = f("godog", &s.out)
|
||||||
if err := s.parseFeatures(); err != nil {
|
if err := s.parseFeatures(); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -284,7 +284,7 @@ func (s *suiteContext) iRunFeatureSuite() error {
|
||||||
if err := s.parseFeatures(); err != nil {
|
if err := s.parseFeatures(); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
s.testedSuite.fmt = testFormatterFunc(&s.out)
|
s.testedSuite.fmt = testFormatterFunc("godog", &s.out)
|
||||||
s.testedSuite.run()
|
s.testedSuite.run()
|
||||||
s.testedSuite.fmt.Summary()
|
s.testedSuite.fmt.Summary()
|
||||||
return nil
|
return nil
|
||||||
|
|
Загрузка…
Создание таблицы
Сослаться в новой задаче