generated from bool64/go-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pretty_failed.go
82 lines (65 loc) · 1.65 KB
/
pretty_failed.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
package godogx
import (
"bytes"
"io"
"sync"
"github.com/cucumber/godog"
"github.com/cucumber/godog/formatters"
)
var prettyFailedRegister sync.Once
// RegisterPrettyFailedFormatter adds `pretty-failed` formatter that skips output of successful scenarios
// and shows failed.
func RegisterPrettyFailedFormatter() {
prettyFailedRegister.Do(func() {
godog.Format("pretty-failed", "Pretty failed formatter skips successful scenarios.",
func(s string, writer io.Writer) formatters.Formatter {
buf := bytes.NewBuffer(nil)
return &prettyFailedFormatter{
PrettyFmt: godog.NewPrettyFmt(s, buf),
w: writer,
buf: buf,
}
})
})
}
type prettyFailedFormatter struct {
*godog.PrettyFmt
buf *bytes.Buffer
w io.Writer
}
func (p *prettyFailedFormatter) Failed(pickle *godog.Scenario, step *godog.Step, match *formatters.StepDefinition, err error) {
p.PrettyFmt.Failed(pickle, step, match, err)
p.Lock.Lock()
defer p.Lock.Unlock()
if _, err := io.Copy(p.w, p.buf); err != nil {
panic(err)
}
}
func (p *prettyFailedFormatter) Pickle(scenario *godog.Scenario) {
p.Lock.Lock()
p.buf.Reset()
p.Lock.Unlock()
p.PrettyFmt.Pickle(scenario)
}
func (p *prettyFailedFormatter) Feature(f *godog.GherkinDocument, ps string, c []byte) {
p.Lock.Lock()
p.buf.Reset()
p.Lock.Unlock()
p.PrettyFmt.Feature(f, ps, c)
p.Lock.Lock()
defer p.Lock.Unlock()
if _, err := io.Copy(p.w, p.buf); err != nil {
panic(err)
}
}
func (p *prettyFailedFormatter) Summary() {
p.Lock.Lock()
p.buf.Reset()
p.Lock.Unlock()
p.PrettyFmt.Summary()
p.Lock.Lock()
defer p.Lock.Unlock()
if _, err := io.Copy(p.w, p.buf); err != nil {
panic(err)
}
}