(t *testing.T)
| 2605 | } |
| 2606 | |
| 2607 | func TestCompleteCompletion(t *testing.T) { |
| 2608 | rootCmd := &Command{Use: "root", Args: NoArgs, Run: emptyRun} |
| 2609 | |
| 2610 | // Test that when there are no sub-commands, the 'completion' command is not completed |
| 2611 | // (because it is not created). |
| 2612 | output, err := executeCommand(rootCmd, ShellCompNoDescRequestCmd, "completion") |
| 2613 | if err != nil { |
| 2614 | t.Errorf("Unexpected error: %v", err) |
| 2615 | } |
| 2616 | |
| 2617 | expected := strings.Join([]string{ |
| 2618 | ":0", |
| 2619 | "Completion ended with directive: ShellCompDirectiveDefault", ""}, "\n") |
| 2620 | |
| 2621 | if output != expected { |
| 2622 | t.Errorf("expected: %q, got: %q", expected, output) |
| 2623 | } |
| 2624 | |
| 2625 | // Test that when there are no sub-commands, completion can be triggered for the default |
| 2626 | // 'completion' command |
| 2627 | output, err = executeCommand(rootCmd, ShellCompNoDescRequestCmd, "completion", "") |
| 2628 | if err != nil { |
| 2629 | t.Errorf("Unexpected error: %v", err) |
| 2630 | } |
| 2631 | |
| 2632 | expected = strings.Join([]string{ |
| 2633 | "bash", |
| 2634 | "fish", |
| 2635 | "powershell", |
| 2636 | "zsh", |
| 2637 | ":4", |
| 2638 | "Completion ended with directive: ShellCompDirectiveNoFileComp", ""}, "\n") |
| 2639 | |
| 2640 | if output != expected { |
| 2641 | t.Errorf("expected: %q, got: %q", expected, output) |
| 2642 | } |
| 2643 | |
| 2644 | // Add a sub-command |
| 2645 | subCmd := &Command{ |
| 2646 | Use: "sub", |
| 2647 | Run: emptyRun, |
| 2648 | } |
| 2649 | rootCmd.AddCommand(subCmd) |
| 2650 | |
| 2651 | // Test sub-commands of the completion command |
| 2652 | output, err = executeCommand(rootCmd, ShellCompNoDescRequestCmd, "completion", "") |
| 2653 | if err != nil { |
| 2654 | t.Errorf("Unexpected error: %v", err) |
| 2655 | } |
| 2656 | |
| 2657 | expected = strings.Join([]string{ |
| 2658 | "bash", |
| 2659 | "fish", |
| 2660 | "powershell", |
| 2661 | "zsh", |
| 2662 | ":4", |
| 2663 | "Completion ended with directive: ShellCompDirectiveNoFileComp", ""}, "\n") |
| 2664 |
nothing calls this directly
no test coverage detected