mirror of
https://github.com/rbenv/rbenv.git
synced 2024-12-29 13:15:42 +01:00
f2ac882579
With zsh `setopt warn_create_global` the "shell" command used to cause a warning message: scalar parameter RBENV_VERSION_OLD created globally in function rbenv. By using `typeset -g` specifically for zsh, this warning goes away.
101 lines
2.3 KiB
Bash
101 lines
2.3 KiB
Bash
#!/usr/bin/env bats
|
|
|
|
load test_helper
|
|
|
|
@test "shell integration disabled" {
|
|
run rbenv shell
|
|
assert_failure "rbenv: shell integration not enabled. Run \`rbenv init' for instructions."
|
|
}
|
|
|
|
@test "shell integration enabled" {
|
|
eval "$(rbenv init -)"
|
|
run rbenv shell
|
|
assert_success "rbenv: no shell-specific version configured"
|
|
}
|
|
|
|
@test "no shell version" {
|
|
mkdir -p "${RBENV_TEST_DIR}/myproject"
|
|
cd "${RBENV_TEST_DIR}/myproject"
|
|
echo "1.2.3" > .ruby-version
|
|
RBENV_VERSION="" run rbenv-sh-shell
|
|
assert_failure "rbenv: no shell-specific version configured"
|
|
}
|
|
|
|
@test "shell version" {
|
|
RBENV_SHELL=bash RBENV_VERSION="1.2.3" run rbenv-sh-shell
|
|
assert_success 'echo "$RBENV_VERSION"'
|
|
}
|
|
|
|
@test "shell version (fish)" {
|
|
RBENV_SHELL=fish RBENV_VERSION="1.2.3" run rbenv-sh-shell
|
|
assert_success 'echo "$RBENV_VERSION"'
|
|
}
|
|
|
|
@test "shell revert" {
|
|
RBENV_SHELL=bash run rbenv-sh-shell -
|
|
assert_success
|
|
assert_line 0 'if [ -n "${RBENV_VERSION_OLD+x}" ]; then'
|
|
}
|
|
|
|
@test "shell revert (fish)" {
|
|
RBENV_SHELL=fish run rbenv-sh-shell -
|
|
assert_success
|
|
assert_line 0 'if set -q RBENV_VERSION_OLD'
|
|
}
|
|
|
|
@test "shell unset" {
|
|
RBENV_SHELL=bash run rbenv-sh-shell --unset
|
|
assert_success
|
|
assert_output <<OUT
|
|
RBENV_VERSION_OLD="\${RBENV_VERSION-}"
|
|
unset RBENV_VERSION
|
|
OUT
|
|
}
|
|
|
|
@test "shell unset (fish)" {
|
|
RBENV_SHELL=fish run rbenv-sh-shell --unset
|
|
assert_success
|
|
assert_output <<OUT
|
|
set -gu RBENV_VERSION_OLD "\$RBENV_VERSION"
|
|
set -e RBENV_VERSION
|
|
OUT
|
|
}
|
|
|
|
@test "shell change invalid version" {
|
|
run rbenv-sh-shell 1.2.3
|
|
assert_failure
|
|
assert_output <<SH
|
|
rbenv: version \`1.2.3' not installed
|
|
false
|
|
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
|
|
assert_output <<OUT
|
|
RBENV_VERSION_OLD="\${RBENV_VERSION-}"
|
|
export RBENV_VERSION="1.2.3"
|
|
OUT
|
|
}
|
|
|
|
@test "shell change version (zsh)" {
|
|
mkdir -p "${RBENV_ROOT}/versions/1.2.3"
|
|
RBENV_SHELL=zsh run rbenv-sh-shell 1.2.3
|
|
assert_success
|
|
assert_output <<OUT
|
|
typeset -g RBENV_VERSION_OLD="\${RBENV_VERSION-}"
|
|
export RBENV_VERSION="1.2.3"
|
|
OUT
|
|
}
|
|
|
|
@test "shell change version (fish)" {
|
|
mkdir -p "${RBENV_ROOT}/versions/1.2.3"
|
|
RBENV_SHELL=fish run rbenv-sh-shell 1.2.3
|
|
assert_success
|
|
assert_output <<OUT
|
|
set -gu RBENV_VERSION_OLD "\$RBENV_VERSION"
|
|
set -gx RBENV_VERSION "1.2.3"
|
|
OUT
|
|
}
|