-
Notifications
You must be signed in to change notification settings - Fork 73
/
cli_test.go
82 lines (77 loc) · 1.76 KB
/
cli_test.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 main
import (
"bytes"
"os"
"strings"
"testing"
)
func TestSpecifiedFlags(t *testing.T) {
os.Args = []string{"dot-github", "-issue", "-help", "-version", "-pullrequest", "-contributing", "-selfupdate"}
p, err := ParseCmdArgs(os.Stderr)
if err != nil {
t.Fatalf("must be parsed without error")
}
if !p.IssueOnly {
t.Errorf("-issue must be looked")
}
if !p.Help {
t.Errorf("-help must be looked")
}
if !p.PROnly {
t.Errorf("-pullrequest must be looked")
}
if !p.ContributingOnly {
t.Errorf("-contributing must be looked")
}
if !p.Version {
t.Errorf("-version must be looked")
}
if !p.SelfUpdate {
t.Errorf("-selfupdate must be looked")
}
}
func TestUnspecifiedFlags(t *testing.T) {
os.Args = []string{"dot-github"}
p, err := ParseCmdArgs(os.Stderr)
if err != nil {
t.Fatalf("must be parsed without error")
}
if p.IssueOnly {
t.Errorf("-issue is not valid default value")
}
if p.Help {
t.Errorf("-help is not valid default value")
}
if p.PROnly {
t.Errorf("-pullrequest is not valid default value")
}
if p.ContributingOnly {
t.Errorf("-contributing is not valid default value")
}
if p.Version {
t.Errorf("-version is not valid default value")
}
if p.SelfUpdate {
t.Errorf("-selfupdate is not valid default value")
}
}
func TestUndefinedFlags(t *testing.T) {
os.Args = []string{"dot-github", "-unknown"}
buf := &bytes.Buffer{}
_, err := ParseCmdArgs(buf)
if err == nil {
t.Fatalf("ignores unknown flag")
}
if !strings.Contains(buf.String(), "Usage:") {
t.Fatalf("does not output usage")
}
}
func TestShowHelp(t *testing.T) {
os.Args = []string{"dot-github"}
p, _ := ParseCmdArgs(os.Stderr)
buf := &bytes.Buffer{}
p.ShowUsage(buf)
if !strings.Contains(buf.String(), "Usage:") {
t.Fatalf("invalid help output")
}
}