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.

96 rivejä
2.4 KiB

  1. #!/usr/bin/env bats
  2. load test_helper
  3. @test "creates shims and versions directories" {
  4. assert [ ! -d "${PYENV_ROOT}/shims" ]
  5. assert [ ! -d "${PYENV_ROOT}/versions" ]
  6. run pyenv-init -
  7. assert_success
  8. assert [ -d "${PYENV_ROOT}/shims" ]
  9. assert [ -d "${PYENV_ROOT}/versions" ]
  10. }
  11. @test "auto rehash" {
  12. run pyenv-init -
  13. assert_success
  14. assert_line "pyenv rehash 2>/dev/null"
  15. }
  16. @test "setup shell completions" {
  17. root="$(cd $BATS_TEST_DIRNAME/.. && pwd)"
  18. run pyenv-init - bash
  19. assert_success
  20. assert_line "source '${root}/test/../libexec/../completions/pyenv.bash'"
  21. }
  22. @test "detect parent shell" {
  23. root="$(cd $BATS_TEST_DIRNAME/.. && pwd)"
  24. SHELL=/bin/false run pyenv-init -
  25. assert_success
  26. assert_line "export PYENV_SHELL=bash"
  27. }
  28. @test "setup shell completions (fish)" {
  29. root="$(cd $BATS_TEST_DIRNAME/.. && pwd)"
  30. run pyenv-init - fish
  31. assert_success
  32. assert_line ". '${root}/test/../libexec/../completions/pyenv.fish'"
  33. }
  34. @test "fish instructions" {
  35. run pyenv-init fish
  36. assert [ "$status" -eq 1 ]
  37. assert_line 'status --is-interactive; and . (pyenv init -|psub)'
  38. }
  39. @test "option to skip rehash" {
  40. run pyenv-init - --no-rehash
  41. assert_success
  42. refute_line "pyenv rehash 2>/dev/null"
  43. }
  44. @test "adds shims to PATH" {
  45. export PATH="${BATS_TEST_DIRNAME}/../libexec:/usr/bin:/bin:/usr/local/bin"
  46. run pyenv-init - bash
  47. assert_success
  48. assert_line 0 'export PATH="'${PYENV_ROOT}'/shims:${PATH}"'
  49. }
  50. @test "adds shims to PATH (fish)" {
  51. export PATH="${BATS_TEST_DIRNAME}/../libexec:/usr/bin:/bin:/usr/local/bin"
  52. run pyenv-init - fish
  53. assert_success
  54. assert_line 0 "setenv PATH '${PYENV_ROOT}/shims' \$PATH"
  55. }
  56. @test "can add shims to PATH more than once" {
  57. export PATH="${PYENV_ROOT}/shims:$PATH"
  58. run pyenv-init - bash
  59. assert_success
  60. assert_line 0 'export PATH="'${PYENV_ROOT}'/shims:${PATH}"'
  61. }
  62. @test "can add shims to PATH more than once (fish)" {
  63. export PATH="${PYENV_ROOT}/shims:$PATH"
  64. run pyenv-init - fish
  65. assert_success
  66. assert_line 0 "setenv PATH '${PYENV_ROOT}/shims' \$PATH"
  67. }
  68. @test "outputs sh-compatible syntax" {
  69. run pyenv-init - bash
  70. assert_success
  71. assert_line ' case "$command" in'
  72. run pyenv-init - zsh
  73. assert_success
  74. assert_line ' case "$command" in'
  75. }
  76. @test "outputs fish-specific syntax (fish)" {
  77. run pyenv-init - fish
  78. assert_success
  79. assert_line ' switch "$command"'
  80. refute_line ' case "$command" in'
  81. }