Make checking of help text smarter

As I was reworking https://github.com/docker/docker/pull/9402 I realized
that the new testcase I just added that verified all help text is within
80 characters really should be smarter and ask "docker help" for the list
of commands to check instead of having a hard-coded list.  This way
it will catch "docker execwait" automagically once #9402 is merged.

Signed-off-by: Doug Davis <dug@us.ibm.com>
This commit is contained in:
Doug Davis 2015-02-04 15:28:51 -08:00
parent 7cc9858223
commit 969ba5c7ed
1 changed files with 34 additions and 41 deletions

View File

@ -6,6 +6,7 @@ import (
"runtime" "runtime"
"strings" "strings"
"testing" "testing"
"unicode"
) )
func TestMainHelpWidth(t *testing.T) { func TestMainHelpWidth(t *testing.T) {
@ -43,47 +44,33 @@ func TestCmdHelpWidth(t *testing.T) {
home = os.Getenv("HOME") home = os.Getenv("HOME")
} }
for _, command := range []string{ // Pull the list of commands from the "Commands:" section of docker help
"attach", helpCmd := exec.Command(dockerBinary, "help")
"build", out, ec, err := runCommandWithOutput(helpCmd)
"commit", if err != nil || ec != 0 {
"cp", t.Fatalf("docker help should have worked\nout:%s\nec:%d", out, ec)
"create", }
"diff", i := strings.Index(out, "Commands:")
"events", if i < 0 {
"exec", t.Fatalf("Missing 'Commands:' in:\n%s", out)
"export", }
"history",
"images", // Grab all chars starting at "Commands:"
"import", // Skip first line, its "Commands:"
"info", count := 0
"inspect", cmds := ""
"kill", for _, command := range strings.Split(out[i:], "\n")[1:] {
"load", // Stop on blank line or non-idented line
"login", if command == "" || !unicode.IsSpace(rune(command[0])) {
"logout", break
"logs", }
"port",
"pause", // Grab just the first word of each line
"ps", command = strings.Split(strings.TrimSpace(command), " ")[0]
"pull",
"push", count++
"rename", cmds = cmds + "\n" + command
"restart",
"rm",
"rmi",
"run",
"save",
"search",
"start",
"stats",
"stop",
"tag",
"top",
"unpause",
"version",
"wait",
} {
helpCmd := exec.Command(dockerBinary, command, "--help") helpCmd := exec.Command(dockerBinary, command, "--help")
out, ec, err := runCommandWithOutput(helpCmd) out, ec, err := runCommandWithOutput(helpCmd)
if err != nil || ec != 0 { if err != nil || ec != 0 {
@ -100,5 +87,11 @@ func TestCmdHelpWidth(t *testing.T) {
} }
} }
expected := 39
if count != expected {
t.Fatalf("Wrong # of commands (%d), it should be: %d\nThe list:\n%s",
len(cmds), expected, cmds)
}
logDone("help - cmd widths") logDone("help - cmd widths")
} }