diff --git a/fmt_cucumber.go b/fmt_cucumber.go
index ed17665..3315fec 100644
--- a/fmt_cucumber.go
+++ b/fmt_cucumber.go
@@ -135,6 +135,7 @@ func (f *cukefmt) Pickle(pickle *messages.Pickle) {
f.curElement.Keyword = scenario.Keyword
f.curElement.ID = f.curFeature.ID + ";" + makeID(pickle.Name)
f.curElement.Type = "scenario"
+
f.curElement.Tags = make([]cukeTag, len(scenario.Tags)+len(f.curFeature.Tags))
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()
if len(examples) > 0 {
rowID := pickle.AstNodeIds[1]
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 {
if rowID == row.Id {
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])
+ 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.Line = int(step.Location.Line)
+ f.curStep.Line = int(line)
f.curStep.Keyword = step.Keyword
arg := pickleStep.Argument
diff --git a/fmt_events.go b/fmt_events.go
index 162ee04..6f31086 100644
--- a/fmt_events.go
+++ b/fmt_events.go
@@ -56,21 +56,17 @@ func (f *events) event(ev interface{}) {
func (f *events) Pickle(pickle *messages.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 {
Event string `json:"event"`
Location string `json:"location"`
Timestamp int64 `json:"timestamp"`
}{
"TestCaseStarted",
- id,
+ f.scenarioLocation(pickle.AstNodeIds),
timeNowFunc().UnixNano() / nanoSec,
})
- if undefined {
+ if len(pickle.Steps) == 0 {
// @TODO: is status undefined or passed? when there are no steps
// for this scenario
f.event(&struct {
@@ -80,7 +76,7 @@ func (f *events) Pickle(pickle *messages.Pickle) {
Status string `json:"status"`
}{
"TestCaseFinished",
- id,
+ f.scenarioLocation(pickle.AstNodeIds),
timeNowFunc().UnixNano() / nanoSec,
"undefined",
})
@@ -155,11 +151,7 @@ func (f *events) step(res *stepResult) {
errMsg,
})
- scenario := f.findScenario(res.owner.AstNodeIds[0])
- line := scenario.Location.Line
- finished := isLastStep(res.owner, res.step)
-
- if finished {
+ if isLastStep(res.owner, res.step) {
f.event(&struct {
Event string `json:"event"`
Location string `json:"location"`
@@ -167,7 +159,7 @@ func (f *events) step(res *stepResult) {
Status string `json:"status"`
}{
"TestCaseFinished",
- fmt.Sprintf("%s:%d", f.path, line),
+ f.scenarioLocation(res.owner.AstNodeIds),
timeNowFunc().UnixNano() / nanoSec,
f.status.String(),
})
@@ -249,3 +241,14 @@ func (f *events) Pending(pickle *messages.Pickle, step *messages.Pickle_PickleSt
f.status = pending
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)
+}
diff --git a/fmt_pretty.go b/fmt_pretty.go
index 7efd2b7..6037d5b 100644
--- a/fmt_pretty.go
+++ b/fmt_pretty.go
@@ -68,7 +68,7 @@ func (f *pretty) Pending(pickle *messages.Pickle, step *messages.Pickle_PickleSt
}
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
}
@@ -117,7 +117,7 @@ func (f *pretty) printUndefinedPickle(pickle *messages.Pickle) {
if astBackground != nil {
fmt.Fprintln(f.out, "\n"+s(f.indent)+keywordAndName(astBackground.Keyword, astBackground.Name))
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)
}
}
@@ -161,9 +161,9 @@ func (f *pretty) Summary() {
astStep := f.findStep(fail.step.AstNodeIds[0])
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(4)+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)+red(scenarioDesc)+f.line(astScenario.Location))
+ fmt.Fprintln(f.out, s(f.indent*2)+red(stepDesc)+f.line(astStep.Location))
+ 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)
}
- 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 {
text += s(maxLength - stepLength + 1)
text += blackb("# " + result.def.definitionID())
diff --git a/formatter-tests/events/scenario_outline b/formatter-tests/events/scenario_outline
index 3af6cad..adab074 100644
--- a/formatter-tests/events/scenario_outline
+++ b/formatter-tests/events/scenario_outline
@@ -1,5 +1,5 @@
{"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":"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}
diff --git a/formatter-tests/features/scenario_outline.feature b/formatter-tests/features/scenario_outline.feature
index 3691ce3..1178642 100644
--- a/formatter-tests/features/scenario_outline.feature
+++ b/formatter-tests/features/scenario_outline.feature
@@ -19,4 +19,3 @@ Feature: outline
| odd | even |
| 1 | 14 |
| 3 | 9 |
-
diff --git a/formatter-tests/pretty/two_scenarios_with_background_fail b/formatter-tests/pretty/two_scenarios_with_background_fail
index 9e2ac58..c5b0969 100644
--- a/formatter-tests/pretty/two_scenarios_with_background_fail
+++ b/formatter-tests/pretty/two_scenarios_with_background_fail
@@ -10,7 +10,6 @@
Then passing step # formatters_print_test.go:63 -> passingStepDef
Scenario: two # formatter-tests/features/two_scenarios_with_background_fail.feature:11
- step failed
Then passing step # formatters_print_test.go:63 -> passingStepDef
--- Failed steps:
diff --git a/formatters_print_test.go b/formatters_print_test.go
index 6f0f4c2..07a24ce 100644
--- a/formatters_print_test.go
+++ b/formatters_print_test.go
@@ -51,10 +51,7 @@ func TestPrintingFormatters(t *testing.T) {
suite.fmt.Summary()
expected := string(expectedOutput)
- expected = trimAllLines(expected)
-
actual := buf.String()
- actual = trimAllLines(actual)
assert.Equalf(t, expected, actual, "path: %s", expectOutputPath)
}