-
Notifications
You must be signed in to change notification settings - Fork 31
/
main_test.go
54 lines (46 loc) · 1.02 KB
/
main_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
package flaggy_test
import (
"os"
"testing"
"github.com/integrii/flaggy"
)
func TestMain(m *testing.M) {
flaggy.PanicInsteadOfExit = true
// flaggy.DebugMode = true
os.Exit(m.Run())
}
func TestSetDescription(t *testing.T) {
desc := "Test Description"
flaggy.SetDescription(desc)
if flaggy.DefaultParser.Description != desc {
t.Fatal("set description does not match")
}
}
func TestSetVersion(t *testing.T) {
ver := "Test Version"
flaggy.SetVersion(ver)
if flaggy.DefaultParser.Version != ver {
t.Fatal("set version does not match")
}
}
func TestParserWithNoArgs(t *testing.T) {
os.Args = []string{}
flaggy.ResetParser()
}
func TestSetName(t *testing.T) {
name := "Test Name"
flaggy.SetName(name)
if flaggy.DefaultParser.Name != name {
t.Fatal("set name does not match")
}
}
func TestShowHelpAndExit(t *testing.T) {
flaggy.PanicInsteadOfExit = true
defer func() {
r := recover()
if r == nil {
t.Fatal("Expected panic on show help and exit call")
}
}()
flaggy.ShowHelpAndExit("test show help and exit")
}