Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.

91 righe
2.1 KiB

  1. #!/usr/bin/env bats
  2. load test_helper
  3. @test "shell integration disabled" {
  4. run pyenv shell
  5. assert_failure "pyenv: shell integration not enabled. Run \`pyenv init' for instructions."
  6. }
  7. @test "shell integration enabled" {
  8. eval "$(pyenv init -)"
  9. run pyenv shell
  10. assert_success "pyenv: no shell-specific version configured"
  11. }
  12. @test "no shell version" {
  13. mkdir -p "${PYENV_TEST_DIR}/myproject"
  14. cd "${PYENV_TEST_DIR}/myproject"
  15. echo "1.2.3" > .python-version
  16. PYENV_VERSION="" run pyenv-sh-shell
  17. assert_failure "pyenv: no shell-specific version configured"
  18. }
  19. @test "shell version" {
  20. PYENV_SHELL=bash PYENV_VERSION="1.2.3" run pyenv-sh-shell
  21. assert_success 'echo "$PYENV_VERSION"'
  22. }
  23. @test "shell version (fish)" {
  24. PYENV_SHELL=fish PYENV_VERSION="1.2.3" run pyenv-sh-shell
  25. assert_success 'echo "$PYENV_VERSION"'
  26. }
  27. @test "shell revert" {
  28. PYENV_SHELL=bash run pyenv-sh-shell -
  29. assert_success
  30. assert_line 0 'if [ -n "${PYENV_VERSION_OLD+x}" ]; then'
  31. }
  32. @test "shell revert (fish)" {
  33. PYENV_SHELL=fish run pyenv-sh-shell -
  34. assert_success
  35. assert_line 0 'if set -q PYENV_VERSION_OLD'
  36. }
  37. @test "shell unset" {
  38. PYENV_SHELL=bash run pyenv-sh-shell --unset
  39. assert_success
  40. assert_output <<OUT
  41. PYENV_VERSION_OLD="\${PYENV_VERSION-}"
  42. unset PYENV_VERSION
  43. OUT
  44. }
  45. @test "shell unset (fish)" {
  46. PYENV_SHELL=fish run pyenv-sh-shell --unset
  47. assert_success
  48. assert_output <<OUT
  49. set -gu PYENV_VERSION_OLD "\$PYENV_VERSION"
  50. set -e PYENV_VERSION
  51. OUT
  52. }
  53. @test "shell change invalid version" {
  54. run pyenv-sh-shell 1.2.3
  55. assert_failure
  56. assert_output <<SH
  57. pyenv: version \`1.2.3' not installed
  58. false
  59. SH
  60. }
  61. @test "shell change version" {
  62. mkdir -p "${PYENV_ROOT}/versions/1.2.3"
  63. PYENV_SHELL=bash run pyenv-sh-shell 1.2.3
  64. assert_success
  65. assert_output <<OUT
  66. PYENV_VERSION_OLD="\${PYENV_VERSION-}"
  67. export PYENV_VERSION="1.2.3"
  68. OUT
  69. }
  70. @test "shell change version (fish)" {
  71. mkdir -p "${PYENV_ROOT}/versions/1.2.3"
  72. PYENV_SHELL=fish run pyenv-sh-shell 1.2.3
  73. assert_success
  74. assert_output <<OUT
  75. set -gu PYENV_VERSION_OLD "\$PYENV_VERSION"
  76. set -gx PYENV_VERSION "1.2.3"
  77. OUT
  78. }