-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathflag_test.go
More file actions
48 lines (43 loc) · 814 Bytes
/
flag_test.go
File metadata and controls
48 lines (43 loc) · 814 Bytes
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
package cli
import "testing"
func TestNewFlag(t *testing.T) {
var flag string
f := NewFlag("flag", &flag)
if f == nil {
t.Fatal("should return a flag")
}
if f.IsSet() {
t.Fatal("should not be set")
}
}
func TestNewFlagPanic(t *testing.T) {
var flag string
defer func() {
perr := recover()
if perr == nil {
t.Fatal("should panic")
}
}()
_ = NewFlag("flag", flag)
}
func TestFlagSet(t *testing.T) {
var flag string
f := NewFlag("flag", &flag)
f.Set("test")
if f.String() != "test" {
t.Fatal("should set flag value")
}
if !f.IsSet() {
t.Fatal("should be set")
}
}
func TestFlagSetCount(t *testing.T) {
var v bool
f := NewFlag("verbose", &v, Bool(), ShortFlag("v"))
f.Set("true")
f.Set("true")
f.Set("true")
if f.Count() != 3 {
t.Fatal("should increment set count")
}
}