From 1467bfd672211a2804cb95c68e58e70a34ae06ac Mon Sep 17 00:00:00 2001 From: gedi Date: Wed, 25 May 2016 21:49:08 +0300 Subject: [PATCH] pass in suite name - tested package name --- builder.go | 2 +- fmt.go | 4 ++-- fmt_events.go | 18 +++++++++--------- fmt_junit.go | 4 ++-- fmt_pretty.go | 2 +- fmt_progress.go | 2 +- fmt_test.go | 2 +- run.go | 8 ++++---- suite_test.go | 4 ++-- 9 files changed, 23 insertions(+), 23 deletions(-) diff --git a/builder.go b/builder.go index 70a5b1a..53a367a 100644 --- a/builder.go +++ b/builder.go @@ -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}} diff --git a/fmt.go b/fmt.go index 2696c75..d18cee3 100644 --- a/fmt.go +++ b/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 diff --git a/fmt_events.go b/fmt_events.go index 41e7d88..063557b 100644 --- a/fmt_events.go +++ b/fmt_events.go @@ -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, }) diff --git a/fmt_junit.go b/fmt_junit.go index d56fafe..08a10b4 100644 --- a/fmt_junit.go +++ b/fmt_junit.go @@ -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, diff --git a/fmt_pretty.go b/fmt_pretty.go index c27ce1e..5a25098 100644 --- a/fmt_pretty.go +++ b/fmt_pretty.go @@ -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(), diff --git a/fmt_progress.go b/fmt_progress.go index daa5de2..dab45cb 100644 --- a/fmt_progress.go +++ b/fmt_progress.go @@ -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(), diff --git a/fmt_test.go b/fmt_test.go index 2614dcc..0458f5c 100644 --- a/fmt_test.go +++ b/fmt_test.go @@ -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(), diff --git a/run.go b/run.go index 3a1a9e5..c5587a4 100644 --- a/run.go +++ b/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) } diff --git a/suite_test.go b/suite_test.go index b493e87..4907516 100644 --- a/suite_test.go +++ b/suite_test.go @@ -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