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.

109 rivejä
2.3 KiB

  1. #!/usr/bin/env bats
  2. load test_helper
  3. create_executable() {
  4. name="${1?}"
  5. shift 1
  6. bin="${PYENV_ROOT}/versions/${PYENV_VERSION}/bin"
  7. mkdir -p "$bin"
  8. { if [ $# -eq 0 ]; then cat -
  9. else echo "$@"
  10. fi
  11. } | sed -Ee '1s/^ +//' > "${bin}/$name"
  12. chmod +x "${bin}/$name"
  13. }
  14. @test "fails with invalid version" {
  15. export PYENV_VERSION="3.4"
  16. run pyenv-exec python -V
  17. assert_failure "pyenv: version \`3.4' is not installed (set by PYENV_VERSION environment variable)"
  18. }
  19. @test "fails with invalid version set from file" {
  20. mkdir -p "$PYENV_TEST_DIR"
  21. cd "$PYENV_TEST_DIR"
  22. echo 2.7 > .python-version
  23. run pyenv-exec rspec
  24. assert_failure "pyenv: version \`2.7' is not installed (set by $PWD/.python-version)"
  25. }
  26. @test "completes with names of executables" {
  27. export PYENV_VERSION="3.4"
  28. create_executable "fab" "#!/bin/sh"
  29. create_executable "python" "#!/bin/sh"
  30. pyenv-rehash
  31. run pyenv-completions exec
  32. assert_success
  33. assert_output <<OUT
  34. --help
  35. fab
  36. python
  37. OUT
  38. }
  39. @test "carries original IFS within hooks" {
  40. create_hook exec hello.bash <<SH
  41. hellos=(\$(printf "hello\\tugly world\\nagain"))
  42. echo HELLO="\$(printf ":%s" "\${hellos[@]}")"
  43. SH
  44. export PYENV_VERSION=system
  45. IFS=$' \t\n' run pyenv-exec env
  46. assert_success
  47. assert_line "HELLO=:hello:ugly:world:again"
  48. }
  49. @test "forwards all arguments" {
  50. export PYENV_VERSION="3.4"
  51. create_executable "python" <<SH
  52. #!$BASH
  53. echo \$0
  54. for arg; do
  55. # hack to avoid bash builtin echo which can't output '-e'
  56. printf " %s\\n" "\$arg"
  57. done
  58. SH
  59. run pyenv-exec python -w "/path to/python script.rb" -- extra args
  60. assert_success
  61. assert_output <<OUT
  62. ${PYENV_ROOT}/versions/3.4/bin/python
  63. -w
  64. /path to/python script.rb
  65. --
  66. extra
  67. args
  68. OUT
  69. }
  70. @test "supports python -S <cmd>" {
  71. export PYENV_VERSION="3.4"
  72. # emulate `python -S' behavior
  73. create_executable "python" <<SH
  74. #!$BASH
  75. if [[ \$1 == "-S"* ]]; then
  76. found="\$(PATH="\${PYTHONPATH:-\$PATH}" which \$2)"
  77. # assert that the found executable has python for shebang
  78. if head -1 "\$found" | grep python >/dev/null; then
  79. \$BASH "\$found"
  80. else
  81. echo "python: no Python script found in input (LoadError)" >&2
  82. exit 1
  83. fi
  84. else
  85. echo 'python 3.4 (pyenv test)'
  86. fi
  87. SH
  88. create_executable "fab" <<SH
  89. #!/usr/bin/env python
  90. echo hello fab
  91. SH
  92. pyenv-rehash
  93. run python -S fab
  94. assert_success "hello fab"
  95. }