mirror of
https://github.com/spf13/cobra
synced 2024-11-24 22:57:12 +00:00
add TestPersistentPreRunHooksForCompletionCommand
This commit is contained in:
parent
ba4e21df7a
commit
3bb59c6775
1 changed files with 25 additions and 0 deletions
|
@ -2460,6 +2460,31 @@ func TestDefaultCompletionCmd(t *testing.T) {
|
||||||
removeCompCmd(rootCmd)
|
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) {
|
func TestCompleteCompletion(t *testing.T) {
|
||||||
rootCmd := &Command{Use: "root", Args: NoArgs, Run: emptyRun}
|
rootCmd := &Command{Use: "root", Args: NoArgs, Run: emptyRun}
|
||||||
subCmd := &Command{
|
subCmd := &Command{
|
||||||
|
|
Loading…
Reference in a new issue