rbenv/test/init.bats

110 lines
2.6 KiB
Text
Raw Normal View History

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
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)"
run rbenv-init - bash
2013-03-20 13:43:57 +01:00
assert_success
assert_line "source '${root}/test/../libexec/../completions/rbenv.bash'"
2013-03-20 13:43:57 +01:00
}
@test "detect parent shell" {
SHELL=/bin/false run rbenv-init -
assert_success
assert_line "export RBENV_SHELL=bash"
}
@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
run ./myscript.sh /bin/zsh
assert_success "sh"
}
@test "skip shell completions (fish)" {
2013-08-15 16:01:13 +02:00
root="$(cd $BATS_TEST_DIRNAME/.. && pwd)"
run rbenv-init - fish
2013-08-15 16:01:13 +02:00
assert_success
local line="$(grep '^source' <<<"$output")"
[ -z "$line" ] || flunk "did not expect line: $line"
2013-08-15 16:01:13 +02:00
}
@test "fish instructions" {
run rbenv-init fish
assert [ "$status" -eq 1 ]
2020-02-17 21:46:25 +01:00
assert_line 'status --is-interactive; and rbenv init - | source'
}
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" {
export PATH="${BATS_TEST_DIRNAME}/../libexec:/usr/bin:/bin:/usr/local/bin"
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)" {
export PATH="${BATS_TEST_DIRNAME}/../libexec:/usr/bin:/bin:/usr/local/bin"
run rbenv-init - fish
2013-08-15 16:01:13 +02:00
assert_success
assert_line 0 "set -gx PATH '${RBENV_ROOT}/shims' \$PATH"
2013-08-15 16:01:13 +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"
run rbenv-init - bash
2013-03-20 13:43:57 +01:00
assert_success
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
@test "can add shims to PATH more than once (fish)" {
2013-08-15 16:01:13 +02:00
export PATH="${RBENV_ROOT}/shims:$PATH"
run rbenv-init - fish
2013-08-15 16:01:13 +02:00
assert_success
assert_line 0 "set -gx PATH '${RBENV_ROOT}/shims' \$PATH"
2013-08-15 16:01:13 +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'
}