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.

71 lines
1.8 KiB

  1. #!/usr/bin/env bats
  2. load test_helper
  3. create_hook() {
  4. mkdir -p "$1/$2"
  5. touch "$1/$2/$3"
  6. }
  7. @test "prints usage help given no argument" {
  8. run pyenv-hooks
  9. assert_failure "Usage: pyenv hooks <command>"
  10. }
  11. @test "prints list of hooks" {
  12. path1="${PYENV_TEST_DIR}/pyenv.d"
  13. path2="${PYENV_TEST_DIR}/etc/pyenv_hooks"
  14. create_hook "$path1" exec "hello.bash"
  15. create_hook "$path1" exec "ahoy.bash"
  16. create_hook "$path1" exec "invalid.sh"
  17. create_hook "$path1" which "boom.bash"
  18. create_hook "$path2" exec "bueno.bash"
  19. PYENV_HOOK_PATH="$path1:$path2" run pyenv-hooks exec
  20. assert_success
  21. assert_output <<OUT
  22. ${PYENV_TEST_DIR}/pyenv.d/exec/ahoy.bash
  23. ${PYENV_TEST_DIR}/pyenv.d/exec/hello.bash
  24. ${PYENV_TEST_DIR}/etc/pyenv_hooks/exec/bueno.bash
  25. OUT
  26. }
  27. @test "supports hook paths with spaces" {
  28. path1="${PYENV_TEST_DIR}/my hooks/pyenv.d"
  29. path2="${PYENV_TEST_DIR}/etc/pyenv hooks"
  30. create_hook "$path1" exec "hello.bash"
  31. create_hook "$path2" exec "ahoy.bash"
  32. PYENV_HOOK_PATH="$path1:$path2" run pyenv-hooks exec
  33. assert_success
  34. assert_output <<OUT
  35. ${PYENV_TEST_DIR}/my hooks/pyenv.d/exec/hello.bash
  36. ${PYENV_TEST_DIR}/etc/pyenv hooks/exec/ahoy.bash
  37. OUT
  38. }
  39. @test "resolves relative paths" {
  40. path="${PYENV_TEST_DIR}/pyenv.d"
  41. create_hook "$path" exec "hello.bash"
  42. mkdir -p "$HOME"
  43. PYENV_HOOK_PATH="${HOME}/../pyenv.d" run pyenv-hooks exec
  44. assert_success "${PYENV_TEST_DIR}/pyenv.d/exec/hello.bash"
  45. }
  46. @test "resolves symlinks" {
  47. path="${PYENV_TEST_DIR}/pyenv.d"
  48. mkdir -p "${path}/exec"
  49. mkdir -p "$HOME"
  50. touch "${HOME}/hola.bash"
  51. ln -s "../../home/hola.bash" "${path}/exec/hello.bash"
  52. touch "${path}/exec/bright.sh"
  53. ln -s "bright.sh" "${path}/exec/world.bash"
  54. PYENV_HOOK_PATH="$path" run pyenv-hooks exec
  55. assert_success
  56. assert_output <<OUT
  57. ${HOME}/hola.bash
  58. ${PYENV_TEST_DIR}/pyenv.d/exec/bright.sh
  59. OUT
  60. }