/
decorator_markdown.go
51 lines (41 loc) · 1.41 KB
/
decorator_markdown.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package bdd
import "fmt"
type MarkdownDecorator struct{}
func NewMarkdownDecorator() *MarkdownDecorator {
return &MarkdownDecorator{}
}
func (d *MarkdownDecorator) _title(s string) string { return fmt.Sprintf("## %s\n", s) }
func (d *MarkdownDecorator) _scenario(s *ScenarioReport) string {
return parseReport(scenarioMarkdownDecoratorTpl, s)
}
func (d *MarkdownDecorator) _feature(f *FeatureReport) string {
return parseReport(featureMarkdownDecoratorTpl, f)
}
var scenarioMarkdownDecoratorTpl = `
{{if eq .TestStatus "PANIC"}}
#### PANIC! {{.TestName}}
Recovered: {{.PanicMsg}}
Trace: {{.Trace}}{{else}}
#### <span style="color:{{if eq .TestStatus "FAIL"}}red{{else}}green{{end}}">{{.TestStatus}}</span> {{.TestName}}
Feature: {{.Feature}}
Scenario: {{.Scenario}}
{{range .Steps}}{{ . }}
{{end}}
{{if .Errors}}**Errors:** {{range .Errors}}
- <code>{{ . }}</code>{{end}}{{end}}{{end}}
`
var featureMarkdownDecoratorTpl = `
### Feature: {{ .Name }}{{range .ScenarioReports}}
{{if eq .TestStatus "PANIC"}}
#### PANIC! {{.TestName}}
Recovered: {{.PanicMsg}}
Trace: {{.Trace}}{{else}}
#### <span style="color:{{if eq .TestStatus "FAIL"}}red{{else}}green{{end}}">{{.TestStatus}}</span> {{.TestName}}
Feature: {{.Feature}}
Scenario: {{.Scenario}}
{{range .Steps}}{{ . }}
{{end}}
{{if .Errors}}**Errors:** {{range .Errors}}
- <code>{{ . }}</code>{{end}}{{end}}{{end}}
{{end}}
`