mirror of
https://github.com/spf13/cobra
synced 2024-11-24 22:57:12 +00:00
Add benchmark for GenBashCompletion
This commit is contained in:
parent
de6b168d98
commit
fb1f39915d
1 changed files with 20 additions and 0 deletions
|
@ -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 a new issue