forked from cucumber/godog
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fmt_progress.go
121 lines (106 loc) · 2.61 KB
/
fmt_progress.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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
package godog
import (
"fmt"
"io"
"math"
"strings"
"sync"
"github.com/DATA-DOG/godog/gherkin"
)
func init() {
Format("progress", "Prints a character per step.", progressFunc)
}
func progressFunc(suite string, out io.Writer) Formatter {
return &progress{
basefmt: basefmt{
started: timeNowFunc(),
indent: 2,
out: out,
},
stepsPerRow: 70,
}
}
type progress struct {
basefmt
sync.Mutex
stepsPerRow int
steps int
}
func (f *progress) Node(n interface{}) {
f.Lock()
defer f.Unlock()
f.basefmt.Node(n)
}
func (f *progress) Feature(ft *gherkin.Feature, p string, c []byte) {
f.Lock()
defer f.Unlock()
f.basefmt.Feature(ft, p, c)
}
func (f *progress) Summary() {
left := math.Mod(float64(f.steps), float64(f.stepsPerRow))
if left != 0 {
if f.steps > f.stepsPerRow {
fmt.Fprintf(f.out, s(f.stepsPerRow-int(left))+fmt.Sprintf(" %d\n", f.steps))
} else {
fmt.Fprintf(f.out, " %d\n", f.steps)
}
}
fmt.Fprintln(f.out, "")
if len(f.failed) > 0 {
fmt.Fprintln(f.out, "\n--- "+red("Failed steps:")+"\n")
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(6)+red("Error: ")+redb(fmt.Sprintf("%+v", fail.err))+"\n")
}
}
f.basefmt.Summary()
}
func (f *progress) step(res *stepResult) {
switch res.typ {
case passed:
fmt.Fprint(f.out, green("."))
case skipped:
fmt.Fprint(f.out, cyan("-"))
case failed:
fmt.Fprint(f.out, red("F"))
case undefined:
fmt.Fprint(f.out, yellow("U"))
case pending:
fmt.Fprint(f.out, yellow("P"))
}
f.steps++
if math.Mod(float64(f.steps), float64(f.stepsPerRow)) == 0 {
fmt.Fprintf(f.out, " %d\n", f.steps)
}
}
func (f *progress) Passed(step *gherkin.Step, match *StepDef) {
f.Lock()
defer f.Unlock()
f.basefmt.Passed(step, match)
f.step(f.passed[len(f.passed)-1])
}
func (f *progress) Skipped(step *gherkin.Step, match *StepDef) {
f.Lock()
defer f.Unlock()
f.basefmt.Skipped(step, match)
f.step(f.skipped[len(f.skipped)-1])
}
func (f *progress) Undefined(step *gherkin.Step, match *StepDef) {
f.Lock()
defer f.Unlock()
f.basefmt.Undefined(step, match)
f.step(f.undefined[len(f.undefined)-1])
}
func (f *progress) Failed(step *gherkin.Step, match *StepDef, err error) {
f.Lock()
defer f.Unlock()
f.basefmt.Failed(step, match, err)
f.step(f.failed[len(f.failed)-1])
}
func (f *progress) Pending(step *gherkin.Step, match *StepDef) {
f.Lock()
defer f.Unlock()
f.basefmt.Pending(step, match)
f.step(f.pending[len(f.pending)-1])
}