resets time to zero for all godog tests
Этот коммит содержится в:
родитель
d3cf314381
коммит
ef794d57ca
9 изменённых файлов: 46 добавлений и 26 удалений
2
fmt.go
2
fmt.go
|
@ -305,7 +305,7 @@ func (f *basefmt) Summary() {
|
||||||
scenarios = append(scenarios, green(fmt.Sprintf("%d passed", passed)))
|
scenarios = append(scenarios, green(fmt.Sprintf("%d passed", passed)))
|
||||||
}
|
}
|
||||||
scenarios = append(scenarios, parts...)
|
scenarios = append(scenarios, parts...)
|
||||||
elapsed := time.Since(f.started)
|
elapsed := timeNowFunc().Sub(f.started)
|
||||||
|
|
||||||
fmt.Fprintln(f.out, "")
|
fmt.Fprintln(f.out, "")
|
||||||
if total == 0 {
|
if total == 0 {
|
||||||
|
|
|
@ -29,7 +29,7 @@ func init() {
|
||||||
func cucumberFunc(suite string, out io.Writer) Formatter {
|
func cucumberFunc(suite string, out io.Writer) Formatter {
|
||||||
formatter := &cukefmt{
|
formatter := &cukefmt{
|
||||||
basefmt: basefmt{
|
basefmt: basefmt{
|
||||||
started: time.Now(),
|
started: timeNowFunc(),
|
||||||
indent: 2,
|
indent: 2,
|
||||||
out: out,
|
out: out,
|
||||||
},
|
},
|
||||||
|
@ -252,7 +252,7 @@ func (f *cukefmt) step(res *stepResult) {
|
||||||
// determine if test case has finished
|
// determine if test case has finished
|
||||||
switch t := f.owner.(type) {
|
switch t := f.owner.(type) {
|
||||||
case *gherkin.TableRow:
|
case *gherkin.TableRow:
|
||||||
d := int(time.Since(f.startTime).Nanoseconds())
|
d := int(timeNowFunc().Sub(f.startTime).Nanoseconds())
|
||||||
f.curStep.Result.Duration = &d
|
f.curStep.Result.Duration = &d
|
||||||
f.curStep.Line = t.Location.Line
|
f.curStep.Line = t.Location.Line
|
||||||
f.curStep.Result.Status = res.typ.String()
|
f.curStep.Result.Status = res.typ.String()
|
||||||
|
@ -260,7 +260,7 @@ func (f *cukefmt) step(res *stepResult) {
|
||||||
f.curStep.Result.Error = res.err.Error()
|
f.curStep.Result.Error = res.err.Error()
|
||||||
}
|
}
|
||||||
case *gherkin.Scenario:
|
case *gherkin.Scenario:
|
||||||
d := int(time.Since(f.startTime).Nanoseconds())
|
d := int(timeNowFunc().Sub(f.startTime).Nanoseconds())
|
||||||
f.curStep.Result.Duration = &d
|
f.curStep.Result.Duration = &d
|
||||||
f.curStep.Result.Status = res.typ.String()
|
f.curStep.Result.Status = res.typ.String()
|
||||||
if res.err != nil {
|
if res.err != nil {
|
||||||
|
@ -271,7 +271,7 @@ func (f *cukefmt) step(res *stepResult) {
|
||||||
|
|
||||||
func (f *cukefmt) Defined(step *gherkin.Step, def *StepDef) {
|
func (f *cukefmt) Defined(step *gherkin.Step, def *StepDef) {
|
||||||
|
|
||||||
f.startTime = time.Now() // start timing the step
|
f.startTime = timeNowFunc() // start timing the step
|
||||||
f.curElement.Steps = append(f.curElement.Steps, cukeStep{})
|
f.curElement.Steps = append(f.curElement.Steps, cukeStep{})
|
||||||
f.curStep = &f.curElement.Steps[len(f.curElement.Steps)-1]
|
f.curStep = &f.curElement.Steps[len(f.curElement.Steps)-1]
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,6 @@ import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/DATA-DOG/godog/gherkin"
|
"github.com/DATA-DOG/godog/gherkin"
|
||||||
)
|
)
|
||||||
|
@ -19,7 +18,7 @@ func init() {
|
||||||
func eventsFunc(suite string, out io.Writer) Formatter {
|
func eventsFunc(suite string, out io.Writer) Formatter {
|
||||||
formatter := &events{
|
formatter := &events{
|
||||||
basefmt: basefmt{
|
basefmt: basefmt{
|
||||||
started: time.Now(),
|
started: timeNowFunc(),
|
||||||
indent: 2,
|
indent: 2,
|
||||||
out: out,
|
out: out,
|
||||||
},
|
},
|
||||||
|
@ -33,7 +32,7 @@ func eventsFunc(suite string, out io.Writer) Formatter {
|
||||||
}{
|
}{
|
||||||
"TestRunStarted",
|
"TestRunStarted",
|
||||||
spec,
|
spec,
|
||||||
time.Now().UnixNano() / nanoSec,
|
timeNowFunc().UnixNano() / nanoSec,
|
||||||
suite,
|
suite,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -87,7 +86,7 @@ func (f *events) Node(n interface{}) {
|
||||||
}{
|
}{
|
||||||
"TestCaseStarted",
|
"TestCaseStarted",
|
||||||
id,
|
id,
|
||||||
time.Now().UnixNano() / nanoSec,
|
timeNowFunc().UnixNano() / nanoSec,
|
||||||
})
|
})
|
||||||
|
|
||||||
if undefined {
|
if undefined {
|
||||||
|
@ -101,7 +100,7 @@ func (f *events) Node(n interface{}) {
|
||||||
}{
|
}{
|
||||||
"TestCaseFinished",
|
"TestCaseFinished",
|
||||||
id,
|
id,
|
||||||
time.Now().UnixNano() / nanoSec,
|
timeNowFunc().UnixNano() / nanoSec,
|
||||||
"undefined",
|
"undefined",
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -148,7 +147,7 @@ func (f *events) Summary() {
|
||||||
}{
|
}{
|
||||||
"TestRunFinished",
|
"TestRunFinished",
|
||||||
status.String(),
|
status.String(),
|
||||||
time.Now().UnixNano() / nanoSec,
|
timeNowFunc().UnixNano() / nanoSec,
|
||||||
snips,
|
snips,
|
||||||
"", // @TODO not sure that could be correctly implemented
|
"", // @TODO not sure that could be correctly implemented
|
||||||
})
|
})
|
||||||
|
@ -168,7 +167,7 @@ func (f *events) step(res *stepResult) {
|
||||||
}{
|
}{
|
||||||
"TestStepFinished",
|
"TestStepFinished",
|
||||||
fmt.Sprintf("%s:%d", f.path, res.step.Location.Line),
|
fmt.Sprintf("%s:%d", f.path, res.step.Location.Line),
|
||||||
time.Now().UnixNano() / nanoSec,
|
timeNowFunc().UnixNano() / nanoSec,
|
||||||
res.typ.String(),
|
res.typ.String(),
|
||||||
errMsg,
|
errMsg,
|
||||||
})
|
})
|
||||||
|
@ -194,7 +193,7 @@ func (f *events) step(res *stepResult) {
|
||||||
}{
|
}{
|
||||||
"TestCaseFinished",
|
"TestCaseFinished",
|
||||||
fmt.Sprintf("%s:%d", f.path, line),
|
fmt.Sprintf("%s:%d", f.path, line),
|
||||||
time.Now().UnixNano() / nanoSec,
|
timeNowFunc().UnixNano() / nanoSec,
|
||||||
f.stat.String(),
|
f.stat.String(),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -236,7 +235,7 @@ func (f *events) Defined(step *gherkin.Step, def *StepDef) {
|
||||||
}{
|
}{
|
||||||
"TestStepStarted",
|
"TestStepStarted",
|
||||||
fmt.Sprintf("%s:%d", f.path, step.Location.Line),
|
fmt.Sprintf("%s:%d", f.path, step.Location.Line),
|
||||||
time.Now().UnixNano() / nanoSec,
|
timeNowFunc().UnixNano() / nanoSec,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
12
fmt_junit.go
12
fmt_junit.go
|
@ -21,7 +21,7 @@ func junitFunc(suite string, out io.Writer) Formatter {
|
||||||
TestSuites: make([]*junitTestSuite, 0),
|
TestSuites: make([]*junitTestSuite, 0),
|
||||||
},
|
},
|
||||||
out: out,
|
out: out,
|
||||||
started: time.Now(),
|
started: timeNowFunc(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -45,9 +45,9 @@ func (j *junitFormatter) Feature(feature *gherkin.Feature, path string, c []byte
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(j.suite.TestSuites) > 0 {
|
if len(j.suite.TestSuites) > 0 {
|
||||||
j.current().Time = time.Since(j.featStarted).String()
|
j.current().Time = timeNowFunc().Sub(j.featStarted).String()
|
||||||
}
|
}
|
||||||
j.featStarted = time.Now()
|
j.featStarted = timeNowFunc()
|
||||||
j.suite.TestSuites = append(j.suite.TestSuites, testSuite)
|
j.suite.TestSuites = append(j.suite.TestSuites, testSuite)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -79,9 +79,9 @@ func (j *junitFormatter) Node(node interface{}) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if len(suite.TestCases) > 0 {
|
if len(suite.TestCases) > 0 {
|
||||||
suite.current().Time = time.Since(j.caseStarted).String()
|
suite.current().Time = timeNowFunc().Sub(j.caseStarted).String()
|
||||||
}
|
}
|
||||||
j.caseStarted = time.Now()
|
j.caseStarted = timeNowFunc()
|
||||||
suite.TestCases = append(suite.TestCases, tcase)
|
suite.TestCases = append(suite.TestCases, tcase)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -134,7 +134,7 @@ func (j *junitFormatter) Pending(step *gherkin.Step, match *StepDef) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (j *junitFormatter) Summary() {
|
func (j *junitFormatter) Summary() {
|
||||||
j.suite.Time = time.Since(j.started).String()
|
j.suite.Time = timeNowFunc().Sub(j.started).String()
|
||||||
io.WriteString(j.out, xml.Header)
|
io.WriteString(j.out, xml.Header)
|
||||||
|
|
||||||
enc := xml.NewEncoder(j.out)
|
enc := xml.NewEncoder(j.out)
|
||||||
|
|
|
@ -6,7 +6,6 @@ import (
|
||||||
"math"
|
"math"
|
||||||
"regexp"
|
"regexp"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
|
||||||
"unicode/utf8"
|
"unicode/utf8"
|
||||||
|
|
||||||
"github.com/DATA-DOG/godog/colors"
|
"github.com/DATA-DOG/godog/colors"
|
||||||
|
@ -20,7 +19,7 @@ func init() {
|
||||||
func prettyFunc(suite string, out io.Writer) Formatter {
|
func prettyFunc(suite string, out io.Writer) Formatter {
|
||||||
return &pretty{
|
return &pretty{
|
||||||
basefmt: basefmt{
|
basefmt: basefmt{
|
||||||
started: time.Now(),
|
started: timeNowFunc(),
|
||||||
indent: 2,
|
indent: 2,
|
||||||
out: out,
|
out: out,
|
||||||
},
|
},
|
||||||
|
|
|
@ -5,7 +5,6 @@ import (
|
||||||
"io"
|
"io"
|
||||||
"math"
|
"math"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/DATA-DOG/godog/gherkin"
|
"github.com/DATA-DOG/godog/gherkin"
|
||||||
)
|
)
|
||||||
|
@ -17,7 +16,7 @@ func init() {
|
||||||
func progressFunc(suite string, out io.Writer) Formatter {
|
func progressFunc(suite string, out io.Writer) Formatter {
|
||||||
return &progress{
|
return &progress{
|
||||||
basefmt: basefmt{
|
basefmt: basefmt{
|
||||||
started: time.Now(),
|
started: timeNowFunc(),
|
||||||
indent: 2,
|
indent: 2,
|
||||||
out: out,
|
out: out,
|
||||||
},
|
},
|
||||||
|
|
|
@ -2,7 +2,6 @@ package godog
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"io"
|
"io"
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/DATA-DOG/godog/gherkin"
|
"github.com/DATA-DOG/godog/gherkin"
|
||||||
)
|
)
|
||||||
|
@ -15,7 +14,7 @@ type testFormatter struct {
|
||||||
func testFormatterFunc(suite string, out io.Writer) Formatter {
|
func testFormatterFunc(suite string, out io.Writer) Formatter {
|
||||||
return &testFormatter{
|
return &testFormatter{
|
||||||
basefmt: basefmt{
|
basefmt: basefmt{
|
||||||
started: time.Now(),
|
started: timeNowFunc(),
|
||||||
indent: 2,
|
indent: 2,
|
||||||
out: out,
|
out: out,
|
||||||
},
|
},
|
||||||
|
|
5
utils.go
5
utils.go
|
@ -4,6 +4,7 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/DATA-DOG/godog/colors"
|
"github.com/DATA-DOG/godog/colors"
|
||||||
)
|
)
|
||||||
|
@ -33,3 +34,7 @@ func fatal(err error) {
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var timeNowFunc = func() time.Time {
|
||||||
|
return time.Now()
|
||||||
|
}
|
||||||
|
|
19
utils_test.go
Обычный файл
19
utils_test.go
Обычный файл
|
@ -0,0 +1,19 @@
|
||||||
|
package godog
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
timeNowFunc = func() time.Time {
|
||||||
|
return time.Time{}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestTimeNowFunc(t *testing.T) {
|
||||||
|
now := timeNowFunc()
|
||||||
|
if !now.IsZero() {
|
||||||
|
t.Fatalf("expected zeroed time, but got: %s", now.Format(time.RFC3339))
|
||||||
|
}
|
||||||
|
}
|
Загрузка…
Создание таблицы
Сослаться в новой задаче