forked from mirror/cobra
Add benchmark for GenBashCompletion
This commit is contained in:
parent
de6b168d98
commit
fb1f39915d
|
@ -2,6 +2,7 @@ package cobra
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"strings"
|
"strings"
|
||||||
|
@ -174,3 +175,22 @@ func TestBashCompletionDeprecatedFlag(t *testing.T) {
|
||||||
t.Errorf("expected completion to not include %q flag: Got %v", flagName, bashCompletion)
|
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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue