123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104 |
- package main
- import (
- "os"
- "os/exec"
- "runtime"
- "strings"
- "testing"
- )
- func TestMainHelpWidth(t *testing.T) {
- // Make sure main help text fits within 80 chars and that
- // on non-windows system we use ~ when possible (to shorten things)
- var home string
- if runtime.GOOS != "windows" {
- home = os.Getenv("HOME")
- }
- helpCmd := exec.Command(dockerBinary, "help")
- out, ec, err := runCommandWithOutput(helpCmd)
- if err != nil || ec != 0 {
- t.Fatalf("docker help should have worked\nout:%s\nec:%d", out, ec)
- }
- lines := strings.Split(out, "\n")
- for _, line := range lines {
- if len(line) > 80 {
- t.Fatalf("Line is too long(%d chars):\n%s", len(line), line)
- }
- if home != "" && strings.Contains(line, home) {
- t.Fatalf("Line should use ~ instead of %q:\n%s", home, line)
- }
- }
- logDone("help - verify main width")
- }
- func TestCmdHelpWidth(t *testing.T) {
- // Make sure main help text fits within 80 chars and that
- // on non-windows system we use ~ when possible (to shorten things)
- var home string
- if runtime.GOOS != "windows" {
- home = os.Getenv("HOME")
- }
- for _, command := range []string{
- "attach",
- "build",
- "commit",
- "cp",
- "create",
- "diff",
- "events",
- "exec",
- "export",
- "history",
- "images",
- "import",
- "info",
- "inspect",
- "kill",
- "load",
- "login",
- "logout",
- "logs",
- "port",
- "pause",
- "ps",
- "pull",
- "push",
- "rename",
- "restart",
- "rm",
- "rmi",
- "run",
- "save",
- "search",
- "start",
- "stats",
- "stop",
- "tag",
- "top",
- "unpause",
- "version",
- "wait",
- } {
- helpCmd := exec.Command(dockerBinary, command, "--help")
- out, ec, err := runCommandWithOutput(helpCmd)
- if err != nil || ec != 0 {
- t.Fatalf("docker help should have worked\nout:%s\nec:%d", out, ec)
- }
- lines := strings.Split(out, "\n")
- for _, line := range lines {
- if len(line) > 80 {
- t.Fatalf("Help for %q is too long(%d chars):\n%s", command, len(line), line)
- }
- if home != "" && strings.Contains(line, home) {
- t.Fatalf("Help for %q should use ~ instead of %q on:\n%s", command, home, line)
- }
- }
- }
- logDone("help - cmd widths")
- }
|