Skip to content

Commit

Permalink
Add benchmark for GenBashCompletion
Browse files Browse the repository at this point in the history
  • Loading branch information
n10v committed May 18, 2017
1 parent de6b168 commit fb1f399
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions bash_completions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package cobra

import (
"bytes"
"io/ioutil"
"os"
"os/exec"
"strings"
Expand Down Expand Up @@ -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)
}
}
}

0 comments on commit fb1f399

Please sign in to comment.