Этот коммит содержится в:
Fredrik Lönnblad 2020-03-02 19:42:59 -03:00
родитель d7e8f831e8
коммит edafd7752d
7 изменённых файлов: 42 добавлений и 32 удалений

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

@ -135,6 +135,7 @@ func (f *cukefmt) Pickle(pickle *messages.Pickle) {
f.curElement.Keyword = scenario.Keyword f.curElement.Keyword = scenario.Keyword
f.curElement.ID = f.curFeature.ID + ";" + makeID(pickle.Name) f.curElement.ID = f.curFeature.ID + ";" + makeID(pickle.Name)
f.curElement.Type = "scenario" f.curElement.Type = "scenario"
f.curElement.Tags = make([]cukeTag, len(scenario.Tags)+len(f.curFeature.Tags)) f.curElement.Tags = make([]cukeTag, len(scenario.Tags)+len(f.curFeature.Tags))
if len(f.curElement.Tags) > 0 { if len(f.curElement.Tags) > 0 {
@ -148,17 +149,22 @@ func (f *cukefmt) Pickle(pickle *messages.Pickle) {
} }
} }
if len(pickle.AstNodeIds) == 1 {
return
}
example, _ := f.findExample(pickle.AstNodeIds[1])
// apply example level tags.
for _, tag := range example.Tags {
tag := cukeTag{Line: int(tag.Location.Line), Name: tag.Name}
f.curElement.Tags = append(f.curElement.Tags, tag)
}
examples := scenario.GetExamples() examples := scenario.GetExamples()
if len(examples) > 0 { if len(examples) > 0 {
rowID := pickle.AstNodeIds[1] rowID := pickle.AstNodeIds[1]
for _, example := range examples { for _, example := range examples {
// apply example level tags.
for _, element := range example.Tags {
tag := cukeTag{Line: int(element.Location.Line), Name: element.Name}
f.curElement.Tags = append(f.curElement.Tags, tag)
}
for idx, row := range example.TableBody { for idx, row := range example.TableBody {
if rowID == row.Id { if rowID == row.Id {
f.curElement.ID += fmt.Sprintf(";%s;%d", makeID(example.Name), idx+2) f.curElement.ID += fmt.Sprintf(";%s;%d", makeID(example.Name), idx+2)
@ -223,8 +229,14 @@ func (f *cukefmt) Defined(pickle *messages.Pickle, pickleStep *messages.Pickle_P
step := f.findStep(pickleStep.AstNodeIds[0]) step := f.findStep(pickleStep.AstNodeIds[0])
line := step.Location.Line
if len(pickle.AstNodeIds) == 2 {
_, row := f.findExample(pickle.AstNodeIds[1])
line = row.Location.Line
}
f.curStep.Name = pickleStep.Text f.curStep.Name = pickleStep.Text
f.curStep.Line = int(step.Location.Line) f.curStep.Line = int(line)
f.curStep.Keyword = step.Keyword f.curStep.Keyword = step.Keyword
arg := pickleStep.Argument arg := pickleStep.Argument

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

@ -56,21 +56,17 @@ func (f *events) event(ev interface{}) {
func (f *events) Pickle(pickle *messages.Pickle) { func (f *events) Pickle(pickle *messages.Pickle) {
f.basefmt.Pickle(pickle) f.basefmt.Pickle(pickle)
scenario := f.findScenario(pickle.AstNodeIds[0])
id := fmt.Sprintf("%s:%d", f.path, scenario.Location.Line)
undefined := len(pickle.Steps) == 0
f.event(&struct { f.event(&struct {
Event string `json:"event"` Event string `json:"event"`
Location string `json:"location"` Location string `json:"location"`
Timestamp int64 `json:"timestamp"` Timestamp int64 `json:"timestamp"`
}{ }{
"TestCaseStarted", "TestCaseStarted",
id, f.scenarioLocation(pickle.AstNodeIds),
timeNowFunc().UnixNano() / nanoSec, timeNowFunc().UnixNano() / nanoSec,
}) })
if undefined { if len(pickle.Steps) == 0 {
// @TODO: is status undefined or passed? when there are no steps // @TODO: is status undefined or passed? when there are no steps
// for this scenario // for this scenario
f.event(&struct { f.event(&struct {
@ -80,7 +76,7 @@ func (f *events) Pickle(pickle *messages.Pickle) {
Status string `json:"status"` Status string `json:"status"`
}{ }{
"TestCaseFinished", "TestCaseFinished",
id, f.scenarioLocation(pickle.AstNodeIds),
timeNowFunc().UnixNano() / nanoSec, timeNowFunc().UnixNano() / nanoSec,
"undefined", "undefined",
}) })
@ -155,11 +151,7 @@ func (f *events) step(res *stepResult) {
errMsg, errMsg,
}) })
scenario := f.findScenario(res.owner.AstNodeIds[0]) if isLastStep(res.owner, res.step) {
line := scenario.Location.Line
finished := isLastStep(res.owner, res.step)
if finished {
f.event(&struct { f.event(&struct {
Event string `json:"event"` Event string `json:"event"`
Location string `json:"location"` Location string `json:"location"`
@ -167,7 +159,7 @@ func (f *events) step(res *stepResult) {
Status string `json:"status"` Status string `json:"status"`
}{ }{
"TestCaseFinished", "TestCaseFinished",
fmt.Sprintf("%s:%d", f.path, line), f.scenarioLocation(res.owner.AstNodeIds),
timeNowFunc().UnixNano() / nanoSec, timeNowFunc().UnixNano() / nanoSec,
f.status.String(), f.status.String(),
}) })
@ -249,3 +241,14 @@ func (f *events) Pending(pickle *messages.Pickle, step *messages.Pickle_PickleSt
f.status = pending f.status = pending
f.step(f.lastStepResult()) f.step(f.lastStepResult())
} }
func (f *events) scenarioLocation(astNodeIds []string) string {
scenario := f.findScenario(astNodeIds[0])
line := scenario.Location.Line
if len(astNodeIds) == 2 {
_, row := f.findExample(astNodeIds[1])
line = row.Location.Line
}
return fmt.Sprintf("%s:%d", f.path, line)
}

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

@ -68,7 +68,7 @@ func (f *pretty) Pending(pickle *messages.Pickle, step *messages.Pickle_PickleSt
} }
func (f *pretty) printFeature(feature *messages.GherkinDocument_Feature) { func (f *pretty) printFeature(feature *messages.GherkinDocument_Feature) {
if len(f.features) != 0 { if len(f.features) > 1 {
fmt.Fprintln(f.out, "") // not a first feature, add a newline fmt.Fprintln(f.out, "") // not a first feature, add a newline
} }
@ -117,7 +117,7 @@ func (f *pretty) printUndefinedPickle(pickle *messages.Pickle) {
if astBackground != nil { if astBackground != nil {
fmt.Fprintln(f.out, "\n"+s(f.indent)+keywordAndName(astBackground.Keyword, astBackground.Name)) fmt.Fprintln(f.out, "\n"+s(f.indent)+keywordAndName(astBackground.Keyword, astBackground.Name))
for _, step := range astBackground.Steps { for _, step := range astBackground.Steps {
text := s(f.indent) + cyan(strings.TrimSpace(step.Keyword)) + " " + cyan(step.Text) text := s(f.indent*2) + cyan(strings.TrimSpace(step.Keyword)) + " " + cyan(step.Text)
fmt.Fprintln(f.out, text) fmt.Fprintln(f.out, text)
} }
} }
@ -161,9 +161,9 @@ func (f *pretty) Summary() {
astStep := f.findStep(fail.step.AstNodeIds[0]) astStep := f.findStep(fail.step.AstNodeIds[0])
stepDesc := strings.TrimSpace(astStep.Keyword) + " " + fail.step.Text stepDesc := strings.TrimSpace(astStep.Keyword) + " " + fail.step.Text
fmt.Fprintln(f.out, s(2)+red(scenarioDesc)+f.line(astScenario.Location)) fmt.Fprintln(f.out, s(f.indent)+red(scenarioDesc)+f.line(astScenario.Location))
fmt.Fprintln(f.out, s(4)+red(stepDesc)+f.line(astStep.Location)) fmt.Fprintln(f.out, s(f.indent*2)+red(stepDesc)+f.line(astStep.Location))
fmt.Fprintln(f.out, s(6)+red("Error: ")+redb(fmt.Sprintf("%+v", fail.err))+"\n") fmt.Fprintln(f.out, s(f.indent*3)+red("Error: ")+redb(fmt.Sprintf("%+v", fail.err))+"\n")
} }
} }
@ -319,7 +319,7 @@ func (f *pretty) printStep(result *stepResult) {
f.printScenarioHeader(astScenario, maxLength-scenarioHeaderLength) f.printScenarioHeader(astScenario, maxLength-scenarioHeaderLength)
} }
text := s(f.indent) + result.status.clr()(strings.TrimSpace(astStep.Keyword)) + " " + result.status.clr()(astStep.Text) text := s(f.indent*2) + result.status.clr()(strings.TrimSpace(astStep.Keyword)) + " " + result.status.clr()(astStep.Text)
if result.def != nil { if result.def != nil {
text += s(maxLength - stepLength + 1) text += s(maxLength - stepLength + 1)
text += blackb("# " + result.def.definitionID()) text += blackb("# " + result.def.definitionID())

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

@ -1,5 +1,5 @@
{"event":"TestRunStarted","version":"0.1.0","timestamp":-6795364578871,"suite":"events"} {"event":"TestRunStarted","version":"0.1.0","timestamp":-6795364578871,"suite":"events"}
{"event":"TestSource","location":"formatter-tests/features/scenario_outline.feature:2","source":"@outline @tag\nFeature: outline\n\n @scenario\n Scenario Outline: outline\n Given passing step\n When passing step\n Then odd \u003codd\u003e and even \u003ceven\u003e number\n\n @tagged\n Examples: tagged\n | odd | even |\n | 1 | 2 |\n | 2 | 0 |\n | 3 | 11 |\n\n @tag2\n Examples:\n | odd | even |\n | 1 | 14 |\n | 3 | 9 |\n\n"} {"event":"TestSource","location":"formatter-tests/features/scenario_outline.feature:2","source":"@outline @tag\nFeature: outline\n\n @scenario\n Scenario Outline: outline\n Given passing step\n When passing step\n Then odd \u003codd\u003e and even \u003ceven\u003e number\n\n @tagged\n Examples: tagged\n | odd | even |\n | 1 | 2 |\n | 2 | 0 |\n | 3 | 11 |\n\n @tag2\n Examples:\n | odd | even |\n | 1 | 14 |\n | 3 | 9 |\n"}
{"event":"TestCaseStarted","location":"formatter-tests/features/scenario_outline.feature:13","timestamp":-6795364578871} {"event":"TestCaseStarted","location":"formatter-tests/features/scenario_outline.feature:13","timestamp":-6795364578871}
{"event":"StepDefinitionFound","location":"formatter-tests/features/scenario_outline.feature:6","definition_id":"formatters_print_test.go:63 -\u003e passingStepDef","arguments":[]} {"event":"StepDefinitionFound","location":"formatter-tests/features/scenario_outline.feature:6","definition_id":"formatters_print_test.go:63 -\u003e passingStepDef","arguments":[]}
{"event":"TestStepStarted","location":"formatter-tests/features/scenario_outline.feature:6","timestamp":-6795364578871} {"event":"TestStepStarted","location":"formatter-tests/features/scenario_outline.feature:6","timestamp":-6795364578871}

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

@ -19,4 +19,3 @@ Feature: outline
| odd | even | | odd | even |
| 1 | 14 | | 1 | 14 |
| 3 | 9 | | 3 | 9 |

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

@ -10,7 +10,6 @@
<cyan>Then</cyan> <cyan>passing step</cyan> <bold-black># formatters_print_test.go:63 -> passingStepDef</bold-black> <cyan>Then</cyan> <cyan>passing step</cyan> <bold-black># formatters_print_test.go:63 -> passingStepDef</bold-black>
<bold-white>Scenario:</bold-white> two <bold-black># formatter-tests/features/two_scenarios_with_background_fail.feature:11</bold-black> <bold-white>Scenario:</bold-white> two <bold-black># formatter-tests/features/two_scenarios_with_background_fail.feature:11</bold-black>
<bold-red>step failed</bold-red>
<cyan>Then</cyan> <cyan>passing step</cyan> <bold-black># formatters_print_test.go:63 -> passingStepDef</bold-black> <cyan>Then</cyan> <cyan>passing step</cyan> <bold-black># formatters_print_test.go:63 -> passingStepDef</bold-black>
--- <red>Failed steps:</red> --- <red>Failed steps:</red>

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

@ -51,10 +51,7 @@ func TestPrintingFormatters(t *testing.T) {
suite.fmt.Summary() suite.fmt.Summary()
expected := string(expectedOutput) expected := string(expectedOutput)
expected = trimAllLines(expected)
actual := buf.String() actual := buf.String()
actual = trimAllLines(actual)
assert.Equalf(t, expected, actual, "path: %s", expectOutputPath) assert.Equalf(t, expected, actual, "path: %s", expectOutputPath)
} }