Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

115 Zeilen
2.8 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 "command 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. SHELL=/bin/false run pyenv-init -
  24. assert_success
  25. assert_line "export PYENV_SHELL=bash"
  26. }
  27. @test "detect parent shell from script" {
  28. mkdir -p "$PYENV_TEST_DIR"
  29. cd "$PYENV_TEST_DIR"
  30. cat > myscript.sh <<OUT
  31. #!/bin/sh
  32. eval "\$(pyenv-init -)"
  33. echo \$PYENV_SHELL
  34. OUT
  35. chmod +x myscript.sh
  36. run ./myscript.sh
  37. assert_success "sh"
  38. }
  39. @test "setup shell completions (fish)" {
  40. root="$(cd $BATS_TEST_DIRNAME/.. && pwd)"
  41. run pyenv-init - fish
  42. assert_success
  43. assert_line "source '${root}/test/../libexec/../completions/pyenv.fish'"
  44. }
  45. @test "fish instructions" {
  46. run pyenv-init fish
  47. assert [ "$status" -eq 1 ]
  48. assert_line 'pyenv init - | source'
  49. }
  50. @test "option to skip rehash" {
  51. run pyenv-init - --no-rehash
  52. assert_success
  53. refute_line "pyenv rehash 2>/dev/null"
  54. }
  55. @test "adds shims to PATH" {
  56. export PATH="${BATS_TEST_DIRNAME}/../libexec:/usr/bin:/bin:/usr/local/bin"
  57. run pyenv-init --path bash
  58. assert_success
  59. assert_line 0 'export PATH="'${PYENV_ROOT}'/shims:${PATH}"'
  60. }
  61. @test "adds shims to PATH (fish)" {
  62. export PATH="${BATS_TEST_DIRNAME}/../libexec:/usr/bin:/bin:/usr/local/bin"
  63. run pyenv-init --path fish
  64. assert_success
  65. assert_line 0 "set -gx PATH '${PYENV_ROOT}/shims' \$PATH"
  66. }
  67. @test "can add shims to PATH more than once" {
  68. export PATH="${PYENV_ROOT}/shims:$PATH"
  69. run pyenv-init --path bash
  70. assert_success
  71. assert_line 0 'export PATH="'${PYENV_ROOT}'/shims:${PATH}"'
  72. }
  73. @test "can add shims to PATH more than once (fish)" {
  74. export PATH="${PYENV_ROOT}/shims:$PATH"
  75. run pyenv-init --path fish
  76. assert_success
  77. assert_line 0 "set -gx PATH '${PYENV_ROOT}/shims' \$PATH"
  78. }
  79. @test "prints a warning if shims not in PATH" {
  80. export PATH="$(perl -0x3A -ls -e 'while (<>) { chomp; ($_ ne $d) && print; }' -- -d="${PYENV_ROOT}/shims" <<<"$PATH")"
  81. run pyenv-init -
  82. assert_success
  83. assert_line 0 'echo '\''WARNING: `pyenv init -` no longer sets PATH.'\'
  84. }
  85. @test "outputs sh-compatible syntax" {
  86. run pyenv-init - bash
  87. assert_success
  88. assert_line ' case "$command" in'
  89. run pyenv-init - zsh
  90. assert_success
  91. assert_line ' case "$command" in'
  92. }
  93. @test "outputs fish-specific syntax (fish)" {
  94. run pyenv-init - fish
  95. assert_success
  96. assert_line ' switch "$command"'
  97. refute_line ' case "$command" in'
  98. }