diff --git a/bash_completions_test.go b/bash_completions_test.go index 50fbe09..a626360 100644 --- a/bash_completions_test.go +++ b/bash_completions_test.go @@ -2,6 +2,7 @@ package cobra import ( "bytes" + "io/ioutil" "os" "os/exec" "strings" @@ -174,3 +175,22 @@ func TestBashCompletionDeprecatedFlag(t *testing.T) { t.Errorf("expected completion to not include %q flag: Got %v", flagName, bashCompletion) } } + +func BenchmarkBashCompletion(b *testing.B) { + c := initializeWithRootCmd() + cmdEcho.AddCommand(cmdTimes) + c.AddCommand(cmdEcho, cmdPrint, cmdDeprecated, cmdColon) + + file, err := ioutil.TempFile("", "") + if err != nil { + b.Fatal(err) + } + defer os.Remove(file.Name()) + + b.ResetTimer() + for i := 0; i < b.N; i++ { + if err := c.GenBashCompletion(file); err != nil { + b.Fatal(err) + } + } +}