better error message for rbenv prefix system

Have `rbenv prefix` handle the case where system Ruby is not installed,
i.e. `rbenv which ruby` doesn't find ruby in PATH.

Fixes #362
This commit is contained in:
Mislav Marohnić 2013-10-03 21:42:52 +02:00
parent 16c3e0ddac
commit f4fade3d26
2 changed files with 22 additions and 4 deletions

View file

@ -22,10 +22,14 @@ elif [ -z "$RBENV_VERSION" ]; then
fi fi
if [ "$RBENV_VERSION" = "system" ]; then if [ "$RBENV_VERSION" = "system" ]; then
RUBY_PATH="$(rbenv-which ruby)" if RUBY_PATH="$(rbenv-which ruby 2>/dev/null)"; then
RUBY_PATH="${RUBY_PATH%/*}" RUBY_PATH="${RUBY_PATH%/*}"
echo "${RUBY_PATH%/bin}" echo "${RUBY_PATH%/bin}"
exit exit
else
echo "rbenv: system version not found in PATH" >&2
exit 1
fi
fi fi
RBENV_PREFIX_PATH="${RBENV_ROOT}/versions/${RBENV_VERSION}" RBENV_PREFIX_PATH="${RBENV_ROOT}/versions/${RBENV_VERSION}"

View file

@ -23,3 +23,17 @@ load test_helper
RBENV_VERSION="system" run rbenv-prefix RBENV_VERSION="system" run rbenv-prefix
assert_success "$RBENV_TEST_DIR" assert_success "$RBENV_TEST_DIR"
} }
@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
assert_failure "rbenv: system version not found in PATH"
}