From 5f49dad1c4a2e31783f7c67dde7fcdda9cb7a595 Mon Sep 17 00:00:00 2001 From: Eloy Coto Date: Fri, 13 Oct 2017 13:15:44 +0200 Subject: [PATCH] Added Duration on GinkgoTestDescription Signed-off-by: Eloy Coto --- ginkgo_dsl.go | 4 +++- internal/spec/spec.go | 7 ++++--- internal/suite/suite_test.go | 1 + 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/ginkgo_dsl.go b/ginkgo_dsl.go index 8befd35ad..a6143a0f6 100644 --- a/ginkgo_dsl.go +++ b/ginkgo_dsl.go @@ -149,7 +149,8 @@ type GinkgoTestDescription struct { FileName string LineNumber int - Failed bool + Failed bool + Duration time.Duration } //CurrentGinkgoTestDescripton returns information about the current running test. @@ -169,6 +170,7 @@ func CurrentGinkgoTestDescription() GinkgoTestDescription { FileName: subjectCodeLocation.FileName, LineNumber: subjectCodeLocation.LineNumber, Failed: summary.HasFailureState(), + Duration: summary.RunTime, } } diff --git a/internal/spec/spec.go b/internal/spec/spec.go index d32dec699..96b779036 100644 --- a/internal/spec/spec.go +++ b/internal/spec/spec.go @@ -19,6 +19,7 @@ type Spec struct { state types.SpecState runTime time.Duration + startTime time.Time failure types.SpecFailure previousFailures bool } @@ -97,7 +98,7 @@ func (spec *Spec) Summary(suiteID string) *types.SpecSummary { ComponentTexts: componentTexts, ComponentCodeLocations: componentCodeLocations, State: spec.state, - RunTime: spec.runTime, + RunTime: time.Since(spec.startTime), Failure: spec.failure, Measurements: spec.measurementsReport(), SuiteID: suiteID, @@ -118,9 +119,9 @@ func (spec *Spec) Run(writer io.Writer) { spec.previousFailures = true } - startTime := time.Now() + spec.startTime = time.Now() defer func() { - spec.runTime = time.Since(startTime) + spec.runTime = time.Since(spec.startTime) }() for sample := 0; sample < spec.subject.Samples(); sample++ { diff --git a/internal/suite/suite_test.go b/internal/suite/suite_test.go index b7bcdbd2e..24f70cae2 100644 --- a/internal/suite/suite_test.go +++ b/internal/suite/suite_test.go @@ -121,6 +121,7 @@ var _ = Describe("Suite", func() { Ω(description.LineNumber).Should(BeNumerically(">", 50)) Ω(description.LineNumber).Should(BeNumerically("<", 150)) Ω(description.Failed).Should(BeFalse()) + Ω(description.Duration).Should(BeNumerically(">", 0)) }) Measure("should run measurements", func(b Benchmarker) {