mirror of
https://github.com/pyenv/pyenv.git
synced 2024-11-21 20:47:00 -05:00
commit
f4652fbbf0
2 changed files with 45 additions and 29 deletions
|
@ -15,40 +15,17 @@ if [ "$1" = "--complete" ]; then
|
||||||
exec rbenv shims --short
|
exec rbenv shims --short
|
||||||
fi
|
fi
|
||||||
|
|
||||||
expand_path() {
|
|
||||||
if [ ! -d "$1" ]; then
|
|
||||||
return 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
local cwd="$(pwd)"
|
|
||||||
cd "$1"
|
|
||||||
pwd
|
|
||||||
cd "$cwd"
|
|
||||||
}
|
|
||||||
|
|
||||||
remove_from_path() {
|
remove_from_path() {
|
||||||
local path_to_remove="$(expand_path "$1")"
|
local path_to_remove="$1"
|
||||||
local result=""
|
local path_before
|
||||||
|
local result=":$PATH:"
|
||||||
if [ -z "$path_to_remove" ]; then
|
while [ "$path_before" != "$result" ]; do
|
||||||
echo "${PATH}"
|
path_before="$result"
|
||||||
return
|
result="${result//:$path_to_remove:/:}"
|
||||||
fi
|
|
||||||
|
|
||||||
local paths
|
|
||||||
IFS=: paths=($PATH)
|
|
||||||
|
|
||||||
for path in "${paths[@]}"; do
|
|
||||||
path="$(expand_path "$path" || true)"
|
|
||||||
if [ -n "$path" ] && [ "$path" != "$path_to_remove" ]; then
|
|
||||||
result="${result}${path}:"
|
|
||||||
fi
|
|
||||||
done
|
done
|
||||||
|
|
||||||
echo "${result%:}"
|
echo "${result%:}"
|
||||||
}
|
}
|
||||||
|
|
||||||
RBENV_VERSION="$(rbenv-version-name)"
|
|
||||||
RBENV_COMMAND="$1"
|
RBENV_COMMAND="$1"
|
||||||
|
|
||||||
if [ -z "$RBENV_COMMAND" ]; then
|
if [ -z "$RBENV_COMMAND" ]; then
|
||||||
|
@ -56,6 +33,8 @@ if [ -z "$RBENV_COMMAND" ]; then
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
RBENV_VERSION="${RBENV_VERSION:-$(rbenv-version-name)}"
|
||||||
|
|
||||||
if [ "$RBENV_VERSION" = "system" ]; then
|
if [ "$RBENV_VERSION" = "system" ]; then
|
||||||
PATH="$(remove_from_path "${RBENV_ROOT}/shims")"
|
PATH="$(remove_from_path "${RBENV_ROOT}/shims")"
|
||||||
RBENV_COMMAND_PATH="$(command -v "$RBENV_COMMAND" || true)"
|
RBENV_COMMAND_PATH="$(command -v "$RBENV_COMMAND" || true)"
|
||||||
|
@ -72,6 +51,9 @@ done
|
||||||
|
|
||||||
if [ -x "$RBENV_COMMAND_PATH" ]; then
|
if [ -x "$RBENV_COMMAND_PATH" ]; then
|
||||||
echo "$RBENV_COMMAND_PATH"
|
echo "$RBENV_COMMAND_PATH"
|
||||||
|
elif ! [ -d "${RBENV_ROOT}/versions/${RBENV_VERSION}" ]; then
|
||||||
|
echo "rbenv: version \`$RBENV_VERSION' is not installed" >&2
|
||||||
|
exit 1
|
||||||
else
|
else
|
||||||
echo "rbenv: $RBENV_COMMAND: command not found" >&2
|
echo "rbenv: $RBENV_COMMAND: command not found" >&2
|
||||||
|
|
||||||
|
|
|
@ -31,6 +31,31 @@ create_executable() {
|
||||||
assert_success "${RBENV_TEST_DIR}/bin/kill-all-humans"
|
assert_success "${RBENV_TEST_DIR}/bin/kill-all-humans"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@test "searches PATH for system version (shims prepended)" {
|
||||||
|
create_executable "${RBENV_TEST_DIR}/bin" "kill-all-humans"
|
||||||
|
create_executable "${RBENV_ROOT}/shims" "kill-all-humans"
|
||||||
|
|
||||||
|
PATH="${RBENV_ROOT}/shims:$PATH" RBENV_VERSION=system run rbenv-which kill-all-humans
|
||||||
|
assert_success "${RBENV_TEST_DIR}/bin/kill-all-humans"
|
||||||
|
}
|
||||||
|
|
||||||
|
@test "searches PATH for system version (shims appended)" {
|
||||||
|
create_executable "${RBENV_TEST_DIR}/bin" "kill-all-humans"
|
||||||
|
create_executable "${RBENV_ROOT}/shims" "kill-all-humans"
|
||||||
|
|
||||||
|
PATH="$PATH:${RBENV_ROOT}/shims" RBENV_VERSION=system run rbenv-which kill-all-humans
|
||||||
|
assert_success "${RBENV_TEST_DIR}/bin/kill-all-humans"
|
||||||
|
}
|
||||||
|
|
||||||
|
@test "searches PATH for system version (shims spread)" {
|
||||||
|
create_executable "${RBENV_TEST_DIR}/bin" "kill-all-humans"
|
||||||
|
create_executable "${RBENV_ROOT}/shims" "kill-all-humans"
|
||||||
|
|
||||||
|
PATH="${RBENV_ROOT}/shims:${RBENV_ROOT}/shims:/tmp/non-existent:$PATH:${RBENV_ROOT}/shims" \
|
||||||
|
RBENV_VERSION=system run rbenv-which kill-all-humans
|
||||||
|
assert_success "${RBENV_TEST_DIR}/bin/kill-all-humans"
|
||||||
|
}
|
||||||
|
|
||||||
@test "version not installed" {
|
@test "version not installed" {
|
||||||
create_executable "2.0" "rspec"
|
create_executable "2.0" "rspec"
|
||||||
RBENV_VERSION=1.9 run rbenv-which rspec
|
RBENV_VERSION=1.9 run rbenv-which rspec
|
||||||
|
@ -72,3 +97,12 @@ SH
|
||||||
assert_success
|
assert_success
|
||||||
assert_output "HELLO=:hello:ugly:world:again"
|
assert_output "HELLO=:hello:ugly:world:again"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@test "discovers version from rbenv-version-name" {
|
||||||
|
mkdir -p "$RBENV_ROOT"
|
||||||
|
cat > "${RBENV_ROOT}/version" <<<"1.8"
|
||||||
|
create_executable "1.8" "ruby"
|
||||||
|
|
||||||
|
RBENV_VERSION= run rbenv-which ruby
|
||||||
|
assert_success "${RBENV_ROOT}/versions/1.8/bin/ruby"
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue