2013-03-20 13:43:57 +01:00
|
|
|
#!/usr/bin/env bats
|
|
|
|
|
|
|
|
load test_helper
|
|
|
|
|
|
|
|
@test "creates shims and versions directories" {
|
|
|
|
assert [ ! -d "${RBENV_ROOT}/shims" ]
|
|
|
|
assert [ ! -d "${RBENV_ROOT}/versions" ]
|
|
|
|
run rbenv-init -
|
|
|
|
assert_success
|
|
|
|
assert [ -d "${RBENV_ROOT}/shims" ]
|
|
|
|
assert [ -d "${RBENV_ROOT}/versions" ]
|
|
|
|
}
|
|
|
|
|
|
|
|
@test "auto rehash" {
|
|
|
|
run rbenv-init -
|
|
|
|
assert_success
|
2014-11-29 06:16:14 +01:00
|
|
|
assert_line "command rbenv rehash 2>/dev/null"
|
2013-03-20 13:43:57 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@test "setup shell completions" {
|
|
|
|
root="$(cd $BATS_TEST_DIRNAME/.. && pwd)"
|
2013-09-28 18:43:39 +02:00
|
|
|
run rbenv-init - bash
|
2013-03-20 13:43:57 +01:00
|
|
|
assert_success
|
2022-09-24 23:59:13 +02:00
|
|
|
assert_line "source '${root}/test/../completions/rbenv.bash'"
|
2013-03-20 13:43:57 +01:00
|
|
|
}
|
|
|
|
|
2013-09-28 18:43:39 +02:00
|
|
|
@test "detect parent shell" {
|
|
|
|
SHELL=/bin/false run rbenv-init -
|
|
|
|
assert_success
|
|
|
|
assert_line "export RBENV_SHELL=bash"
|
|
|
|
}
|
|
|
|
|
2015-12-24 12:29:35 +01:00
|
|
|
@test "detect parent shell from script" {
|
|
|
|
mkdir -p "$RBENV_TEST_DIR"
|
|
|
|
cd "$RBENV_TEST_DIR"
|
|
|
|
cat > myscript.sh <<OUT
|
|
|
|
#!/bin/sh
|
|
|
|
eval "\$(rbenv-init -)"
|
|
|
|
echo \$RBENV_SHELL
|
|
|
|
OUT
|
|
|
|
chmod +x myscript.sh
|
2021-03-23 22:41:55 +01:00
|
|
|
run ./myscript.sh
|
2015-12-24 12:29:35 +01:00
|
|
|
assert_success "sh"
|
|
|
|
}
|
|
|
|
|
2020-01-28 17:47:59 +01:00
|
|
|
@test "skip shell completions (fish)" {
|
2013-08-15 16:01:13 +02:00
|
|
|
root="$(cd $BATS_TEST_DIRNAME/.. && pwd)"
|
2013-09-28 18:43:39 +02:00
|
|
|
run rbenv-init - fish
|
2013-08-15 16:01:13 +02:00
|
|
|
assert_success
|
2020-01-28 17:47:59 +01:00
|
|
|
local line="$(grep '^source' <<<"$output")"
|
|
|
|
[ -z "$line" ] || flunk "did not expect line: $line"
|
2013-08-15 16:01:13 +02:00
|
|
|
}
|
|
|
|
|
2024-05-03 16:59:39 +02:00
|
|
|
@test "set up bash" {
|
|
|
|
assert [ ! -e ~/.bash_profile ]
|
2018-07-13 22:22:17 +02:00
|
|
|
run rbenv-init bash
|
2024-05-03 16:59:39 +02:00
|
|
|
assert_success "writing ~/.bash_profile: now configured for rbenv."
|
|
|
|
run cat ~/.bash_profile
|
|
|
|
# shellcheck disable=SC2016
|
2024-07-05 14:44:17 +02:00
|
|
|
assert_line 'eval "$(rbenv init - --no-rehash bash)"'
|
2018-07-13 22:22:17 +02:00
|
|
|
}
|
|
|
|
|
2024-05-03 16:59:39 +02:00
|
|
|
@test "set up bash (bashrc)" {
|
|
|
|
mkdir -p "$HOME"
|
|
|
|
touch ~/.bashrc
|
|
|
|
assert [ ! -e ~/.bash_profile ]
|
|
|
|
run rbenv-init bash
|
|
|
|
assert_success "writing ~/.bashrc: now configured for rbenv."
|
|
|
|
run cat ~/.bashrc
|
|
|
|
# shellcheck disable=SC2016
|
2024-07-05 14:44:17 +02:00
|
|
|
assert_line 'eval "$(rbenv init - --no-rehash bash)"'
|
2024-05-03 16:59:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@test "set up zsh" {
|
|
|
|
unset ZDOTDIR
|
|
|
|
assert [ ! -e ~/.zprofile ]
|
|
|
|
run rbenv-init zsh
|
|
|
|
assert_success "writing ~/.zprofile: now configured for rbenv."
|
|
|
|
run cat ~/.zprofile
|
|
|
|
# shellcheck disable=SC2016
|
2024-07-05 14:44:17 +02:00
|
|
|
assert_line 'eval "$(rbenv init - --no-rehash zsh)"'
|
2024-05-03 16:59:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@test "set up zsh (zshrc)" {
|
|
|
|
unset ZDOTDIR
|
|
|
|
mkdir -p "$HOME"
|
|
|
|
cat > ~/.zshrc <<<"# rbenv"
|
|
|
|
run rbenv-init zsh
|
|
|
|
assert_success "writing ~/.zshrc: now configured for rbenv."
|
|
|
|
run cat ~/.zshrc
|
|
|
|
# shellcheck disable=SC2016
|
2024-07-05 14:44:17 +02:00
|
|
|
assert_line 'eval "$(rbenv init - --no-rehash zsh)"'
|
2024-05-03 16:59:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@test "set up fish" {
|
|
|
|
unset XDG_CONFIG_HOME
|
2013-12-06 16:45:22 +01:00
|
|
|
run rbenv-init fish
|
2024-05-03 16:59:39 +02:00
|
|
|
assert_success "writing ~/.config/fish/config.fish: now configured for rbenv."
|
|
|
|
run cat ~/.config/fish/config.fish
|
2024-07-05 14:44:17 +02:00
|
|
|
assert_line 'status --is-interactive; and rbenv init - --no-rehash fish | source'
|
2013-12-06 16:45:22 +01:00
|
|
|
}
|
|
|
|
|
2024-05-03 16:59:39 +02:00
|
|
|
@test "set up multiple shells at once" {
|
|
|
|
unset ZDOTDIR
|
|
|
|
unset XDG_CONFIG_HOME
|
|
|
|
run rbenv-init bash zsh fish
|
|
|
|
assert_success
|
|
|
|
assert_output <<OUT
|
|
|
|
writing ~/.bash_profile: now configured for rbenv.
|
|
|
|
writing ~/.zprofile: now configured for rbenv.
|
|
|
|
writing ~/.config/fish/config.fish: now configured for rbenv.
|
|
|
|
OUT
|
|
|
|
}
|
|
|
|
|
2013-03-20 13:43:57 +01:00
|
|
|
@test "option to skip rehash" {
|
|
|
|
run rbenv-init - --no-rehash
|
|
|
|
assert_success
|
|
|
|
refute_line "rbenv rehash 2>/dev/null"
|
|
|
|
}
|
|
|
|
|
|
|
|
@test "adds shims to PATH" {
|
2014-01-02 22:17:38 +01:00
|
|
|
export PATH="${BATS_TEST_DIRNAME}/../libexec:/usr/bin:/bin:/usr/local/bin"
|
2013-09-28 18:43:39 +02:00
|
|
|
run rbenv-init - bash
|
2013-03-20 13:43:57 +01:00
|
|
|
assert_success
|
|
|
|
assert_line 0 'export PATH="'${RBENV_ROOT}'/shims:${PATH}"'
|
|
|
|
}
|
|
|
|
|
2013-08-15 16:01:13 +02:00
|
|
|
@test "adds shims to PATH (fish)" {
|
2014-01-02 22:17:38 +01:00
|
|
|
export PATH="${BATS_TEST_DIRNAME}/../libexec:/usr/bin:/bin:/usr/local/bin"
|
2013-09-28 18:43:39 +02:00
|
|
|
run rbenv-init - fish
|
2013-08-15 16:01:13 +02:00
|
|
|
assert_success
|
2017-05-16 22:36:06 +02:00
|
|
|
assert_line 0 "set -gx PATH '${RBENV_ROOT}/shims' \$PATH"
|
2013-08-15 16:01:13 +02:00
|
|
|
}
|
|
|
|
|
2014-10-15 01:36:20 +02:00
|
|
|
@test "can add shims to PATH more than once" {
|
2013-03-20 13:43:57 +01:00
|
|
|
export PATH="${RBENV_ROOT}/shims:$PATH"
|
2013-09-28 18:43:39 +02:00
|
|
|
run rbenv-init - bash
|
2013-03-20 13:43:57 +01:00
|
|
|
assert_success
|
2014-10-15 01:36:20 +02:00
|
|
|
assert_line 0 'export PATH="'${RBENV_ROOT}'/shims:${PATH}"'
|
2013-03-20 13:43:57 +01:00
|
|
|
}
|
2013-08-15 16:01:13 +02:00
|
|
|
|
2015-04-19 23:53:19 +02:00
|
|
|
@test "can add shims to PATH more than once (fish)" {
|
2013-08-15 16:01:13 +02:00
|
|
|
export PATH="${RBENV_ROOT}/shims:$PATH"
|
2013-09-28 18:43:39 +02:00
|
|
|
run rbenv-init - fish
|
2013-08-15 16:01:13 +02:00
|
|
|
assert_success
|
2017-05-16 22:36:06 +02:00
|
|
|
assert_line 0 "set -gx PATH '${RBENV_ROOT}/shims' \$PATH"
|
2013-08-15 16:01:13 +02:00
|
|
|
}
|
2014-06-02 19:36:49 +02:00
|
|
|
|
|
|
|
@test "outputs sh-compatible syntax" {
|
|
|
|
run rbenv-init - bash
|
|
|
|
assert_success
|
|
|
|
assert_line ' case "$command" in'
|
|
|
|
|
|
|
|
run rbenv-init - zsh
|
|
|
|
assert_success
|
|
|
|
assert_line ' case "$command" in'
|
|
|
|
}
|
|
|
|
|
|
|
|
@test "outputs fish-specific syntax (fish)" {
|
|
|
|
run rbenv-init - fish
|
|
|
|
assert_success
|
|
|
|
assert_line ' switch "$command"'
|
|
|
|
refute_line ' case "$command" in'
|
|
|
|
}
|