-
Notifications
You must be signed in to change notification settings - Fork 253
/
fmt.go
124 lines (101 loc) · 3.42 KB
/
fmt.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
122
123
124
package godog
import (
"fmt"
"io"
"strings"
"unicode/utf8"
"github.com/cucumber/godog/colors"
"github.com/cucumber/godog/formatters"
internal_fmt "github.com/cucumber/godog/internal/formatters"
"github.com/cucumber/godog/internal/models"
"github.com/cucumber/godog/internal/storage"
)
// FindFmt searches available formatters registered
// and returns FormaterFunc matched by given
// format name or nil otherwise
func FindFmt(name string) FormatterFunc {
return formatters.FindFmt(name)
}
// Format registers a feature suite output
// formatter by given name, description and
// FormatterFunc constructor function, to initialize
// formatter with the output recorder.
func Format(name, description string, f FormatterFunc) {
formatters.Format(name, description, f)
}
// AvailableFormatters gives a map of all
// formatters registered with their name as key
// and description as value
func AvailableFormatters() map[string]string {
return formatters.AvailableFormatters()
}
// Formatter is an interface for feature runner
// output summary presentation.
//
// New formatters may be created to represent
// suite results in different ways. These new
// formatters needs to be registered with a
// godog.Format function call
type Formatter = formatters.Formatter
type storageFormatter interface {
SetStorage(*storage.Storage)
}
// FormatterFunc builds a formatter with given
// suite name and io.Writer to record output
type FormatterFunc = formatters.FormatterFunc
func printStepDefinitions(steps []*models.StepDefinition, w io.Writer) {
var longest int
for _, def := range steps {
n := utf8.RuneCountInString(def.Expr.String())
if longest < n {
longest = n
}
}
for _, def := range steps {
n := utf8.RuneCountInString(def.Expr.String())
location := internal_fmt.DefinitionID(def)
spaces := strings.Repeat(" ", longest-n)
fmt.Fprintln(w,
colors.Yellow(def.Expr.String())+spaces,
colors.Bold(colors.Black)("# "+location))
}
if len(steps) == 0 {
fmt.Fprintln(w, "there were no contexts registered, could not find any step definition..")
}
}
// NewBaseFmt creates a new base formatter.
func NewBaseFmt(suite string, out io.Writer) *BaseFmt {
return internal_fmt.NewBase(suite, out)
}
// NewProgressFmt creates a new progress formatter.
func NewProgressFmt(suite string, out io.Writer) *ProgressFmt {
return internal_fmt.NewProgress(suite, out)
}
// NewPrettyFmt creates a new pretty formatter.
func NewPrettyFmt(suite string, out io.Writer) *PrettyFmt {
return &PrettyFmt{Base: NewBaseFmt(suite, out)}
}
// NewEventsFmt creates a new event streaming formatter.
func NewEventsFmt(suite string, out io.Writer) *EventsFmt {
return &EventsFmt{Base: NewBaseFmt(suite, out)}
}
// NewCukeFmt creates a new Cucumber JSON formatter.
func NewCukeFmt(suite string, out io.Writer) *CukeFmt {
return &CukeFmt{Base: NewBaseFmt(suite, out)}
}
// NewJUnitFmt creates a new JUnit formatter.
func NewJUnitFmt(suite string, out io.Writer) *JUnitFmt {
return &JUnitFmt{Base: NewBaseFmt(suite, out)}
}
// BaseFmt exports Base formatter.
type BaseFmt = internal_fmt.Base
// ProgressFmt exports Progress formatter.
type ProgressFmt = internal_fmt.Progress
// PrettyFmt exports Pretty formatter.
type PrettyFmt = internal_fmt.Pretty
// EventsFmt exports Events formatter.
type EventsFmt = internal_fmt.Events
// CukeFmt exports Cucumber JSON formatter.
type CukeFmt = internal_fmt.Cuke
// JUnitFmt exports JUnit formatter.
type JUnitFmt = internal_fmt.JUnit