MCPcopy
hub / github.com/urfave/cli / TestCompletionSubcommandOrder

Function TestCompletionSubcommandOrder

completion_test.go:121–144  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

119}
120
121func TestCompletionSubcommandOrder(t *testing.T) {
122 // The completion subcommands must appear in a deterministic order so that
123 // help output (and docs generated from it) does not change between runs.
124 // Previously they were built by iterating a map, whose order Go randomizes.
125 want := []string{"bash", "zsh", "fish", "pwsh"}
126
127 // Build several times to guard against intra-process variation.
128 for range 10 {
129 cmd := buildCompletionCommand("foo")
130
131 got := make([]string, 0, len(cmd.Commands))
132 for _, sub := range cmd.Commands {
133 got = append(got, sub.Name)
134 }
135
136 assert.Equal(t, want, got)
137 }
138
139 // Every shell in shellCompletions must be represented in the ordered list.
140 assert.Len(t, completionShells, len(shellCompletions))
141 for shell := range shellCompletions {
142 assert.Contains(t, completionShells, shell)
143 }
144}
145
146func TestCompletionBashNoShebang(t *testing.T) {
147 // Regression test for https://github.com/urfave/cli/issues/2259

Callers

nothing calls this directly

Calls 2

buildCompletionCommandFunction · 0.85
LenMethod · 0.65

Tested by

no test coverage detected