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