mirror of
https://github.com/pyenv/pyenv.git
synced 2024-11-07 20:31:01 -05:00
add support for rbenv shell -
`rbenv shell -` allows you to switch to the previously activated ruby version. Similar to `cd -` or `git checkout -`. This tries to implement `rbenv shell -` as proposed in #854. However, adding support seemed to break the "shell change version" test. I'm not very good at Bash programming, can someone tell me what is wrong with what I'm doing? I'd like to add a bit more functionality to this, but I'm really just cargo cult programming Bash. Thank you! fix tests
This commit is contained in:
parent
c38833179b
commit
6a912bf104
2 changed files with 87 additions and 11 deletions
|
@ -39,25 +39,50 @@ fi
|
|||
if [ "$version" = "--unset" ]; then
|
||||
case "$shell" in
|
||||
fish )
|
||||
echo "set -e OLD_RBENV_VERSION"
|
||||
echo "set -e RBENV_VERSION"
|
||||
;;
|
||||
* )
|
||||
echo "unset OLD_RBENV_VERSION"
|
||||
echo "unset RBENV_VERSION"
|
||||
;;
|
||||
esac
|
||||
exit
|
||||
fi
|
||||
|
||||
if [ "$version" = "-" ]; then
|
||||
if [ -z "$OLD_RBENV_VERSION" ]; then
|
||||
echo "rbenv: OLD_RBENV_VERSION not set" >&2
|
||||
exit 1;
|
||||
fi
|
||||
case "$shell" in
|
||||
fish )
|
||||
rbenv_version=$RBENV_VERSION
|
||||
echo "set -e OLD_RBENV_VERSION \"$rbenv_version\""
|
||||
echo "set -e RBENV_VERSION \"$OLD_RBENV_VERSION\""
|
||||
;;
|
||||
* )
|
||||
rbenv_version=$RBENV_VERSION
|
||||
echo "export OLD_RBENV_VERSION=\"$rbenv_version\""
|
||||
echo "export RBENV_VERSION=\"$OLD_RBENV_VERSION\""
|
||||
;;
|
||||
esac
|
||||
exit
|
||||
fi
|
||||
|
||||
# Make sure the specified version is installed.
|
||||
if rbenv-prefix "$version" >/dev/null; then
|
||||
case "$shell" in
|
||||
fish )
|
||||
echo "setenv RBENV_VERSION \"${version}\""
|
||||
;;
|
||||
* )
|
||||
echo "export RBENV_VERSION=\"${version}\""
|
||||
;;
|
||||
esac
|
||||
if [ "$version" != "$RBENV_VERSION" ]; then
|
||||
case "$shell" in
|
||||
fish )
|
||||
echo "setenv RBENV_VERSION \"${version}\""
|
||||
;;
|
||||
* )
|
||||
echo "export OLD_RBENV_VERSION=\"$RBENV_VERSION\""
|
||||
echo "export RBENV_VERSION=\"${version}\""
|
||||
;;
|
||||
esac
|
||||
fi
|
||||
else
|
||||
echo "false"
|
||||
exit 1
|
||||
|
|
|
@ -22,12 +22,18 @@ load test_helper
|
|||
|
||||
@test "shell unset" {
|
||||
RBENV_SHELL=bash run rbenv-sh-shell --unset
|
||||
assert_success "unset RBENV_VERSION"
|
||||
assert_output <<OUT
|
||||
unset OLD_RBENV_VERSION
|
||||
unset RBENV_VERSION
|
||||
OUT
|
||||
}
|
||||
|
||||
@test "shell unset (fish)" {
|
||||
RBENV_SHELL=fish run rbenv-sh-shell --unset
|
||||
assert_success "set -e RBENV_VERSION"
|
||||
assert_output <<OUT
|
||||
set -e OLD_RBENV_VERSION
|
||||
set -e RBENV_VERSION
|
||||
OUT
|
||||
}
|
||||
|
||||
@test "shell change invalid version" {
|
||||
|
@ -42,7 +48,52 @@ SH
|
|||
@test "shell change version" {
|
||||
mkdir -p "${RBENV_ROOT}/versions/1.2.3"
|
||||
RBENV_SHELL=bash run rbenv-sh-shell 1.2.3
|
||||
assert_success 'export RBENV_VERSION="1.2.3"'
|
||||
assert_output <<OUT
|
||||
export OLD_RBENV_VERSION=""
|
||||
export RBENV_VERSION="1.2.3"
|
||||
OUT
|
||||
}
|
||||
|
||||
@test "shell change version pushes away previous OLD_RBENV_VERSION" {
|
||||
mkdir -p "${RBENV_ROOT}/versions/1.2.3"
|
||||
mkdir -p "${RBENV_ROOT}/versions/1.2.4"
|
||||
mkdir -p "${RBENV_ROOT}/versions/1.2.5"
|
||||
export OLD_RBENV_VERSION="1.2.3"
|
||||
export RBENV_VERSION="1.2.4"
|
||||
RBENV_SHELL=bash run rbenv-sh-shell 1.2.5
|
||||
assert_output <<OUT
|
||||
export OLD_RBENV_VERSION="1.2.4"
|
||||
export RBENV_VERSION="1.2.5"
|
||||
OUT
|
||||
}
|
||||
|
||||
@test "shell change version to the same version does not lose OLD_RBENV_VERSION" {
|
||||
mkdir -p "${RBENV_ROOT}/versions/1.2.3"
|
||||
mkdir -p "${RBENV_ROOT}/versions/1.2.4"
|
||||
export OLD_RBENV_VERSION="1.2.3"
|
||||
export RBENV_VERSION="1.2.4"
|
||||
RBENV_SHELL=bash run rbenv-sh-shell 1.2.4
|
||||
assert_output ''
|
||||
}
|
||||
|
||||
@test "shell change version to - swaps old and new versions" {
|
||||
mkdir -p "${RBENV_ROOT}/versions/1.2.3"
|
||||
mkdir -p "${RBENV_ROOT}/versions/1.2.4"
|
||||
export OLD_RBENV_VERSION="1.2.3"
|
||||
export RBENV_VERSION="1.2.4"
|
||||
RBENV_SHELL=bash run rbenv-sh-shell -
|
||||
assert_output <<OUT
|
||||
export OLD_RBENV_VERSION="1.2.4"
|
||||
export RBENV_VERSION="1.2.3"
|
||||
OUT
|
||||
}
|
||||
|
||||
@test "shell change version to - with no previous is an error" {
|
||||
mkdir -p "${RBENV_ROOT}/versions/1.2.3"
|
||||
RBENV_SHELL=bash run rbenv-sh-shell -
|
||||
assert_failure <<OUT
|
||||
rbenv: OLD_RBENV_VERSION not set
|
||||
OUT
|
||||
}
|
||||
|
||||
@test "shell change version (fish)" {
|
||||
|
|
Loading…
Reference in a new issue