-
Notifications
You must be signed in to change notification settings - Fork 15
/
main_test.go
49 lines (40 loc) · 1017 Bytes
/
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
package main
import (
"testing"
"github.com/stretchr/testify/assert"
_ "honnef.co/go/tools/staticcheck"
)
func TestMain(t *testing.T) {
assert.Error(t, cliMain("main"))
assert.NoError(t, cliMain("main", "--help"))
}
func TestDupeCommands(t *testing.T) {
commands := make(map[string]struct{})
app := buildApp()
for _, cmd := range app.Commands {
for _, name := range cmd.Names() {
assert.NotContains(t, commands, name)
commands[name] = struct{}{}
}
}
}
func TestDupeFlags(t *testing.T) {
app := buildApp()
for _, cmd := range app.Commands {
flags := make(map[string]struct{})
// Global (even though technically can dupe, it's confusing, so prevent)
for _, flag := range app.Flags {
for _, name := range flag.Names() {
assert.NotContains(t, flags, name)
flags[name] = struct{}{}
}
}
// And the specific flags
for _, flag := range cmd.Flags {
for _, name := range flag.Names() {
assert.NotContains(t, flags, name)
flags[name] = struct{}{}
}
}
}
}