forked from urfave/cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcompletion_test.go
70 lines (63 loc) · 1.59 KB
/
completion_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
package cli
import (
"bytes"
"strings"
"testing"
)
func TestCompletionDisable(t *testing.T) {
a := &App{}
err := a.Run([]string{"foo", completionCommandName})
if err == nil {
t.Error("Expected error for no help topic for completion")
}
}
func TestCompletionEnable(t *testing.T) {
a := &App{
EnableShellCompletion: true,
}
err := a.Run([]string{"foo", completionCommandName})
if err == nil || !strings.Contains(err.Error(), "no shell provided") {
t.Errorf("expected no shell provided error instead got [%v]", err)
}
}
func TestCompletionEnableDiffCommandName(t *testing.T) {
defer func() {
completionCommand.Name = completionCommandName
}()
a := &App{
EnableShellCompletion: true,
ShellCompletionCommandName: "junky",
}
err := a.Run([]string{"foo", "junky"})
if err == nil || !strings.Contains(err.Error(), "no shell provided") {
t.Errorf("expected no shell provided error instead got [%v]", err)
}
}
func TestCompletionShell(t *testing.T) {
for k := range shellCompletions {
var b bytes.Buffer
t.Run(k, func(t *testing.T) {
a := &App{
EnableShellCompletion: true,
Writer: &b,
}
err := a.Run([]string{"foo", completionCommandName, k})
if err != nil {
t.Error(err)
}
})
output := b.String()
if !strings.Contains(output, k) {
t.Errorf("Expected output to contain shell name %v", output)
}
}
}
func TestCompletionInvalidShell(t *testing.T) {
a := &App{
EnableShellCompletion: true,
}
err := a.Run([]string{"foo", completionCommandName, "junky-sheell"})
if err == nil {
t.Error("Expected error for invalid shell")
}
}