-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhelp_test.go
More file actions
54 lines (48 loc) · 1.14 KB
/
Copy pathhelp_test.go
File metadata and controls
54 lines (48 loc) · 1.14 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
package commandergo
import (
"strings"
"testing"
)
func TestNewRegistersHelp(t *testing.T) {
cmd := New("app")
if !cmd._options.has("help") {
t.Fatal("New() should auto-register --help option")
}
opt, _ := cmd._options.get("help")
if opt.alias != "h" {
t.Fatalf("--help alias should be 'h', got %q", opt.alias)
}
}
func TestHelpText(t *testing.T) {
cmd := New("todo").
Description("A simple todo CLI").
Arguments("[filter]", "filter todos", nil).
Options("--all", "show all todos", false)
cmd.Command("add [todo]", "add a new todo").
Options("--force", "force add", false)
cmd.Command("list", "list todos")
help := cmd.helpText()
cases := []string{
"Usage: todo",
"[options]",
"[command]",
"[filter]",
"A simple todo CLI",
"Arguments:",
"filter",
"Options:",
"--all",
"-h, --help",
"Commands:",
"add [options] [todo]",
"list",
}
for _, want := range cases {
if !strings.Contains(help, want) {
t.Errorf("helpText() missing %q\ngot:\n%s", want, help)
}
}
if strings.Contains(help, "list [options]") {
t.Errorf("helpText() should not show default help option as subcommand options\ngot:\n%s", help)
}
}