Add benchmark for GenBashCompletion

This commit is contained in:
Albert Nigmatzianov 2017-05-14 14:57:11 +02:00
parent de6b168d98
commit fb1f39915d

View file

@ -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)
}
}
}