docker_cli_help_test.go 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. package main
  2. import (
  3. "os"
  4. "os/exec"
  5. "runtime"
  6. "strings"
  7. "testing"
  8. )
  9. func TestMainHelpWidth(t *testing.T) {
  10. // Make sure main help text fits within 80 chars and that
  11. // on non-windows system we use ~ when possible (to shorten things)
  12. var home string
  13. if runtime.GOOS != "windows" {
  14. home = os.Getenv("HOME")
  15. }
  16. helpCmd := exec.Command(dockerBinary, "help")
  17. out, ec, err := runCommandWithOutput(helpCmd)
  18. if err != nil || ec != 0 {
  19. t.Fatalf("docker help should have worked\nout:%s\nec:%d", out, ec)
  20. }
  21. lines := strings.Split(out, "\n")
  22. for _, line := range lines {
  23. if len(line) > 80 {
  24. t.Fatalf("Line is too long(%d chars):\n%s", len(line), line)
  25. }
  26. if home != "" && strings.Contains(line, home) {
  27. t.Fatalf("Line should use ~ instead of %q:\n%s", home, line)
  28. }
  29. }
  30. logDone("help - verify main width")
  31. }
  32. func TestCmdHelpWidth(t *testing.T) {
  33. // Make sure main help text fits within 80 chars and that
  34. // on non-windows system we use ~ when possible (to shorten things)
  35. var home string
  36. if runtime.GOOS != "windows" {
  37. home = os.Getenv("HOME")
  38. }
  39. for _, command := range []string{
  40. "attach",
  41. "build",
  42. "commit",
  43. "cp",
  44. "create",
  45. "diff",
  46. "events",
  47. "exec",
  48. "export",
  49. "history",
  50. "images",
  51. "import",
  52. "info",
  53. "inspect",
  54. "kill",
  55. "load",
  56. "login",
  57. "logout",
  58. "logs",
  59. "port",
  60. "pause",
  61. "ps",
  62. "pull",
  63. "push",
  64. "rename",
  65. "restart",
  66. "rm",
  67. "rmi",
  68. "run",
  69. "save",
  70. "search",
  71. "start",
  72. "stats",
  73. "stop",
  74. "tag",
  75. "top",
  76. "unpause",
  77. "version",
  78. "wait",
  79. } {
  80. helpCmd := exec.Command(dockerBinary, command, "--help")
  81. out, ec, err := runCommandWithOutput(helpCmd)
  82. if err != nil || ec != 0 {
  83. t.Fatalf("docker help should have worked\nout:%s\nec:%d", out, ec)
  84. }
  85. lines := strings.Split(out, "\n")
  86. for _, line := range lines {
  87. if len(line) > 80 {
  88. t.Fatalf("Help for %q is too long(%d chars):\n%s", command, len(line), line)
  89. }
  90. if home != "" && strings.Contains(line, home) {
  91. t.Fatalf("Help for %q should use ~ instead of %q on:\n%s", command, home, line)
  92. }
  93. }
  94. }
  95. logDone("help - cmd widths")
  96. }