From 6f6ffc597ab584c9564a25ebf70b9423cbc99446 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fredrik=20L=C3=B6nnblad?= Date: Mon, 20 Jan 2020 14:24:18 -0300 Subject: [PATCH] Fixed an issue when executing empty Features or Scenarios --- fmt.go | 5 +++-- suite.go | 24 ++++++++++++++++++++++++ 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/fmt.go b/fmt.go index ea1b9ea..12167a8 100644 --- a/fmt.go +++ b/fmt.go @@ -242,7 +242,8 @@ func (f *basefmt) Node(n interface{}) { case *gherkin.Scenario: f.owner = t feature := f.features[len(f.features)-1] - feature.Scenarios = append(feature.Scenarios, &scenario{Name: t.Name}) + feature.time = timeNowFunc() + feature.Scenarios = append(feature.Scenarios, &scenario{Name: t.Name, time: feature.time}) case *gherkin.ScenarioOutline: feature := f.features[len(f.features)-1] feature.Scenarios = append(feature.Scenarios, &scenario{OutlineName: t.Name}) @@ -252,7 +253,7 @@ func (f *basefmt) Node(n interface{}) { feature := f.features[len(f.features)-1] lastExample := feature.Scenarios[len(feature.Scenarios)-1] - newExample := scenario{OutlineName: lastExample.OutlineName, ExampleNo: lastExample.ExampleNo + 1} + newExample := scenario{OutlineName: lastExample.OutlineName, ExampleNo: lastExample.ExampleNo + 1, time: timeNowFunc()} newExample.Name = fmt.Sprintf("%s #%d", newExample.OutlineName, newExample.ExampleNo) const firstExample = 1 diff --git a/suite.go b/suite.go index 4a22d19..db7761c 100644 --- a/suite.go +++ b/suite.go @@ -26,16 +26,28 @@ type feature struct { Scenarios []*scenario + time time.Time Content []byte `json:"-"` Path string `json:"path"` order int } func (f feature) startedAt() time.Time { +<<<<<<< Updated upstream return f.Scenarios[0].startedAt() } func (f feature) finishedAt() time.Time { +======= + return f.time +} + +func (f feature) finishedAt() time.Time { + if len(f.Scenarios) == 0 { + return f.startedAt() + } + +>>>>>>> Stashed changes return f.Scenarios[len(f.Scenarios)-1].finishedAt() } @@ -48,14 +60,26 @@ type scenario struct { Name string OutlineName string ExampleNo int + time time.Time Steps []*stepResult } func (s scenario) startedAt() time.Time { +<<<<<<< Updated upstream return s.Steps[0].time } func (s scenario) finishedAt() time.Time { +======= + return s.time +} + +func (s scenario) finishedAt() time.Time { + if len(s.Steps) == 0 { + return s.startedAt() + } + +>>>>>>> Stashed changes return s.Steps[len(s.Steps)-1].time }