(t *testing.T)
| 82 | } |
| 83 | |
| 84 | func TestActiveHelpWithComps(t *testing.T) { |
| 85 | rootCmd := &Command{ |
| 86 | Use: "root", |
| 87 | Run: emptyRun, |
| 88 | } |
| 89 | |
| 90 | childCmd := &Command{ |
| 91 | Use: "thechild", |
| 92 | Short: "The child command", |
| 93 | Run: emptyRun, |
| 94 | } |
| 95 | rootCmd.AddCommand(childCmd) |
| 96 | |
| 97 | // Test that activeHelp can be added following other completions |
| 98 | childCmd.ValidArgsFunction = func(cmd *Command, args []string, toComplete string) ([]string, ShellCompDirective) { |
| 99 | comps := []string{"first", "second"} |
| 100 | comps = AppendActiveHelp(comps, activeHelpMessage) |
| 101 | return comps, ShellCompDirectiveDefault |
| 102 | } |
| 103 | |
| 104 | output, err := executeCommand(rootCmd, ShellCompNoDescRequestCmd, "thechild", "") |
| 105 | if err != nil { |
| 106 | t.Errorf("Unexpected error: %v", err) |
| 107 | } |
| 108 | |
| 109 | expected := strings.Join([]string{ |
| 110 | "first", |
| 111 | "second", |
| 112 | fmt.Sprintf("%s%s", activeHelpMarker, activeHelpMessage), |
| 113 | ":0", |
| 114 | "Completion ended with directive: ShellCompDirectiveDefault", ""}, "\n") |
| 115 | |
| 116 | if output != expected { |
| 117 | t.Errorf("expected: %q, got: %q", expected, output) |
| 118 | } |
| 119 | |
| 120 | // Test that activeHelp can be added preceding other completions |
| 121 | childCmd.ValidArgsFunction = func(cmd *Command, args []string, toComplete string) ([]string, ShellCompDirective) { |
| 122 | var comps []string |
| 123 | comps = AppendActiveHelp(comps, activeHelpMessage) |
| 124 | comps = append(comps, []string{"first", "second"}...) |
| 125 | return comps, ShellCompDirectiveDefault |
| 126 | } |
| 127 | |
| 128 | output, err = executeCommand(rootCmd, ShellCompNoDescRequestCmd, "thechild", "") |
| 129 | if err != nil { |
| 130 | t.Errorf("Unexpected error: %v", err) |
| 131 | } |
| 132 | |
| 133 | expected = strings.Join([]string{ |
| 134 | fmt.Sprintf("%s%s", activeHelpMarker, activeHelpMessage), |
| 135 | "first", |
| 136 | "second", |
| 137 | ":0", |
| 138 | "Completion ended with directive: ShellCompDirectiveDefault", ""}, "\n") |
| 139 | |
| 140 | if output != expected { |
| 141 | t.Errorf("expected: %q, got: %q", expected, output) |
nothing calls this directly
no test coverage detected