You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

115 lines
2.6 KiB

  1. #!/usr/bin/env bats
  2. load test_helper
  3. create_version() {
  4. mkdir -p "${PYENV_ROOT}/versions/$1"
  5. }
  6. setup() {
  7. mkdir -p "$PYENV_TEST_DIR"
  8. cd "$PYENV_TEST_DIR"
  9. }
  10. @test "no version selected" {
  11. assert [ ! -d "${PYENV_ROOT}/versions" ]
  12. run pyenv-version-name
  13. assert_success "system"
  14. }
  15. @test "system version is not checked for existance" {
  16. PYENV_VERSION=system run pyenv-version-name
  17. assert_success "system"
  18. }
  19. @test "PYENV_VERSION can be overridden by hook" {
  20. create_version "2.7.11"
  21. create_version "3.5.1"
  22. create_hook version-name test.bash <<<"PYENV_VERSION=3.5.1"
  23. PYENV_VERSION=2.7.11 run pyenv-version-name
  24. assert_success "3.5.1"
  25. }
  26. @test "carries original IFS within hooks" {
  27. create_hook version-name hello.bash <<SH
  28. hellos=(\$(printf "hello\\tugly world\\nagain"))
  29. echo HELLO="\$(printf ":%s" "\${hellos[@]}")"
  30. SH
  31. export PYENV_VERSION=system
  32. IFS=$' \t\n' run pyenv-version-name env
  33. assert_success
  34. assert_line "HELLO=:hello:ugly:world:again"
  35. }
  36. @test "PYENV_VERSION has precedence over local" {
  37. create_version "2.7.11"
  38. create_version "3.5.1"
  39. cat > ".python-version" <<<"2.7.11"
  40. run pyenv-version-name
  41. assert_success "2.7.11"
  42. PYENV_VERSION=3.5.1 run pyenv-version-name
  43. assert_success "3.5.1"
  44. }
  45. @test "local file has precedence over global" {
  46. create_version "2.7.11"
  47. create_version "3.5.1"
  48. cat > "${PYENV_ROOT}/version" <<<"2.7.11"
  49. run pyenv-version-name
  50. assert_success "2.7.11"
  51. cat > ".python-version" <<<"3.5.1"
  52. run pyenv-version-name
  53. assert_success "3.5.1"
  54. }
  55. @test "missing version" {
  56. PYENV_VERSION=1.2 run pyenv-version-name
  57. assert_failure "pyenv: version \`1.2' is not installed (set by PYENV_VERSION environment variable)"
  58. }
  59. @test "one missing version (second missing)" {
  60. create_version "3.5.1"
  61. PYENV_VERSION="3.5.1:1.2" run pyenv-version-name
  62. assert_failure
  63. assert_output <<OUT
  64. pyenv: version \`1.2' is not installed (set by PYENV_VERSION environment variable)
  65. 3.5.1
  66. OUT
  67. }
  68. @test "one missing version (first missing)" {
  69. create_version "3.5.1"
  70. PYENV_VERSION="1.2:3.5.1" run pyenv-version-name
  71. assert_failure
  72. assert_output <<OUT
  73. pyenv: version \`1.2' is not installed (set by PYENV_VERSION environment variable)
  74. 3.5.1
  75. OUT
  76. }
  77. pyenv-version-name-without-stderr() {
  78. pyenv-version-name 2>/dev/null
  79. }
  80. @test "one missing version (without stderr)" {
  81. create_version "3.5.1"
  82. PYENV_VERSION="1.2:3.5.1" run pyenv-version-name-without-stderr
  83. assert_failure
  84. assert_output <<OUT
  85. 3.5.1
  86. OUT
  87. }
  88. @test "version with prefix in name" {
  89. create_version "2.7.11"
  90. cat > ".python-version" <<<"python-2.7.11"
  91. run pyenv-version-name
  92. assert_success
  93. assert_output "2.7.11"
  94. }