forked from cucumber/godog
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathflags_test.go
More file actions
77 lines (63 loc) · 1.72 KB
/
flags_test.go
File metadata and controls
77 lines (63 loc) · 1.72 KB
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
package godog
import (
"bytes"
"fmt"
"strings"
"testing"
"github.com/DATA-DOG/godog/colors"
)
func TestFlagsShouldRandomizeAndGenerateSeed(t *testing.T) {
var opt Options
flags := FlagSet(&opt)
if err := flags.Parse([]string{"--random"}); err != nil {
t.Fatalf("unable to parse flags: %v", err)
}
if opt.Randomize <= 0 {
t.Fatal("should have generated random seed")
}
}
func TestFlagsShouldRandomizeByGivenSeed(t *testing.T) {
var opt Options
flags := FlagSet(&opt)
if err := flags.Parse([]string{"--random=123"}); err != nil {
t.Fatalf("unable to parse flags: %v", err)
}
if opt.Randomize != 123 {
t.Fatalf("expected random seed to be: 123, but it was: %d", opt.Randomize)
}
}
func TestFlagsShouldParseFormat(t *testing.T) {
cases := map[string][]string{
"pretty": {},
"progress": {"-f", "progress"},
"junit": {"-f=junit"},
"custom": {"--format", "custom"},
"cust": {"--format=cust"},
}
for format, args := range cases {
var opt Options
flags := FlagSet(&opt)
if err := flags.Parse(args); err != nil {
t.Fatalf("unable to parse flags: %v", err)
}
if opt.Format != format {
t.Fatalf("expected format: %s, but it was: %s", format, opt.Format)
}
}
}
func TestFlagsUsageShouldIncludeFormatDescriptons(t *testing.T) {
var buf bytes.Buffer
output := colors.Uncolored(&buf)
// register some custom formatter
Format("custom", "custom format description", junitFunc)
var opt Options
flags := FlagSet(&opt)
usage(flags, output)()
out := buf.String()
for name, desc := range AvailableFormatters() {
match := fmt.Sprintf("%s: %s\n", name, desc)
if idx := strings.Index(out, match); idx == -1 {
t.Fatalf("could not locate format: %s description in flag usage", name)
}
}
}