Этот коммит содержится в:
gedi 2016-09-03 23:13:35 +03:00
родитель 1467bfd672
коммит 78cb180a3a
2 изменённых файлов: 7 добавлений и 54 удалений

Просмотреть файл

@ -1,8 +1,6 @@
package godog
import (
"crypto/sha1"
"encoding/hex"
"encoding/json"
"fmt"
"io"
@ -19,38 +17,24 @@ func init() {
}
func eventsFunc(suite string, out io.Writer) Formatter {
data, err := json.Marshal(&struct {
Time int64
Runner string
}{time.Now().UnixNano(), "godog"})
if err != nil {
panic("failed to marshal run id")
}
hasher := sha1.New()
hasher.Write(data)
formatter := &events{
basefmt: basefmt{
started: time.Now(),
indent: 2,
out: out,
},
runID: hex.EncodeToString(hasher.Sum(nil)),
suite: suite,
}
formatter.event(&struct {
Event string `json:"event"`
RunID string `json:"run_id"`
Version string `json:"version"`
Timestamp int64 `json:"timestamp"`
Suite string `json:"suite"`
}{
"TestRunStarted",
formatter.runID,
spec,
time.Now().UnixNano() / nanoSec,
suite,
})
return formatter
@ -59,9 +43,6 @@ func eventsFunc(suite string, out io.Writer) Formatter {
type events struct {
basefmt
runID string
suite string
// currently running feature path, to be part of id.
// this is sadly not passed by gherkin nodes.
// it restricts this formatter to run only in synchronous single
@ -85,28 +66,20 @@ func (f *events) Node(n interface{}) {
case *gherkin.Scenario:
f.event(&struct {
Event string `json:"event"`
RunID string `json:"run_id"`
Suite string `json:"suite"`
Location string `json:"location"`
Timestamp int64 `json:"timestamp"`
}{
"TestCaseStarted",
f.runID,
f.suite,
fmt.Sprintf("%s:%d", f.path, t.Location.Line),
time.Now().UnixNano() / nanoSec,
})
case *gherkin.TableRow:
f.event(&struct {
Event string `json:"event"`
RunID string `json:"run_id"`
Suite string `json:"suite"`
Location string `json:"location"`
Timestamp int64 `json:"timestamp"`
}{
"TestCaseStarted",
f.runID,
f.suite,
fmt.Sprintf("%s:%d", f.path, t.Location.Line),
time.Now().UnixNano() / nanoSec,
})
@ -118,12 +91,10 @@ func (f *events) Feature(ft *gherkin.Feature, p string, c []byte) {
f.path = p
f.event(&struct {
Event string `json:"event"`
RunID string `json:"run_id"`
Location string `json:"location"`
Source string `json:"source"`
}{
"TestSource",
f.runID,
fmt.Sprintf("%s:%d", p, ft.Location.Line),
string(c),
})
@ -143,12 +114,10 @@ func (f *events) Summary() {
}
f.event(&struct {
Event string `json:"event"`
RunID string `json:"run_id"`
Status string `json:"status"`
Timestamp int64 `json:"timestamp"`
}{
"TestRunFinished",
f.runID,
status.String(),
time.Now().UnixNano() / nanoSec,
})
@ -161,16 +130,12 @@ func (f *events) step(res *stepResult) {
}
f.event(&struct {
Event string `json:"event"`
RunID string `json:"run_id"`
Suite string `json:"suite"`
Location string `json:"location"`
Timestamp int64 `json:"timestamp"`
Status string `json:"status"`
Summary string `json:"summary,omitempty"`
}{
"TestStepFinished",
f.runID,
f.suite,
fmt.Sprintf("%s:%d", f.path, res.step.Location.Line),
time.Now().UnixNano() / nanoSec,
res.typ.String(),
@ -195,15 +160,11 @@ func (f *events) step(res *stepResult) {
if finished {
f.event(&struct {
Event string `json:"event"`
RunID string `json:"run_id"`
Suite string `json:"suite"`
Location string `json:"location"`
Timestamp int64 `json:"timestamp"`
Status string `json:"status"`
}{
"TestCaseFinished",
f.runID,
f.suite,
fmt.Sprintf("%s:%d", f.path, line),
time.Now().UnixNano() / nanoSec,
f.stat.String(),
@ -229,15 +190,11 @@ func (f *events) Defined(step *gherkin.Step, def *StepDef) {
f.event(&struct {
Event string `json:"event"`
RunID string `json:"run_id"`
Suite string `json:"suite"`
Location string `json:"location"`
DefID string `json:"definition_id"`
Args [][2]int `json:"arguments"`
}{
"StepDefinitionFound",
f.runID,
f.suite,
fmt.Sprintf("%s:%d", f.path, step.Location.Line),
def.definitionID(),
args,
@ -246,14 +203,10 @@ func (f *events) Defined(step *gherkin.Step, def *StepDef) {
f.event(&struct {
Event string `json:"event"`
RunID string `json:"run_id"`
Suite string `json:"suite"`
Location string `json:"location"`
Timestamp int64 `json:"timestamp"`
}{
"TestStepStarted",
f.runID,
f.suite,
fmt.Sprintf("%s:%d", f.path, step.Location.Line),
time.Now().UnixNano() / nanoSec,
})
@ -261,8 +214,8 @@ func (f *events) Defined(step *gherkin.Step, def *StepDef) {
func (f *events) Passed(step *gherkin.Step, match *StepDef) {
f.basefmt.Passed(step, match)
f.step(f.passed[len(f.passed)-1])
f.stat = passed
f.step(f.passed[len(f.passed)-1])
}
func (f *events) Skipped(step *gherkin.Step) {
@ -272,18 +225,18 @@ func (f *events) Skipped(step *gherkin.Step) {
func (f *events) Undefined(step *gherkin.Step) {
f.basefmt.Undefined(step)
f.step(f.undefined[len(f.undefined)-1])
f.stat = undefined
f.step(f.undefined[len(f.undefined)-1])
}
func (f *events) Failed(step *gherkin.Step, match *StepDef, err error) {
f.basefmt.Failed(step, match, err)
f.step(f.failed[len(f.failed)-1])
f.stat = failed
f.step(f.failed[len(f.failed)-1])
}
func (f *events) Pending(step *gherkin.Step, match *StepDef) {
f.stat = pending
f.basefmt.Pending(step, match)
f.step(f.pending[len(f.pending)-1])
f.stat = pending
}

Просмотреть файл

@ -385,7 +385,7 @@ func (s *Suite) printStepDefinitions() {
}
for _, def := range s.steps {
n := utf8.RuneCountInString(def.Expr.String())
location := def.funcName()
location := def.definitionID()
spaces := strings.Repeat(" ", longest-n)
fmt.Println(cl(def.Expr.String(), yellow)+spaces, cl("# "+location, black))
}