Added examples logic.
Этот коммит содержится в:
родитель
9820f49ceb
коммит
afc629be69
1 изменённых файлов: 26 добавлений и 56 удалений
|
@ -7,7 +7,6 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
"github.com/DATA-DOG/godog/gherkin"
|
"github.com/DATA-DOG/godog/gherkin"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"strconv"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const cukeurl = "https://www.relishapp.com/cucumber/cucumber/docs/formatters/json-output-formatter"
|
const cukeurl = "https://www.relishapp.com/cucumber/cucumber/docs/formatters/json-output-formatter"
|
||||||
|
@ -48,20 +47,6 @@ type cukeMatch struct {
|
||||||
Location string `json:"location"`
|
Location string `json:"location"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type cukeExample struct {
|
|
||||||
Keyword string `json:"keyword"`
|
|
||||||
Id string `json:"id"`
|
|
||||||
Name string `json:"name"`
|
|
||||||
Line int `json:"line"`
|
|
||||||
Description string `json:"description"`
|
|
||||||
Rows []cukeRow `json:"rows"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type cukeRow struct {
|
|
||||||
Cells []string `json:"cells"`
|
|
||||||
Id string `json:"id"`
|
|
||||||
Line int `json:"line"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type cukeStep struct {
|
type cukeStep struct {
|
||||||
Keyword string `json:"keyword"`
|
Keyword string `json:"keyword"`
|
||||||
|
@ -78,9 +63,8 @@ type cukeElement struct {
|
||||||
Line int `json:"line"`
|
Line int `json:"line"`
|
||||||
Description string `json:"description"`
|
Description string `json:"description"`
|
||||||
Tags []cukeTag `json:"tags"`
|
Tags []cukeTag `json:"tags"`
|
||||||
Type string `json:type`
|
Type string `json:"type"`
|
||||||
Steps []cukeStep `json:steps`
|
Steps []cukeStep `json:"steps"`
|
||||||
Examples []cukeExample `json:examples,omitempty`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type cukeFeatureJson struct {
|
type cukeFeatureJson struct {
|
||||||
|
@ -109,6 +93,8 @@ type cukefmt struct {
|
||||||
curStep *cukeStep // track the current step
|
curStep *cukeStep // track the current step
|
||||||
curElement *cukeElement // track the current element
|
curElement *cukeElement // track the current element
|
||||||
curFeature *cukeFeatureJson // track the current feature
|
curFeature *cukeFeatureJson // track the current feature
|
||||||
|
curOutline cukeElement // Each example show up as an outline element but the outline is parsed only once
|
||||||
|
// so I need to keep track of the current outline
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *cukefmt) Node(n interface{}) {
|
func (f *cukefmt) Node(n interface{}) {
|
||||||
|
@ -117,44 +103,26 @@ func (f *cukefmt) Node(n interface{}) {
|
||||||
switch t := n.(type) {
|
switch t := n.(type) {
|
||||||
|
|
||||||
case *gherkin.Examples:
|
case *gherkin.Examples:
|
||||||
ex := cukeExample{}
|
fmt.Fprintln("Examples")
|
||||||
ex.Description = t.Description
|
saveElement := f.curElement
|
||||||
ex.Id = f.curElement.Id + ";" + makeId(t.Name)
|
|
||||||
ex.Line = t.Location.Line
|
|
||||||
ex.Name = t.Name
|
|
||||||
ex.Keyword = t.Keyword
|
|
||||||
ex.Rows = make([]cukeRow,len(t.TableBody)+1)
|
|
||||||
|
|
||||||
// first row is the header
|
f.curElement.Id = f.curElement.Id + ";" + makeId(t.Name)
|
||||||
ex.Rows[0].Line = t.TableHeader.Location.Line
|
f.curFeature.Elements = append(f.curFeature.Elements, f.curElement)
|
||||||
ex.Rows[0].Cells = make([]string,len(t.TableHeader.Cells))
|
|
||||||
ex.Rows[0].Id = ex.Id + ";1"
|
|
||||||
for idx, val := range t.TableHeader.Cells {
|
|
||||||
ex.Rows[0].Cells[idx] = val.Value
|
|
||||||
}
|
|
||||||
|
|
||||||
// The other example are in the body
|
f.curElement = saveElement
|
||||||
for i, row := range t.TableBody {
|
|
||||||
ex.Rows[1+i].Line = row.Location.Line
|
|
||||||
ex.Rows[1+i].Cells = make([]string,len(row.Cells))
|
|
||||||
ex.Rows[1+i].Id = ex.Id + ";"+strconv.Itoa(i+2)
|
|
||||||
for idx, val := range row.Cells {
|
|
||||||
ex.Rows[1+i].Cells[idx] = val.Value
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
f.curElement.Examples = append(f.curElement.Examples,ex)
|
|
||||||
|
|
||||||
case *gherkin.ScenarioOutline:
|
case *gherkin.ScenarioOutline:
|
||||||
f.curFeature.Elements = append(f.curFeature.Elements, cukeElement{})
|
fmt.Fprintln("Outline")
|
||||||
f.curElement = &f.curFeature.Elements[len(f.curFeature.Elements) - 1]
|
//f.curFeature.Elements = append(f.curFeature.Elements, cukeElement{})
|
||||||
|
//f.curElement = &f.curFeature.Elements[len(f.curFeature.Elements) - 1]
|
||||||
|
|
||||||
|
f.curElement=cukeElement{}
|
||||||
f.curElement.Name = t.Name
|
f.curElement.Name = t.Name
|
||||||
f.curElement.Line = t.Location.Line
|
f.curElement.Line = t.Location.Line
|
||||||
f.curElement.Description = t.Description
|
f.curElement.Description = t.Description
|
||||||
f.curElement.Keyword = t.Keyword
|
f.curElement.Keyword = t.Keyword
|
||||||
f.curElement.Id = f.curFeature.Id + ";" + makeId(t.Name)
|
f.curElement.Id = f.curFeature.Id + ";" + makeId(t.Name)
|
||||||
f.curElement.Type = t.Type
|
f.curElement.Type = "scenario"
|
||||||
f.curElement.Tags = make([]cukeTag, len(t.Tags))
|
f.curElement.Tags = make([]cukeTag, len(t.Tags))
|
||||||
for idx, element := range t.Tags {
|
for idx, element := range t.Tags {
|
||||||
f.curElement.Tags[idx].Line = element.Location.Line
|
f.curElement.Tags[idx].Line = element.Location.Line
|
||||||
|
@ -162,24 +130,26 @@ func (f *cukefmt) Node(n interface{}) {
|
||||||
}
|
}
|
||||||
|
|
||||||
case *gherkin.Scenario:
|
case *gherkin.Scenario:
|
||||||
f.curFeature.Elements = append(f.curFeature.Elements, cukeElement{})
|
fmt.Fprintln("Scenario")
|
||||||
f.curElement = &f.curFeature.Elements[len(f.curFeature.Elements) - 1]
|
|
||||||
|
|
||||||
|
f.curElement = cukeElement{}
|
||||||
f.curElement.Name = t.Name
|
f.curElement.Name = t.Name
|
||||||
f.curElement.Line = t.Location.Line
|
f.curElement.Line = t.Location.Line
|
||||||
f.curElement.Description = t.Description
|
f.curElement.Description = t.Description
|
||||||
f.curElement.Keyword = t.Keyword
|
f.curElement.Keyword = t.Keyword
|
||||||
f.curElement.Id = f.curFeature.Id + ";" + makeId(t.Name)
|
f.curElement.Id = f.curFeature.Id + ";" + makeId(t.Name)
|
||||||
f.curElement.Type = t.Type
|
f.curElement.Type = "scenario"
|
||||||
f.curElement.Tags = make([]cukeTag, len(t.Tags))
|
f.curElement.Tags = make([]cukeTag, len(t.Tags))
|
||||||
for idx, element := range t.Tags {
|
for idx, element := range t.Tags {
|
||||||
f.curElement.Tags[idx].Line = element.Location.Line
|
f.curElement.Tags[idx].Line = element.Location.Line
|
||||||
f.curElement.Tags[idx].Name = element.Name
|
f.curElement.Tags[idx].Name = element.Name
|
||||||
}
|
}
|
||||||
|
f.curFeature.Elements = append(f.curFeature.Elements, f.curElement)
|
||||||
|
|
||||||
case *gherkin.TableRow:
|
case *gherkin.TableRow:
|
||||||
|
lastElement := &f.curFeature.Elements[len(f.curFeature.Elements) - 1]
|
||||||
|
lastElement.Id = lastElement.Id + ";cnt"
|
||||||
|
|
||||||
fmt.Fprintf(f.out, "Entering Node TableRow: %s:%d\n", f.path, t.Location.Line)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -218,13 +188,13 @@ func (f *cukefmt) Summary() {
|
||||||
func (f *cukefmt) step(res *stepResult) {
|
func (f *cukefmt) step(res *stepResult) {
|
||||||
|
|
||||||
// determine if test case has finished
|
// determine if test case has finished
|
||||||
var finished bool
|
switch t:= f.owner.(type) {
|
||||||
var line int
|
|
||||||
switch t := f.owner.(type) {
|
|
||||||
case *gherkin.TableRow:
|
case *gherkin.TableRow:
|
||||||
line = t.Location.Line
|
f.curStep.Line = t.Location.Line
|
||||||
finished = f.isLastStep(res.step)
|
f.curStep.Result.Status = res.typ.String()
|
||||||
fmt.Fprintf(f.out, "step: TableRow: line:%v finished:%v\n", line, finished)
|
if res.err != nil {
|
||||||
|
f.curStep.Result.Error = res.err.Error()
|
||||||
|
}
|
||||||
case *gherkin.Scenario:
|
case *gherkin.Scenario:
|
||||||
f.curStep.Result.Status = res.typ.String()
|
f.curStep.Result.Status = res.typ.String()
|
||||||
if res.err != nil {
|
if res.err != nil {
|
||||||
|
|
Загрузка…
Создание таблицы
Сослаться в новой задаче