Skip to content

Commit

Permalink
add TestPersistentPreRunHooksForCompletionCommand
Browse files Browse the repository at this point in the history
  • Loading branch information
JunNishimura committed Jul 13, 2023
1 parent ba4e21d commit 3bb59c6
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions completions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2460,6 +2460,31 @@ func TestDefaultCompletionCmd(t *testing.T) {
removeCompCmd(rootCmd)
}

func TestPersistentPreRunHooksForCompletionCommand(t *testing.T) {
executed := false

rootCmd := &Command{
Use: "root",
PersistentPreRun: func(*Command, []string) { executed = true },
Run: emptyRun,
}
subCmd := &Command{
Use: "sub",
Run: emptyRun,
}
rootCmd.AddCommand(subCmd)

for _, shell := range []string{"bash", "fish", "powershell", "zsh"} {
if _, err := executeCommand(rootCmd, compCmdName, shell); err != nil {
t.Errorf("Unexpected error: %v", err)
}
if !executed {
t.Error("Root PersistentPreRun should have been executed")
}
executed = false
}
}

func TestCompleteCompletion(t *testing.T) {
rootCmd := &Command{Use: "root", Args: NoArgs, Run: emptyRun}
subCmd := &Command{
Expand Down

0 comments on commit 3bb59c6

Please sign in to comment.