allow run options to configure output writer
Этот коммит содержится в:
родитель
115923c97f
коммит
e2069934b3
5 изменённых файлов: 46 добавлений и 11 удалений
|
@ -20,6 +20,6 @@ Feature: get version
|
|||
And the response should match json:
|
||||
"""
|
||||
{
|
||||
"version": "v0.5.4"
|
||||
"version": "v0.6.0"
|
||||
}
|
||||
"""
|
||||
|
|
|
@ -137,7 +137,7 @@ func (j *junitFormatter) Summary() {
|
|||
j.suite.Time = time.Since(j.started).String()
|
||||
io.WriteString(j.out, xml.Header)
|
||||
|
||||
enc := xml.NewEncoder(os.Stdout)
|
||||
enc := xml.NewEncoder(j.out)
|
||||
enc.Indent("", s(2))
|
||||
if err := enc.Encode(j.suite); err != nil {
|
||||
fmt.Fprintln(os.Stderr, "failed to write junit xml:", err)
|
||||
|
|
2
godog.go
2
godog.go
|
@ -42,4 +42,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.5.4"
|
||||
const Version = "v0.6.0"
|
||||
|
|
31
options.go
31
options.go
|
@ -1,5 +1,7 @@
|
|||
package godog
|
||||
|
||||
import "io"
|
||||
|
||||
// Options are suite run options
|
||||
// flags are mapped to these options.
|
||||
//
|
||||
|
@ -8,11 +10,28 @@ package godog
|
|||
//
|
||||
// See the flags for more details
|
||||
type Options struct {
|
||||
// Print step definitions found and exit
|
||||
ShowStepDefinitions bool
|
||||
StopOnFailure bool
|
||||
NoColors bool
|
||||
Tags string
|
||||
Format string
|
||||
Concurrency int
|
||||
Paths []string
|
||||
|
||||
// Stops on the first failure
|
||||
StopOnFailure bool
|
||||
|
||||
// Forces ansi color stripping
|
||||
NoColors bool
|
||||
|
||||
// Various filters for scenarios parsed
|
||||
// from feature files
|
||||
Tags string
|
||||
|
||||
// The formatter name
|
||||
Format string
|
||||
|
||||
// Concurrency rate, not all formatters accepts this
|
||||
Concurrency int
|
||||
|
||||
// All feature file paths
|
||||
Paths []string
|
||||
|
||||
// Where it should print formatter output
|
||||
Output io.Writer
|
||||
}
|
||||
|
|
20
run.go
20
run.go
|
@ -2,7 +2,10 @@ package godog
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
|
||||
"github.com/DATA-DOG/godog/colors"
|
||||
)
|
||||
|
||||
type initializer func(*Suite)
|
||||
|
@ -69,6 +72,17 @@ func (r *runner) run() (failed bool) {
|
|||
// godog in for example TestMain function together
|
||||
// with go tests
|
||||
func RunWithOptions(suite string, contextInitializer func(suite *Suite), opt Options) int {
|
||||
var output io.Writer = os.Stdout
|
||||
if nil != opt.Output {
|
||||
output = opt.Output
|
||||
}
|
||||
|
||||
if opt.NoColors {
|
||||
output = colors.Uncolored(output)
|
||||
} else {
|
||||
output = colors.Colored(output)
|
||||
}
|
||||
|
||||
if opt.ShowStepDefinitions {
|
||||
s := &Suite{}
|
||||
contextInitializer(s)
|
||||
|
@ -93,7 +107,7 @@ func RunWithOptions(suite string, contextInitializer func(suite *Suite), opt Opt
|
|||
fatal(err)
|
||||
|
||||
r := runner{
|
||||
fmt: formatter(suite, os.Stdout),
|
||||
fmt: formatter(suite, output),
|
||||
initializer: contextInitializer,
|
||||
features: features,
|
||||
stopOnFailure: opt.StopOnFailure,
|
||||
|
@ -105,7 +119,7 @@ func RunWithOptions(suite string, contextInitializer func(suite *Suite), opt Opt
|
|||
} else {
|
||||
failed = r.run()
|
||||
}
|
||||
if failed && format != "events" {
|
||||
if failed && opt.Format != "events" {
|
||||
return 1
|
||||
}
|
||||
return 0
|
||||
|
@ -126,6 +140,7 @@ func RunWithOptions(suite string, contextInitializer func(suite *Suite), opt Opt
|
|||
func Run(suite string, contextInitializer func(suite *Suite)) int {
|
||||
var opt Options
|
||||
flagSet := FlagSet(
|
||||
colors.Colored(os.Stdout),
|
||||
&opt.Format,
|
||||
&opt.Tags,
|
||||
&opt.ShowStepDefinitions,
|
||||
|
@ -135,6 +150,7 @@ func Run(suite string, contextInitializer func(suite *Suite)) int {
|
|||
)
|
||||
err := flagSet.Parse(os.Args[1:])
|
||||
fatal(err)
|
||||
|
||||
opt.Paths = flagSet.Args()
|
||||
|
||||
return RunWithOptions(suite, contextInitializer, opt)
|
||||
|
|
Загрузка…
Создание таблицы
Сослаться в новой задаче