(t *testing.T)
| 229 | } |
| 230 | |
| 231 | func TestActiveHelpForFlag(t *testing.T) { |
| 232 | rootCmd := &Command{ |
| 233 | Use: "root", |
| 234 | Run: emptyRun, |
| 235 | } |
| 236 | flagname := "flag" |
| 237 | rootCmd.Flags().String(flagname, "", "A flag") |
| 238 | |
| 239 | // Test that multiple activeHelp message can be added |
| 240 | _ = rootCmd.RegisterFlagCompletionFunc(flagname, func(cmd *Command, args []string, toComplete string) ([]string, ShellCompDirective) { |
| 241 | comps := []string{"first"} |
| 242 | comps = AppendActiveHelp(comps, activeHelpMessage) |
| 243 | comps = append(comps, "second") |
| 244 | comps = AppendActiveHelp(comps, activeHelpMessage2) |
| 245 | return comps, ShellCompDirectiveNoFileComp |
| 246 | }) |
| 247 | |
| 248 | output, err := executeCommand(rootCmd, ShellCompNoDescRequestCmd, "--flag", "") |
| 249 | if err != nil { |
| 250 | t.Errorf("Unexpected error: %v", err) |
| 251 | } |
| 252 | |
| 253 | expected := strings.Join([]string{ |
| 254 | "first", |
| 255 | fmt.Sprintf("%s%s", activeHelpMarker, activeHelpMessage), |
| 256 | "second", |
| 257 | fmt.Sprintf("%s%s", activeHelpMarker, activeHelpMessage2), |
| 258 | ":4", |
| 259 | "Completion ended with directive: ShellCompDirectiveNoFileComp", ""}, "\n") |
| 260 | |
| 261 | if output != expected { |
| 262 | t.Errorf("expected: %q, got: %q", expected, output) |
| 263 | } |
| 264 | } |
| 265 | |
| 266 | func TestConfigActiveHelp(t *testing.T) { |
| 267 | rootCmd := &Command{ |
nothing calls this directly
no test coverage detected