25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.

209 satır
4.5 KiB

10 yıl önce
10 yıl önce
  1. #!/usr/bin/env bats
  2. load test_helper
  3. export PYENV_ROOT="${TMP}/pyenv"
  4. setup() {
  5. stub pyenv-hooks 'install : true'
  6. stub pyenv-rehash 'true'
  7. }
  8. stub_python_build() {
  9. stub python-build "--lib : $BATS_TEST_DIRNAME/../bin/python-build --lib" "$@"
  10. }
  11. @test "install proper" {
  12. stub_python_build 'echo python-build "$@"'
  13. run pyenv-install 3.4.2
  14. assert_success "python-build 3.4.2 ${PYENV_ROOT}/versions/3.4.2"
  15. unstub python-build
  16. unstub pyenv-hooks
  17. unstub pyenv-rehash
  18. }
  19. @test "install pyenv local version by default" {
  20. stub_python_build 'echo python-build "$1"'
  21. stub pyenv-local 'echo 3.4.2'
  22. run pyenv-install
  23. assert_success "python-build 3.4.2"
  24. unstub python-build
  25. unstub pyenv-local
  26. }
  27. @test "list available versions" {
  28. stub_python_build \
  29. "--definitions : echo 2.6.9 2.7.9-rc1 2.7.9-rc2 3.4.2 | tr ' ' $'\\n'"
  30. run pyenv-install --list
  31. assert_success
  32. assert_output <<OUT
  33. Available versions:
  34. 2.6.9
  35. 2.7.9-rc1
  36. 2.7.9-rc2
  37. 3.4.2
  38. OUT
  39. unstub python-build
  40. }
  41. @test "nonexistent version" {
  42. stub brew false
  43. stub_python_build 'echo ERROR >&2 && exit 2' \
  44. "--definitions : echo 2.6.9 2.7.9-rc1 2.7.9-rc2 3.4.2 | tr ' ' $'\\n'"
  45. run pyenv-install 2.7.9
  46. assert_failure
  47. assert_output <<OUT
  48. ERROR
  49. The following versions contain \`2.7.9' in the name:
  50. 2.7.9-rc1
  51. 2.7.9-rc2
  52. See all available versions with \`pyenv install --list'.
  53. If the version you need is missing, try upgrading pyenv:
  54. cd ${BATS_TEST_DIRNAME}/../../.. && git pull && cd -
  55. OUT
  56. unstub python-build
  57. }
  58. @test "Homebrew upgrade instructions" {
  59. stub brew "--prefix : echo '${BATS_TEST_DIRNAME%/*}'"
  60. stub_python_build 'echo ERROR >&2 && exit 2' \
  61. "--definitions : true"
  62. run pyenv-install 1.9.3
  63. assert_failure
  64. assert_output <<OUT
  65. ERROR
  66. See all available versions with \`pyenv install --list'.
  67. If the version you need is missing, try upgrading pyenv:
  68. brew update && brew upgrade pyenv
  69. OUT
  70. unstub brew
  71. unstub python-build
  72. }
  73. @test "no build definitions from plugins" {
  74. assert [ ! -e "${PYENV_ROOT}/plugins" ]
  75. stub_python_build 'echo $PYTHON_BUILD_DEFINITIONS'
  76. run pyenv-install 3.4.2
  77. assert_success ""
  78. }
  79. @test "some build definitions from plugins" {
  80. mkdir -p "${PYENV_ROOT}/plugins/foo/share/python-build"
  81. mkdir -p "${PYENV_ROOT}/plugins/bar/share/python-build"
  82. stub_python_build "echo \$PYTHON_BUILD_DEFINITIONS | tr ':' $'\\n'"
  83. run pyenv-install 3.4.2
  84. assert_success
  85. assert_output <<OUT
  86. ${PYENV_ROOT}/plugins/bar/share/python-build
  87. ${PYENV_ROOT}/plugins/foo/share/python-build
  88. OUT
  89. }
  90. @test "list build definitions from plugins" {
  91. mkdir -p "${PYENV_ROOT}/plugins/foo/share/python-build"
  92. mkdir -p "${PYENV_ROOT}/plugins/bar/share/python-build"
  93. stub_python_build "--definitions : echo \$PYTHON_BUILD_DEFINITIONS | tr ':' $'\\n'"
  94. run pyenv-install --list
  95. assert_success
  96. assert_output <<OUT
  97. Available versions:
  98. ${PYENV_ROOT}/plugins/bar/share/python-build
  99. ${PYENV_ROOT}/plugins/foo/share/python-build
  100. OUT
  101. }
  102. @test "completion results include build definitions from plugins" {
  103. mkdir -p "${PYENV_ROOT}/plugins/foo/share/python-build"
  104. mkdir -p "${PYENV_ROOT}/plugins/bar/share/python-build"
  105. stub python-build "--definitions : echo \$PYTHON_BUILD_DEFINITIONS | tr ':' $'\\n'"
  106. run pyenv-install --complete
  107. assert_success
  108. assert_output <<OUT
  109. ${PYENV_ROOT}/plugins/bar/share/python-build
  110. ${PYENV_ROOT}/plugins/foo/share/python-build
  111. OUT
  112. }
  113. @test "not enough arguments for pyenv-install" {
  114. stub_python_build
  115. stub pyenv-help 'install : true'
  116. run pyenv-install
  117. assert_failure
  118. unstub pyenv-help
  119. }
  120. @test "too many arguments for pyenv-install" {
  121. stub_python_build
  122. stub pyenv-help 'install : true'
  123. run pyenv-install 3.4.1 3.4.2
  124. assert_failure
  125. unstub pyenv-help
  126. }
  127. @test "show help for pyenv-install" {
  128. stub_python_build
  129. stub pyenv-help 'install : true'
  130. run pyenv-install -h
  131. assert_success
  132. unstub pyenv-help
  133. }
  134. @test "pyenv-install has usage help preface" {
  135. run head "$(which pyenv-install)"
  136. assert_output_contains 'Usage: pyenv install'
  137. }
  138. @test "not enough arguments pyenv-uninstall" {
  139. stub pyenv-help 'uninstall : true'
  140. run pyenv-uninstall
  141. assert_failure
  142. unstub pyenv-help
  143. }
  144. @test "too many arguments for pyenv-uninstall" {
  145. stub pyenv-help 'uninstall : true'
  146. run pyenv-uninstall 3.4.1 3.4.2
  147. assert_failure
  148. unstub pyenv-help
  149. }
  150. @test "show help for pyenv-uninstall" {
  151. stub pyenv-help 'uninstall : true'
  152. run pyenv-uninstall -h
  153. assert_success
  154. unstub pyenv-help
  155. }
  156. @test "pyenv-uninstall has usage help preface" {
  157. run head "$(which pyenv-uninstall)"
  158. assert_output_contains 'Usage: pyenv uninstall'
  159. }