diff --git a/test/prefix.bats b/test/prefix.bats index 0d6cdba6..3fb94086 100644 --- a/test/prefix.bats +++ b/test/prefix.bats @@ -25,15 +25,6 @@ load test_helper } @test "prefix for invalid system" { - USRBIN_ALT="${RBENV_TEST_DIR}/usr-bin-alt" - mkdir -p "$USRBIN_ALT" - for util in head readlink greadlink; do - if [ -x "/usr/bin/$util" ]; then - ln -s "/usr/bin/$util" "${USRBIN_ALT}/$util" - fi - done - PATH_WITHOUT_RUBY="${PATH/\/usr\/bin:/$USRBIN_ALT:}" - - PATH="$PATH_WITHOUT_RUBY" run rbenv-prefix system + PATH="$(path_without ruby)" run rbenv-prefix system assert_failure "rbenv: system version not found in PATH" } diff --git a/test/test_helper.bash b/test/test_helper.bash index 43b04d3b..53ae8e64 100644 --- a/test/test_helper.bash +++ b/test/test_helper.bash @@ -93,3 +93,25 @@ assert() { flunk "failed: $@" fi } + +# Output a modified PATH that ensures that the given executable is not present, +# but in which system utils necessary for rbenv operation are still available. +path_without() { + local exe="$1" + local path="${PATH}:" + local found alt util + for found in $(which -a "$exe"); do + found="${found%/*}" + if [ "$found" != "${RBENV_ROOT}/shims" ]; then + alt="${RBENV_TEST_DIR}/$(echo "${found#/}" | tr '/' '-')" + mkdir -p "$alt" + for util in bash head cut readlink greadlink; do + if [ -x "${found}/$util" ]; then + ln -s "${found}/$util" "${alt}/$util" + fi + done + path="${path/${found}:/${alt}:}" + fi + done + echo "${path%:}" +}