common failed scenario output for progress and pretty format: #113
Этот коммит содержится в:
родитель
cf27a6173c
коммит
f9aabcdc58
4 изменённых файлов: 61 добавлений и 30 удалений
48
fmt.go
48
fmt.go
|
@ -161,6 +161,54 @@ func (f stepResult) line() string {
|
||||||
return fmt.Sprintf("%s:%d", f.feature.Path, f.step.Location.Line)
|
return fmt.Sprintf("%s:%d", f.feature.Path, f.step.Location.Line)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (f stepResult) scenarioDesc() string {
|
||||||
|
if sc, ok := f.owner.(*gherkin.Scenario); ok {
|
||||||
|
return fmt.Sprintf("%s: %s", sc.Keyword, sc.Name)
|
||||||
|
}
|
||||||
|
|
||||||
|
if row, ok := f.owner.(*gherkin.TableRow); ok {
|
||||||
|
for _, def := range f.feature.Feature.ScenarioDefinitions {
|
||||||
|
out, ok := def.(*gherkin.ScenarioOutline)
|
||||||
|
if !ok {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, ex := range out.Examples {
|
||||||
|
for _, rw := range ex.TableBody {
|
||||||
|
if rw.Location.Line == row.Location.Line {
|
||||||
|
return fmt.Sprintf("%s: %s", out.Keyword, out.Name)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return f.line() // was not expecting different owner
|
||||||
|
}
|
||||||
|
|
||||||
|
func (f stepResult) scenarioLine() string {
|
||||||
|
if sc, ok := f.owner.(*gherkin.Scenario); ok {
|
||||||
|
return fmt.Sprintf("%s:%d", f.feature.Path, sc.Location.Line)
|
||||||
|
}
|
||||||
|
|
||||||
|
if row, ok := f.owner.(*gherkin.TableRow); ok {
|
||||||
|
for _, def := range f.feature.Feature.ScenarioDefinitions {
|
||||||
|
out, ok := def.(*gherkin.ScenarioOutline)
|
||||||
|
if !ok {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, ex := range out.Examples {
|
||||||
|
for _, rw := range ex.TableBody {
|
||||||
|
if rw.Location.Line == row.Location.Line {
|
||||||
|
return fmt.Sprintf("%s:%d", f.feature.Path, out.Location.Line)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return f.line() // was not expecting different owner
|
||||||
|
}
|
||||||
|
|
||||||
type basefmt struct {
|
type basefmt struct {
|
||||||
out io.Writer
|
out io.Writer
|
||||||
owner interface{}
|
owner interface{}
|
||||||
|
|
|
@ -120,34 +120,12 @@ func (f *pretty) printUndefinedScenario(sc *gherkin.Scenario) {
|
||||||
|
|
||||||
// Summary sumarize the feature formatter output
|
// Summary sumarize the feature formatter output
|
||||||
func (f *pretty) Summary() {
|
func (f *pretty) Summary() {
|
||||||
// failed steps on background are not scenarios
|
if len(f.failed) > 0 {
|
||||||
var failedScenarios []*stepResult
|
fmt.Fprintln(f.out, "\n--- "+red("Failed steps:")+"\n")
|
||||||
for _, fail := range f.failed {
|
for _, fail := range f.failed {
|
||||||
switch fail.owner.(type) {
|
fmt.Fprintln(f.out, s(2)+red(fail.scenarioDesc())+black(" # "+fail.scenarioLine()))
|
||||||
case *gherkin.Scenario:
|
fmt.Fprintln(f.out, s(4)+red(strings.TrimSpace(fail.step.Keyword)+" "+fail.step.Text)+black(" # "+fail.line()))
|
||||||
failedScenarios = append(failedScenarios, fail)
|
fmt.Fprintln(f.out, s(6)+red("Error: ")+redb(fmt.Sprintf("%+v", fail.err))+"\n")
|
||||||
case *gherkin.TableRow:
|
|
||||||
failedScenarios = append(failedScenarios, fail)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if len(failedScenarios) > 0 {
|
|
||||||
fmt.Fprintln(f.out, "\n--- "+red("Failed scenarios:")+"\n")
|
|
||||||
var unique []string
|
|
||||||
for _, fail := range failedScenarios {
|
|
||||||
var found bool
|
|
||||||
for _, in := range unique {
|
|
||||||
if in == fail.line() {
|
|
||||||
found = true
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if !found {
|
|
||||||
unique = append(unique, fail.line())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, fail := range unique {
|
|
||||||
fmt.Fprintln(f.out, " "+red(fail))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
f.basefmt.Summary()
|
f.basefmt.Summary()
|
||||||
|
|
|
@ -58,6 +58,7 @@ func (f *progress) Summary() {
|
||||||
if len(f.failed) > 0 {
|
if len(f.failed) > 0 {
|
||||||
fmt.Fprintln(f.out, "\n--- "+red("Failed steps:")+"\n")
|
fmt.Fprintln(f.out, "\n--- "+red("Failed steps:")+"\n")
|
||||||
for _, fail := range f.failed {
|
for _, fail := range f.failed {
|
||||||
|
fmt.Fprintln(f.out, s(2)+red(fail.scenarioDesc())+black(" # "+fail.scenarioLine()))
|
||||||
fmt.Fprintln(f.out, s(4)+red(strings.TrimSpace(fail.step.Keyword)+" "+fail.step.Text)+black(" # "+fail.line()))
|
fmt.Fprintln(f.out, s(4)+red(strings.TrimSpace(fail.step.Keyword)+" "+fail.step.Text)+black(" # "+fail.line()))
|
||||||
fmt.Fprintln(f.out, s(6)+red("Error: ")+redb(fmt.Sprintf("%+v", fail.err))+"\n")
|
fmt.Fprintln(f.out, s(6)+red("Error: ")+redb(fmt.Sprintf("%+v", fail.err))+"\n")
|
||||||
}
|
}
|
||||||
|
|
|
@ -41,10 +41,12 @@ func TestProgressFormatterOutput(t *testing.T) {
|
||||||
|
|
||||||
--- Failed steps:
|
--- Failed steps:
|
||||||
|
|
||||||
|
Scenario: failing scenario # any.feature:10
|
||||||
When failing # any.feature:11
|
When failing # any.feature:11
|
||||||
Error: errored
|
Error: errored
|
||||||
|
|
||||||
When failing # any.feature:24
|
Scenario Outline: outline # any.feature:22
|
||||||
|
When failing # any.feature:24
|
||||||
Error: errored
|
Error: errored
|
||||||
|
|
||||||
|
|
||||||
|
@ -118,7 +120,7 @@ func TestProgressFormatterWhenStepPanics(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
out := buf.String()
|
out := buf.String()
|
||||||
if idx := strings.Index(out, "github.com/DATA-DOG/godog/fmt_progress_test.go:116"); idx == -1 {
|
if idx := strings.Index(out, "github.com/DATA-DOG/godog/fmt_progress_test.go:114"); idx == -1 {
|
||||||
t.Fatalf("expected to find panic stacktrace, actual:\n%s", out)
|
t.Fatalf("expected to find panic stacktrace, actual:\n%s", out)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -178,6 +180,7 @@ func TestProgressFormatterWithFailingMultisteps(t *testing.T) {
|
||||||
|
|
||||||
--- Failed steps:
|
--- Failed steps:
|
||||||
|
|
||||||
|
Scenario: passing scenario # some.feature:4
|
||||||
Then two # some.feature:6
|
Then two # some.feature:6
|
||||||
Error: sub2: sub-sub: errored
|
Error: sub2: sub-sub: errored
|
||||||
|
|
||||||
|
@ -385,6 +388,7 @@ Feature: basic
|
||||||
|
|
||||||
--- Failed steps:
|
--- Failed steps:
|
||||||
|
|
||||||
|
Scenario: passing scenario # :4
|
||||||
Then two # :6
|
Then two # :6
|
||||||
Error: nested steps cannot be multiline and have table or content body argument
|
Error: nested steps cannot be multiline and have table or content body argument
|
||||||
|
|
||||||
|
|
Загрузка…
Создание таблицы
Сослаться в новой задаче