Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions command_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6452,15 +6452,19 @@ func TestCommand_Walk_NilFn(t *testing.T) {
}

// TestRunWithNoOsArgs checks that Run does not panic when handed an empty
// argument slice.
// argument slice. In particular, the combination of an empty Name and
// EnableShellCompletion exercises both the setupDefaults empty-name guard
// and the buildCompletionCommand("") append together.
func TestRunWithNoOsArgs(t *testing.T) {
for _, tst := range []struct {
name string
cmd *Command
name string
cmd *Command
wantName string
}{
{name: "plain", cmd: &Command{Name: "foo"}},
{name: "shell completion enabled", cmd: &Command{Name: "foo", EnableShellCompletion: true}},
{name: "plain", cmd: &Command{Name: "foo"}, wantName: "foo"},
{name: "shell completion enabled", cmd: &Command{Name: "foo", EnableShellCompletion: true}, wantName: "foo"},
{name: "no name", cmd: &Command{}},
{name: "no name, shell completion enabled", cmd: &Command{EnableShellCompletion: true}},
} {
t.Run(tst.name, func(t *testing.T) {
called := false
Expand All @@ -6473,6 +6477,7 @@ func TestRunWithNoOsArgs(t *testing.T) {
require.NoError(t, tst.cmd.Run(buildTestContext(t), []string{}))
})
assert.True(t, called)
assert.Equal(t, tst.wantName, tst.cmd.Name)
})
}
}