diff --git a/fmt.go b/fmt.go index 556bdcf..7aa35d5 100644 --- a/fmt.go +++ b/fmt.go @@ -206,6 +206,16 @@ func (f *basefmt) lastStepResult() *stepResult { return f.lastFeature().lastStepResult() } +func (f *basefmt) findFeature(scenarioAstID string) *feature { + for _, ft := range f.features { + if sc := ft.findScenario(scenarioAstID); sc != nil { + return ft + } + } + + panic("Couldn't find scenario for AST ID: " + scenarioAstID) +} + func (f *basefmt) findScenario(scenarioAstID string) *messages.GherkinDocument_Feature_Scenario { for _, ft := range f.features { if sc := ft.findScenario(scenarioAstID); sc != nil { diff --git a/fmt_pretty.go b/fmt_pretty.go index dd8a1c0..2b8a17b 100644 --- a/fmt_pretty.go +++ b/fmt_pretty.go @@ -104,7 +104,7 @@ func (f *pretty) scenarioLengths(scenarioAstID string) (scenarioHeaderLength int func (f *pretty) printScenarioHeader(astScenario *messages.GherkinDocument_Feature_Scenario, spaceFilling int) { text := s(f.indent) + keywordAndName(astScenario.Keyword, astScenario.Name) - text += s(spaceFilling) + f.line(astScenario.Location) + text += s(spaceFilling) + f.line(f.lastFeature().Path, astScenario.Location) fmt.Fprintln(f.out, "\n"+text) } @@ -155,14 +155,16 @@ func (f *pretty) Summary() { if len(failedStepResults) > 0 { fmt.Fprintln(f.out, "\n--- "+red("Failed steps:")+"\n") for _, fail := range failedStepResults { + feature := f.findFeature(fail.owner.AstNodeIds[0]) + astScenario := f.findScenario(fail.owner.AstNodeIds[0]) scenarioDesc := fmt.Sprintf("%s: %s", astScenario.Keyword, fail.owner.Name) astStep := f.findStep(fail.step.AstNodeIds[0]) stepDesc := strings.TrimSpace(astStep.Keyword) + " " + fail.step.Text - 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)+red(scenarioDesc)+f.line(feature.Path, astScenario.Location)) + fmt.Fprintln(f.out, s(f.indent*2)+red(stepDesc)+f.line(feature.Path, astStep.Location)) fmt.Fprintln(f.out, s(f.indent*3)+red("Error: ")+redb(fmt.Sprintf("%+v", fail.err))+"\n") } } @@ -455,8 +457,8 @@ func (f *pretty) longestStep(steps []*messages.GherkinDocument_Feature_Step, pic } // a line number representation in feature file -func (f *pretty) line(loc *messages.Location) string { - return " " + blackb(fmt.Sprintf("# %s:%d", f.lastFeature().Path, loc.Line)) +func (f *pretty) line(path string, loc *messages.Location) string { + return " " + blackb(fmt.Sprintf("# %s:%d", path, loc.Line)) } func (f *pretty) lengthPickleStep(keyword, text string) int {