From 10b0388a6e2b8097ddc11fa05c1dd717a60c4512 Mon Sep 17 00:00:00 2001 From: Jun Nishimura Date: Sun, 9 Jul 2023 16:12:28 +0900 Subject: [PATCH] add test to check required flags will be ignored for bash, zsh, fish, powershell completion --- completions_test.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/completions_test.go b/completions_test.go index 0588da0f..c9274a8a 100644 --- a/completions_test.go +++ b/completions_test.go @@ -2447,6 +2447,17 @@ func TestDefaultCompletionCmd(t *testing.T) { rootCmd.CompletionOptions.HiddenDefaultCmd = false // Remove completion command for the next test removeCompCmd(rootCmd) + + // Test that required flag will be ignored + rootCmd.PersistentFlags().Bool("foo", false, "") + assertNoErr(t, rootCmd.MarkPersistentFlagRequired("foo")) + for _, shell := range []string{"bash", "fish", "powershell", "zsh"} { + if _, err = executeCommand(rootCmd, compCmdName, shell); err != nil { + t.Errorf("Unexpected error: %v", err) + } + } + // Remove completion command for the next test + removeCompCmd(rootCmd) } func TestCompleteCompletion(t *testing.T) {