Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

122 строки
2.7 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 "supports hook path with spaces" {
  40. hook_path="${PYENV_TEST_DIR}/custom stuff/pyenv hooks"
  41. mkdir -p "${hook_path}/exec"
  42. echo "export HELLO='from hook'" > "${hook_path}/exec/hello.bash"
  43. export PYENV_VERSION=system
  44. PYENV_HOOK_PATH="$hook_path" run pyenv-exec env
  45. assert_success
  46. assert_line "HELLO=from hook"
  47. }
  48. @test "carries original IFS within hooks" {
  49. hook_path="${PYENV_TEST_DIR}/pyenv.d"
  50. mkdir -p "${hook_path}/exec"
  51. cat > "${hook_path}/exec/hello.bash" <<SH
  52. hellos=(\$(printf "hello\\tugly world\\nagain"))
  53. echo HELLO="\$(printf ":%s" "\${hellos[@]}")"
  54. SH
  55. export PYENV_VERSION=system
  56. PYENV_HOOK_PATH="$hook_path" IFS=$' \t\n' run pyenv-exec env
  57. assert_success
  58. assert_line "HELLO=:hello:ugly:world:again"
  59. }
  60. @test "forwards all arguments" {
  61. export PYENV_VERSION="3.4"
  62. create_executable "python" <<SH
  63. #!$BASH
  64. echo \$0
  65. for arg; do
  66. # hack to avoid bash builtin echo which can't output '-e'
  67. printf " %s\\n" "\$arg"
  68. done
  69. SH
  70. run pyenv-exec python -w "/path to/python script.rb" -- extra args
  71. assert_success
  72. assert_output <<OUT
  73. ${PYENV_ROOT}/versions/3.4/bin/python
  74. -w
  75. /path to/python script.rb
  76. --
  77. extra
  78. args
  79. OUT
  80. }
  81. @test "supports python -S <cmd>" {
  82. export PYENV_VERSION="3.4"
  83. # emulate `python -S' behavior
  84. create_executable "python" <<SH
  85. #!$BASH
  86. if [[ \$1 == "-S"* ]]; then
  87. found="\$(PATH="\${PYTHONPATH:-\$PATH}" which \$2)"
  88. # assert that the found executable has python for shebang
  89. if head -1 "\$found" | grep python >/dev/null; then
  90. \$BASH "\$found"
  91. else
  92. echo "python: no Python script found in input (LoadError)" >&2
  93. exit 1
  94. fi
  95. else
  96. echo 'python 3.4 (pyenv test)'
  97. fi
  98. SH
  99. create_executable "fab" <<SH
  100. #!/usr/bin/env python
  101. echo hello fab
  102. SH
  103. pyenv-rehash
  104. run python -S fab
  105. assert_success "hello fab"
  106. }