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

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

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

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

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