mirror of
https://github.com/pyenv/pyenv.git
synced 2024-11-21 20:47:00 -05:00
878bd87328
`$SHELL` variable is a terrible way of detecting the current shell because it's not even supposed to reflect the current shell; it's meant for keeping the value of the default shell for programs to start. If an explicit `<shell>` argument wasn't passed to `rbenv init`, it tries to detect the shell by getting the name of its parent process. If this fails, it falls back on the value of `$SHELL` as before. Furthermore, `rbenv init` will set the RBENV_SHELL variable in the current shell to the value of the detected shell so that `sh-shell` and `sh-rehash` commands don't have to repeat the detection.
52 lines
1.2 KiB
Bash
52 lines
1.2 KiB
Bash
#!/usr/bin/env bats
|
|
|
|
load test_helper
|
|
|
|
@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 unset" {
|
|
RBENV_SHELL=bash run rbenv-sh-shell --unset
|
|
assert_success "unset RBENV_VERSION"
|
|
}
|
|
|
|
@test "shell unset (fish)" {
|
|
RBENV_SHELL=fish run rbenv-sh-shell --unset
|
|
assert_success "set -e RBENV_VERSION"
|
|
}
|
|
|
|
@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 'export RBENV_VERSION="1.2.3"'
|
|
}
|
|
|
|
@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 'setenv RBENV_VERSION "1.2.3"'
|
|
}
|