From 0c1d529e06130d58680072eb8384360c97c256e8 Mon Sep 17 00:00:00 2001 From: gedi Date: Fri, 12 Jun 2015 17:17:33 +0300 Subject: [PATCH] parse features for suite, add doc for public methods --- colors.go | 4 ++-- config.go | 7 +++++++ suite.go | 27 ++++++++++++++++++++------- 3 files changed, 29 insertions(+), 9 deletions(-) diff --git a/colors.go b/colors.go index b98d0a9..42ba30b 100644 --- a/colors.go +++ b/colors.go @@ -15,6 +15,6 @@ const ( white ) -func cl(s string, c color) string { - return fmt.Sprintf("\033[%dm%s\033[0m", c, s) +func cl(s interface{}, c color) string { + return fmt.Sprintf("\033[%dm%v\033[0m", c, s) } diff --git a/config.go b/config.go index d8d6442..1359004 100644 --- a/config.go +++ b/config.go @@ -52,3 +52,10 @@ func (c config) features() (lst []*gherkin.Feature, err error) { return err }) } + +func fatal(err error) { + if err != nil { + fmt.Println(err) + os.Exit(1) + } +} diff --git a/suite.go b/suite.go index 79f3d55..0790671 100644 --- a/suite.go +++ b/suite.go @@ -2,19 +2,30 @@ package godog import ( "flag" - "log" + "fmt" "regexp" + + "github.com/DATA-DOG/godog/gherkin" ) +// Suite is an interface which allows various contexts +// to register step definitions and event handlers type Suite interface { Step(exp *regexp.Regexp, h StepHandler) } type suite struct { - steps map[*regexp.Regexp]StepHandler + steps map[*regexp.Regexp]StepHandler + features []*gherkin.Feature } +// New initializes a suite which supports the Suite +// interface. The instance is passed around to all +// context initialization functions from *_test.go files func New() *suite { + if !flag.Parsed() { + flag.Parse() + } return &suite{ steps: make(map[*regexp.Regexp]StepHandler), } @@ -24,10 +35,12 @@ func (s *suite) Step(exp *regexp.Regexp, h StepHandler) { s.steps[exp] = h } +// Run - runs a godog feature suite func (s *suite) Run() { - if !flag.Parsed() { - flag.Parse() - } - log.Println("running godoc, num registered steps:", len(s.steps), "color test:", cl("red", red)) - log.Println("will read features in path:", cl(cfg.featuresPath, yellow)) + var err error + s.features, err = cfg.features() + fatal(err) + + fmt.Println("running", cl("godog", cyan)+", num registered steps:", cl(len(s.steps), yellow)) + fmt.Println("have loaded", cl(len(s.features), yellow), "features from path:", cl(cfg.featuresPath, green)) }