mirror of
https://github.com/pyenv/pyenv.git
synced 2024-12-23 01:00:46 +00:00
Merge branch 'test-coverage' for MAXIMUM COVERAGE
This commit is contained in:
commit
05568496c1
19 changed files with 794 additions and 55 deletions
|
@ -38,13 +38,14 @@ RBENV_VERSION="$1"
|
|||
if [ "$RBENV_VERSION" = "--unset" ]; then
|
||||
rm -f .ruby-version .rbenv-version
|
||||
elif [ -n "$RBENV_VERSION" ]; then
|
||||
if [ "$(RBENV_VERSION= rbenv-version-origin)" -ef .rbenv-version ]; then
|
||||
previous_file="$(RBENV_VERSION= rbenv-version-origin || true)"
|
||||
rbenv-version-file-write .ruby-version "$RBENV_VERSION"
|
||||
if [ "$previous_file" -ef .rbenv-version ]; then
|
||||
rm -f .rbenv-version
|
||||
{ echo "rbenv: removed existing \`.rbenv-version' file and migrated"
|
||||
echo " local version specification to \`.ruby-version' file"
|
||||
} >&2
|
||||
fi
|
||||
rbenv-version-file-write .ruby-version "$RBENV_VERSION"
|
||||
else
|
||||
rbenv-version-file-read .ruby-version ||
|
||||
rbenv-version-file-read .rbenv-version ||
|
||||
|
|
46
test/--version.bats
Normal file
46
test/--version.bats
Normal file
|
@ -0,0 +1,46 @@
|
|||
#!/usr/bin/env bats
|
||||
|
||||
load test_helper
|
||||
|
||||
setup() {
|
||||
mkdir -p "$HOME"
|
||||
git config --global user.name "Tester"
|
||||
git config --global user.email "tester@test.local"
|
||||
}
|
||||
|
||||
git_commit() {
|
||||
git commit --quiet --allow-empty -m "" --allow-empty-message
|
||||
}
|
||||
|
||||
@test "default version" {
|
||||
assert [ ! -e "$RBENV_ROOT" ]
|
||||
run rbenv---version
|
||||
assert_success
|
||||
[[ $output == "rbenv 0."* ]]
|
||||
}
|
||||
|
||||
@test "reads version from git repo" {
|
||||
mkdir -p "$RBENV_ROOT"
|
||||
cd "$RBENV_ROOT"
|
||||
git init
|
||||
git_commit
|
||||
git tag v0.4.1
|
||||
git_commit
|
||||
git_commit
|
||||
|
||||
cd "$RBENV_TEST_DIR"
|
||||
run rbenv---version
|
||||
assert_success
|
||||
[[ $output == "rbenv 0.4.1-2-g"* ]]
|
||||
}
|
||||
|
||||
@test "prints default version if no tags in git repo" {
|
||||
mkdir -p "$RBENV_ROOT"
|
||||
cd "$RBENV_ROOT"
|
||||
git init
|
||||
git_commit
|
||||
|
||||
cd "$RBENV_TEST_DIR"
|
||||
run rbenv---version
|
||||
[[ $output == "rbenv 0."* ]]
|
||||
}
|
|
@ -38,7 +38,9 @@ else
|
|||
exit 1
|
||||
fi"
|
||||
run rbenv-completions hello happy world
|
||||
assert_success "\
|
||||
happy
|
||||
world"
|
||||
assert_success
|
||||
assert_output <<OUT
|
||||
happy
|
||||
world
|
||||
OUT
|
||||
}
|
||||
|
|
|
@ -27,9 +27,11 @@ create_executable() {
|
|||
|
||||
rbenv-rehash
|
||||
run rbenv-completions exec
|
||||
assert_success "\
|
||||
rake
|
||||
ruby"
|
||||
assert_success
|
||||
assert_output <<OUT
|
||||
rake
|
||||
ruby
|
||||
OUT
|
||||
}
|
||||
|
||||
@test "supports hook path with spaces" {
|
||||
|
@ -50,19 +52,20 @@ create_executable() {
|
|||
echo \$0
|
||||
for arg; do
|
||||
# hack to avoid bash builtin echo which can't output '-e'
|
||||
printf "%s\\n" "\$arg"
|
||||
printf " %s\\n" "\$arg"
|
||||
done
|
||||
SH
|
||||
|
||||
run rbenv-exec ruby -w -e "puts 'hello world'" -- extra args
|
||||
assert_success "\
|
||||
${RBENV_ROOT}/versions/2.0/bin/ruby
|
||||
-w
|
||||
-e
|
||||
puts 'hello world'
|
||||
--
|
||||
extra
|
||||
args"
|
||||
run rbenv-exec ruby -w "/path to/ruby script.rb" -- extra args
|
||||
assert_success
|
||||
assert_output <<OUT
|
||||
${RBENV_ROOT}/versions/2.0/bin/ruby
|
||||
-w
|
||||
/path to/ruby script.rb
|
||||
--
|
||||
extra
|
||||
args
|
||||
OUT
|
||||
}
|
||||
|
||||
@test "supports ruby -S <cmd>" {
|
||||
|
@ -85,9 +88,10 @@ else
|
|||
fi
|
||||
SH
|
||||
|
||||
create_executable "rake" "\
|
||||
#!/usr/bin/env ruby
|
||||
echo hello rake"
|
||||
create_executable "rake" <<SH
|
||||
#!/usr/bin/env ruby
|
||||
echo hello rake
|
||||
SH
|
||||
|
||||
rbenv-rehash
|
||||
run ruby -S rake
|
||||
|
|
115
test/help.bats
Normal file
115
test/help.bats
Normal file
|
@ -0,0 +1,115 @@
|
|||
#!/usr/bin/env bats
|
||||
|
||||
load test_helper
|
||||
|
||||
@test "without args shows summary of common commands" {
|
||||
run rbenv-help
|
||||
assert_success
|
||||
assert_line "Usage: rbenv <command> [<args>]"
|
||||
assert_line "Some useful rbenv commands are:"
|
||||
}
|
||||
|
||||
@test "invalid command" {
|
||||
run rbenv-help hello
|
||||
assert_failure "rbenv: no such command \`hello'"
|
||||
}
|
||||
|
||||
@test "shows help for a specific command" {
|
||||
mkdir -p "${RBENV_TEST_DIR}/bin"
|
||||
cat > "${RBENV_TEST_DIR}/bin/rbenv-hello" <<SH
|
||||
#!shebang
|
||||
# Usage: rbenv hello <world>
|
||||
# Summary: Says "hello" to you, from rbenv
|
||||
# This command is useful for saying hello.
|
||||
echo hello
|
||||
SH
|
||||
|
||||
run rbenv-help hello
|
||||
assert_success
|
||||
assert_output <<SH
|
||||
Usage: rbenv hello <world>
|
||||
|
||||
This command is useful for saying hello.
|
||||
SH
|
||||
}
|
||||
|
||||
@test "replaces missing extended help with summary text" {
|
||||
mkdir -p "${RBENV_TEST_DIR}/bin"
|
||||
cat > "${RBENV_TEST_DIR}/bin/rbenv-hello" <<SH
|
||||
#!shebang
|
||||
# Usage: rbenv hello <world>
|
||||
# Summary: Says "hello" to you, from rbenv
|
||||
echo hello
|
||||
SH
|
||||
|
||||
run rbenv-help hello
|
||||
assert_success
|
||||
assert_output <<SH
|
||||
Usage: rbenv hello <world>
|
||||
|
||||
Says "hello" to you, from rbenv
|
||||
SH
|
||||
}
|
||||
|
||||
@test "extracts only usage" {
|
||||
mkdir -p "${RBENV_TEST_DIR}/bin"
|
||||
cat > "${RBENV_TEST_DIR}/bin/rbenv-hello" <<SH
|
||||
#!shebang
|
||||
# Usage: rbenv hello <world>
|
||||
# Summary: Says "hello" to you, from rbenv
|
||||
# This extended help won't be shown.
|
||||
echo hello
|
||||
SH
|
||||
|
||||
run rbenv-help --usage hello
|
||||
assert_success "Usage: rbenv hello <world>"
|
||||
}
|
||||
|
||||
@test "multiline usage section" {
|
||||
mkdir -p "${RBENV_TEST_DIR}/bin"
|
||||
cat > "${RBENV_TEST_DIR}/bin/rbenv-hello" <<SH
|
||||
#!shebang
|
||||
# Usage: rbenv hello <world>
|
||||
# rbenv hi [everybody]
|
||||
# rbenv hola --translate
|
||||
# Summary: Says "hello" to you, from rbenv
|
||||
# Help text.
|
||||
echo hello
|
||||
SH
|
||||
|
||||
run rbenv-help hello
|
||||
assert_success
|
||||
assert_output <<SH
|
||||
Usage: rbenv hello <world>
|
||||
rbenv hi [everybody]
|
||||
rbenv hola --translate
|
||||
|
||||
Help text.
|
||||
SH
|
||||
}
|
||||
|
||||
@test "multiline extended help section" {
|
||||
mkdir -p "${RBENV_TEST_DIR}/bin"
|
||||
cat > "${RBENV_TEST_DIR}/bin/rbenv-hello" <<SH
|
||||
#!shebang
|
||||
# Usage: rbenv hello <world>
|
||||
# Summary: Says "hello" to you, from rbenv
|
||||
# This is extended help text.
|
||||
# It can contain multiple lines.
|
||||
#
|
||||
# And paragraphs.
|
||||
|
||||
echo hello
|
||||
SH
|
||||
|
||||
run rbenv-help hello
|
||||
assert_success
|
||||
assert_output <<SH
|
||||
Usage: rbenv hello <world>
|
||||
|
||||
This is extended help text.
|
||||
It can contain multiple lines.
|
||||
|
||||
And paragraphs.
|
||||
SH
|
||||
}
|
|
@ -22,10 +22,12 @@ create_hook() {
|
|||
create_hook "$path2" exec "bueno.bash"
|
||||
|
||||
RBENV_HOOK_PATH="$path1:$path2" run rbenv-hooks exec
|
||||
assert_success "\
|
||||
${RBENV_TEST_DIR}/rbenv.d/exec/ahoy.bash
|
||||
${RBENV_TEST_DIR}/rbenv.d/exec/hello.bash
|
||||
${RBENV_TEST_DIR}/etc/rbenv_hooks/exec/bueno.bash"
|
||||
assert_success
|
||||
assert_output <<OUT
|
||||
${RBENV_TEST_DIR}/rbenv.d/exec/ahoy.bash
|
||||
${RBENV_TEST_DIR}/rbenv.d/exec/hello.bash
|
||||
${RBENV_TEST_DIR}/etc/rbenv_hooks/exec/bueno.bash
|
||||
OUT
|
||||
}
|
||||
|
||||
@test "supports hook paths with spaces" {
|
||||
|
@ -35,9 +37,11 @@ create_hook() {
|
|||
create_hook "$path2" exec "ahoy.bash"
|
||||
|
||||
RBENV_HOOK_PATH="$path1:$path2" run rbenv-hooks exec
|
||||
assert_success "\
|
||||
${RBENV_TEST_DIR}/my hooks/rbenv.d/exec/hello.bash
|
||||
${RBENV_TEST_DIR}/etc/rbenv hooks/exec/ahoy.bash"
|
||||
assert_success
|
||||
assert_output <<OUT
|
||||
${RBENV_TEST_DIR}/my hooks/rbenv.d/exec/hello.bash
|
||||
${RBENV_TEST_DIR}/etc/rbenv hooks/exec/ahoy.bash
|
||||
OUT
|
||||
}
|
||||
|
||||
@test "resolves relative paths" {
|
||||
|
|
|
@ -19,6 +19,19 @@ setup() {
|
|||
assert_success "1.2.3"
|
||||
}
|
||||
|
||||
@test "supports legacy .rbenv-version file" {
|
||||
echo "1.2.3" > .rbenv-version
|
||||
run rbenv-local
|
||||
assert_success "1.2.3"
|
||||
}
|
||||
|
||||
@test "local .ruby-version has precedence over .rbenv-version" {
|
||||
echo "1.8" > .rbenv-version
|
||||
echo "2.0" > .ruby-version
|
||||
run rbenv-local
|
||||
assert_success "2.0"
|
||||
}
|
||||
|
||||
@test "ignores version in parent directory" {
|
||||
echo "1.2.3" > .ruby-version
|
||||
mkdir -p "subdir" && cd "subdir"
|
||||
|
@ -48,6 +61,43 @@ setup() {
|
|||
assert_success "1.0-pre"
|
||||
run rbenv-local 1.2.3
|
||||
assert_success ""
|
||||
run rbenv-local
|
||||
assert_success "1.2.3"
|
||||
assert [ "$(cat .ruby-version)" = "1.2.3" ]
|
||||
}
|
||||
|
||||
@test "renames .rbenv-version to .ruby-version" {
|
||||
echo "1.8.7" > .rbenv-version
|
||||
mkdir -p "${RBENV_ROOT}/versions/1.9.3"
|
||||
run rbenv-local
|
||||
assert_success "1.8.7"
|
||||
run rbenv-local "1.9.3"
|
||||
assert_success
|
||||
assert_output <<OUT
|
||||
rbenv: removed existing \`.rbenv-version' file and migrated
|
||||
local version specification to \`.ruby-version' file
|
||||
OUT
|
||||
assert [ ! -e .rbenv-version ]
|
||||
assert [ "$(cat .ruby-version)" = "1.9.3" ]
|
||||
}
|
||||
|
||||
@test "doesn't rename .rbenv-version if changing the version failed" {
|
||||
echo "1.8.7" > .rbenv-version
|
||||
assert [ ! -e "${RBENV_ROOT}/versions/1.9.3" ]
|
||||
run rbenv-local "1.9.3"
|
||||
assert_failure "rbenv: version \`1.9.3' not installed"
|
||||
assert [ ! -e .ruby-version ]
|
||||
assert [ "$(cat .rbenv-version)" = "1.8.7" ]
|
||||
}
|
||||
|
||||
@test "unsets local version" {
|
||||
touch .ruby-version
|
||||
run rbenv-local --unset
|
||||
assert_success ""
|
||||
assert [ ! -e .rbenv-version ]
|
||||
}
|
||||
|
||||
@test "unsets alternate version file" {
|
||||
touch .rbenv-version
|
||||
run rbenv-local --unset
|
||||
assert_success ""
|
||||
assert [ ! -e .rbenv-version ]
|
||||
}
|
||||
|
|
|
@ -2,10 +2,17 @@
|
|||
|
||||
load test_helper
|
||||
|
||||
create_executable() {
|
||||
local bin="${RBENV_ROOT}/versions/${1}/bin"
|
||||
mkdir -p "$bin"
|
||||
touch "${bin}/$2"
|
||||
chmod +x "${bin}/$2"
|
||||
}
|
||||
|
||||
@test "empty rehash" {
|
||||
assert [ ! -d "${RBENV_ROOT}/shims" ]
|
||||
run rbenv-rehash
|
||||
assert_success
|
||||
assert_success ""
|
||||
assert [ -d "${RBENV_ROOT}/shims" ]
|
||||
rmdir "${RBENV_ROOT}/shims"
|
||||
}
|
||||
|
@ -14,14 +21,34 @@ load test_helper
|
|||
mkdir -p "${RBENV_ROOT}/shims"
|
||||
chmod -w "${RBENV_ROOT}/shims"
|
||||
run rbenv-rehash
|
||||
assert_failure
|
||||
assert_output "rbenv: cannot rehash: ${RBENV_ROOT}/shims isn't writable"
|
||||
assert_failure "rbenv: cannot rehash: ${RBENV_ROOT}/shims isn't writable"
|
||||
}
|
||||
|
||||
@test "rehash in progress" {
|
||||
mkdir -p "${RBENV_ROOT}/shims"
|
||||
touch "${RBENV_ROOT}/shims/.rbenv-shim"
|
||||
run rbenv-rehash
|
||||
assert_failure
|
||||
assert_output "rbenv: cannot rehash: ${RBENV_ROOT}/shims/.rbenv-shim exists"
|
||||
assert_failure "rbenv: cannot rehash: ${RBENV_ROOT}/shims/.rbenv-shim exists"
|
||||
}
|
||||
|
||||
@test "creates shims" {
|
||||
create_executable "1.8" "ruby"
|
||||
create_executable "1.8" "rake"
|
||||
create_executable "2.0" "ruby"
|
||||
create_executable "2.0" "rspec"
|
||||
|
||||
assert [ ! -e "${RBENV_ROOT}/shims/ruby" ]
|
||||
assert [ ! -e "${RBENV_ROOT}/shims/rake" ]
|
||||
assert [ ! -e "${RBENV_ROOT}/shims/rspec" ]
|
||||
|
||||
run rbenv-rehash
|
||||
assert_success ""
|
||||
|
||||
run ls "${RBENV_ROOT}/shims"
|
||||
assert_success
|
||||
assert_output <<OUT
|
||||
rake
|
||||
rspec
|
||||
ruby
|
||||
OUT
|
||||
}
|
||||
|
|
|
@ -23,13 +23,14 @@ load test_helper
|
|||
@test "shell change invalid version" {
|
||||
run rbenv-sh-shell 1.2.3
|
||||
assert_failure
|
||||
assert_line "rbenv: version \`1.2.3' not installed"
|
||||
assert_line "return 1"
|
||||
assert_output <<SH
|
||||
rbenv: version \`1.2.3' not installed
|
||||
return 1
|
||||
SH
|
||||
}
|
||||
|
||||
@test "shell change version" {
|
||||
mkdir -p "${RBENV_ROOT}/versions/1.2.3"
|
||||
run rbenv-sh-shell 1.2.3
|
||||
assert_success 'export RBENV_VERSION="1.2.3"'
|
||||
refute_line "return 1"
|
||||
}
|
||||
|
|
|
@ -26,7 +26,7 @@ assert_success() {
|
|||
if [ "$status" -ne 0 ]; then
|
||||
flunk "command failed with exit status $status"
|
||||
elif [ "$#" -gt 0 ]; then
|
||||
assert_output_lines "$1"
|
||||
assert_output "$1"
|
||||
fi
|
||||
}
|
||||
|
||||
|
@ -34,7 +34,7 @@ assert_failure() {
|
|||
if [ "$status" -eq 0 ]; then
|
||||
flunk "expected failed exit status"
|
||||
elif [ "$#" -gt 0 ]; then
|
||||
assert_output_lines "$1"
|
||||
assert_output "$1"
|
||||
fi
|
||||
}
|
||||
|
||||
|
@ -47,21 +47,11 @@ assert_equal() {
|
|||
}
|
||||
|
||||
assert_output() {
|
||||
assert_equal "$1" "$output"
|
||||
}
|
||||
|
||||
# compares lines with leading whitespace trimmed
|
||||
assert_output_lines() {
|
||||
local -a expected
|
||||
IFS=$'\n' expected=($1)
|
||||
for (( i=0; i < ${#expected[@]}; i++ )); do
|
||||
local wants="${expected[$i]}"
|
||||
local got="${lines[$i]}"
|
||||
assert_equal \
|
||||
"${wants#"${wants%%[![:space:]]*}"}" \
|
||||
"${got#"${got%%[![:space:]]*}"}"
|
||||
done
|
||||
assert_equal "${expected[$i]}" "${lines[$i]}"
|
||||
local expected
|
||||
if [ $# -eq 0 ]; then expected="$(cat -)"
|
||||
else expected="$1"
|
||||
fi
|
||||
assert_equal "$expected" "$output"
|
||||
}
|
||||
|
||||
assert_line() {
|
||||
|
|
39
test/version-file-read.bats
Normal file
39
test/version-file-read.bats
Normal file
|
@ -0,0 +1,39 @@
|
|||
#!/usr/bin/env bats
|
||||
|
||||
load test_helper
|
||||
|
||||
setup() {
|
||||
mkdir -p "${RBENV_TEST_DIR}/myproject"
|
||||
cd "${RBENV_TEST_DIR}/myproject"
|
||||
}
|
||||
|
||||
@test "fails without arguments" {
|
||||
run rbenv-version-file-read
|
||||
assert_failure ""
|
||||
}
|
||||
|
||||
@test "fails for invalid file" {
|
||||
run rbenv-version-file-read "non-existent"
|
||||
assert_failure ""
|
||||
}
|
||||
|
||||
@test "reads simple version file" {
|
||||
cat > my-version <<<"1.9.3"
|
||||
run rbenv-version-file-read my-version
|
||||
assert_success "1.9.3"
|
||||
}
|
||||
|
||||
@test "reads only the first word from file" {
|
||||
cat > my-version <<<"1.9.3-p194@tag 1.8.7 hi"
|
||||
run rbenv-version-file-read my-version
|
||||
assert_success "1.9.3-p194@tag"
|
||||
}
|
||||
|
||||
@test "loads only the first line in file" {
|
||||
cat > my-version <<IN
|
||||
1.8.7 one
|
||||
1.9.3 two
|
||||
IN
|
||||
run rbenv-version-file-read my-version
|
||||
assert_success "1.8.7"
|
||||
}
|
30
test/version-file-write.bats
Normal file
30
test/version-file-write.bats
Normal file
|
@ -0,0 +1,30 @@
|
|||
#!/usr/bin/env bats
|
||||
|
||||
load test_helper
|
||||
|
||||
setup() {
|
||||
mkdir -p "$RBENV_TEST_DIR"
|
||||
cd "$RBENV_TEST_DIR"
|
||||
}
|
||||
|
||||
@test "invocation without 2 arguments prints usage" {
|
||||
run rbenv-version-file-write
|
||||
assert_failure "Usage: rbenv version-file-write <file> <version>"
|
||||
run rbenv-version-file-write "one" ""
|
||||
assert_failure
|
||||
}
|
||||
|
||||
@test "setting nonexistent version fails" {
|
||||
assert [ ! -e ".ruby-version" ]
|
||||
run rbenv-version-file-write ".ruby-version" "1.8.7"
|
||||
assert_failure "rbenv: version \`1.8.7' not installed"
|
||||
assert [ ! -e ".ruby-version" ]
|
||||
}
|
||||
|
||||
@test "writes value to arbitrary file" {
|
||||
mkdir -p "${RBENV_ROOT}/versions/1.8.7"
|
||||
assert [ ! -e "my-version" ]
|
||||
run rbenv-version-file-write "${PWD}/my-version" "1.8.7"
|
||||
assert_success ""
|
||||
assert [ "$(cat my-version)" = "1.8.7" ]
|
||||
}
|
99
test/version-file.bats
Normal file
99
test/version-file.bats
Normal file
|
@ -0,0 +1,99 @@
|
|||
#!/usr/bin/env bats
|
||||
|
||||
load test_helper
|
||||
|
||||
setup() {
|
||||
mkdir -p "$RBENV_TEST_DIR"
|
||||
cd "$RBENV_TEST_DIR"
|
||||
}
|
||||
|
||||
create_file() {
|
||||
mkdir -p "$(dirname "$1")"
|
||||
touch "$1"
|
||||
}
|
||||
|
||||
@test "prints global file if no version files exist" {
|
||||
assert [ ! -e "${RBENV_ROOT}/version" ]
|
||||
assert [ ! -e ".ruby-version" ]
|
||||
run rbenv-version-file
|
||||
assert_success "${RBENV_ROOT}/version"
|
||||
}
|
||||
|
||||
@test "detects 'global' file" {
|
||||
create_file "${RBENV_ROOT}/global"
|
||||
run rbenv-version-file
|
||||
assert_success "${RBENV_ROOT}/global"
|
||||
}
|
||||
|
||||
@test "detects 'default' file" {
|
||||
create_file "${RBENV_ROOT}/default"
|
||||
run rbenv-version-file
|
||||
assert_success "${RBENV_ROOT}/default"
|
||||
}
|
||||
|
||||
@test "'version' has precedence over 'global' and 'default'" {
|
||||
create_file "${RBENV_ROOT}/version"
|
||||
create_file "${RBENV_ROOT}/global"
|
||||
create_file "${RBENV_ROOT}/default"
|
||||
run rbenv-version-file
|
||||
assert_success "${RBENV_ROOT}/version"
|
||||
}
|
||||
|
||||
@test "in current directory" {
|
||||
create_file ".ruby-version"
|
||||
run rbenv-version-file
|
||||
assert_success "${RBENV_TEST_DIR}/.ruby-version"
|
||||
}
|
||||
|
||||
@test "legacy file in current directory" {
|
||||
create_file ".rbenv-version"
|
||||
run rbenv-version-file
|
||||
assert_success "${RBENV_TEST_DIR}/.rbenv-version"
|
||||
}
|
||||
|
||||
@test ".ruby-version has precedence over legacy file" {
|
||||
create_file ".ruby-version"
|
||||
create_file ".rbenv-version"
|
||||
run rbenv-version-file
|
||||
assert_success "${RBENV_TEST_DIR}/.ruby-version"
|
||||
}
|
||||
|
||||
@test "in parent directory" {
|
||||
create_file ".ruby-version"
|
||||
mkdir -p project
|
||||
cd project
|
||||
run rbenv-version-file
|
||||
assert_success "${RBENV_TEST_DIR}/.ruby-version"
|
||||
}
|
||||
|
||||
@test "topmost file has precedence" {
|
||||
create_file ".ruby-version"
|
||||
create_file "project/.ruby-version"
|
||||
cd project
|
||||
run rbenv-version-file
|
||||
assert_success "${RBENV_TEST_DIR}/project/.ruby-version"
|
||||
}
|
||||
|
||||
@test "legacy file has precedence if higher" {
|
||||
create_file ".ruby-version"
|
||||
create_file "project/.rbenv-version"
|
||||
cd project
|
||||
run rbenv-version-file
|
||||
assert_success "${RBENV_TEST_DIR}/project/.rbenv-version"
|
||||
}
|
||||
|
||||
@test "RBENV_DIR has precedence over PWD" {
|
||||
create_file "widget/.ruby-version"
|
||||
create_file "project/.ruby-version"
|
||||
cd project
|
||||
RBENV_DIR="${RBENV_TEST_DIR}/widget" run rbenv-version-file
|
||||
assert_success "${RBENV_TEST_DIR}/widget/.ruby-version"
|
||||
}
|
||||
|
||||
@test "PWD is searched if RBENV_DIR yields no results" {
|
||||
mkdir -p "widget/blank"
|
||||
create_file "project/.ruby-version"
|
||||
cd project
|
||||
RBENV_DIR="${RBENV_TEST_DIR}/widget/blank" run rbenv-version-file
|
||||
assert_success "${RBENV_TEST_DIR}/project/.ruby-version"
|
||||
}
|
65
test/version-name.bats
Normal file
65
test/version-name.bats
Normal file
|
@ -0,0 +1,65 @@
|
|||
#!/usr/bin/env bats
|
||||
|
||||
load test_helper
|
||||
|
||||
create_version() {
|
||||
mkdir -p "${RBENV_ROOT}/versions/$1"
|
||||
}
|
||||
|
||||
setup() {
|
||||
mkdir -p "$RBENV_TEST_DIR"
|
||||
cd "$RBENV_TEST_DIR"
|
||||
}
|
||||
|
||||
@test "no version selected" {
|
||||
assert [ ! -d "${RBENV_ROOT}/versions" ]
|
||||
run rbenv-version-name
|
||||
assert_success "system"
|
||||
}
|
||||
|
||||
@test "system version is not checked for existance" {
|
||||
RBENV_VERSION=system run rbenv-version-name
|
||||
assert_success "system"
|
||||
}
|
||||
|
||||
@test "RBENV_VERSION has precedence over local" {
|
||||
create_version "1.8.7"
|
||||
create_version "1.9.3"
|
||||
|
||||
cat > ".ruby-version" <<<"1.8.7"
|
||||
run rbenv-version-name
|
||||
assert_success "1.8.7"
|
||||
|
||||
RBENV_VERSION=1.9.3 run rbenv-version-name
|
||||
assert_success "1.9.3"
|
||||
}
|
||||
|
||||
@test "local file has precedence over global" {
|
||||
create_version "1.8.7"
|
||||
create_version "1.9.3"
|
||||
|
||||
cat > "${RBENV_ROOT}/version" <<<"1.8.7"
|
||||
run rbenv-version-name
|
||||
assert_success "1.8.7"
|
||||
|
||||
cat > ".ruby-version" <<<"1.9.3"
|
||||
run rbenv-version-name
|
||||
assert_success "1.9.3"
|
||||
}
|
||||
|
||||
@test "missing version" {
|
||||
RBENV_VERSION=1.2 run rbenv-version-name
|
||||
assert_failure "rbenv: version \`1.2' is not installed"
|
||||
}
|
||||
|
||||
@test "version with prefix in name" {
|
||||
create_version "1.8.7"
|
||||
cat > ".ruby-version" <<<"ruby-1.8.7"
|
||||
run rbenv-version-name
|
||||
assert_success
|
||||
assert_output <<OUT
|
||||
warning: ignoring extraneous \`ruby-' prefix in version \`ruby-1.8.7'
|
||||
(set by ${PWD}/.ruby-version)
|
||||
1.8.7
|
||||
OUT
|
||||
}
|
38
test/version-origin.bats
Normal file
38
test/version-origin.bats
Normal file
|
@ -0,0 +1,38 @@
|
|||
#!/usr/bin/env bats
|
||||
|
||||
load test_helper
|
||||
|
||||
setup() {
|
||||
mkdir -p "$RBENV_TEST_DIR"
|
||||
cd "$RBENV_TEST_DIR"
|
||||
}
|
||||
|
||||
@test "reports global file even if it doesn't exist" {
|
||||
assert [ ! -e "${RBENV_ROOT}/version" ]
|
||||
run rbenv-version-origin
|
||||
assert_success "${RBENV_ROOT}/version"
|
||||
}
|
||||
|
||||
@test "detects global file" {
|
||||
mkdir -p "$RBENV_ROOT"
|
||||
touch "${RBENV_ROOT}/version"
|
||||
run rbenv-version-origin
|
||||
assert_success "${RBENV_ROOT}/version"
|
||||
}
|
||||
|
||||
@test "detects RBENV_VERSION" {
|
||||
RBENV_VERSION=1 run rbenv-version-origin
|
||||
assert_success "RBENV_VERSION environment variable"
|
||||
}
|
||||
|
||||
@test "detects local file" {
|
||||
touch .ruby-version
|
||||
run rbenv-version-origin
|
||||
assert_success "${PWD}/.ruby-version"
|
||||
}
|
||||
|
||||
@test "detects alternate version file" {
|
||||
touch .rbenv-version
|
||||
run rbenv-version-origin
|
||||
assert_success "${PWD}/.rbenv-version"
|
||||
}
|
38
test/version.bats
Normal file
38
test/version.bats
Normal file
|
@ -0,0 +1,38 @@
|
|||
#!/usr/bin/env bats
|
||||
|
||||
load test_helper
|
||||
|
||||
create_version() {
|
||||
mkdir -p "${RBENV_ROOT}/versions/$1"
|
||||
}
|
||||
|
||||
setup() {
|
||||
mkdir -p "$RBENV_TEST_DIR"
|
||||
cd "$RBENV_TEST_DIR"
|
||||
}
|
||||
|
||||
@test "no version selected" {
|
||||
assert [ ! -d "${RBENV_ROOT}/versions" ]
|
||||
run rbenv-version
|
||||
assert_success "system (set by ${RBENV_ROOT}/version)"
|
||||
}
|
||||
|
||||
@test "set by RBENV_VERSION" {
|
||||
create_version "1.9.3"
|
||||
RBENV_VERSION=1.9.3 run rbenv-version
|
||||
assert_success "1.9.3 (set by RBENV_VERSION environment variable)"
|
||||
}
|
||||
|
||||
@test "set by local file" {
|
||||
create_version "1.9.3"
|
||||
cat > ".ruby-version" <<<"1.9.3"
|
||||
run rbenv-version
|
||||
assert_success "1.9.3 (set by ${PWD}/.ruby-version)"
|
||||
}
|
||||
|
||||
@test "set by global file" {
|
||||
create_version "1.9.3"
|
||||
cat > "${RBENV_ROOT}/version" <<<"1.9.3"
|
||||
run rbenv-version
|
||||
assert_success "1.9.3 (set by ${RBENV_ROOT}/version)"
|
||||
}
|
100
test/versions.bats
Normal file
100
test/versions.bats
Normal file
|
@ -0,0 +1,100 @@
|
|||
#!/usr/bin/env bats
|
||||
|
||||
load test_helper
|
||||
|
||||
create_version() {
|
||||
mkdir -p "${RBENV_ROOT}/versions/$1"
|
||||
}
|
||||
|
||||
@test "no versions installed" {
|
||||
assert [ ! -d "${RBENV_ROOT}/versions" ]
|
||||
run rbenv-versions
|
||||
assert_success "* system (set by ${RBENV_ROOT}/version)"
|
||||
}
|
||||
|
||||
@test "bare output no versions installed" {
|
||||
assert [ ! -d "${RBENV_ROOT}/versions" ]
|
||||
run rbenv-versions --bare
|
||||
assert_success ""
|
||||
}
|
||||
|
||||
@test "single version installed" {
|
||||
create_version "1.9"
|
||||
run rbenv-versions
|
||||
assert_success
|
||||
assert_output <<OUT
|
||||
* system (set by ${RBENV_ROOT}/version)
|
||||
1.9
|
||||
OUT
|
||||
}
|
||||
|
||||
@test "single version bare" {
|
||||
create_version "1.9"
|
||||
run rbenv-versions --bare
|
||||
assert_success "1.9"
|
||||
}
|
||||
|
||||
@test "multiple versions" {
|
||||
create_version "1.8.7"
|
||||
create_version "1.9.3"
|
||||
create_version "2.0.0"
|
||||
run rbenv-versions
|
||||
assert_success
|
||||
assert_output <<OUT
|
||||
* system (set by ${RBENV_ROOT}/version)
|
||||
1.8.7
|
||||
1.9.3
|
||||
2.0.0
|
||||
OUT
|
||||
}
|
||||
|
||||
@test "indicates current version" {
|
||||
create_version "1.9.3"
|
||||
create_version "2.0.0"
|
||||
RBENV_VERSION=1.9.3 run rbenv-versions
|
||||
assert_success
|
||||
assert_output <<OUT
|
||||
system
|
||||
* 1.9.3 (set by RBENV_VERSION environment variable)
|
||||
2.0.0
|
||||
OUT
|
||||
}
|
||||
|
||||
@test "bare doesn't indicate current version" {
|
||||
create_version "1.9.3"
|
||||
create_version "2.0.0"
|
||||
RBENV_VERSION=1.9.3 run rbenv-versions --bare
|
||||
assert_success
|
||||
assert_output <<OUT
|
||||
1.9.3
|
||||
2.0.0
|
||||
OUT
|
||||
}
|
||||
|
||||
@test "globally selected version" {
|
||||
create_version "1.9.3"
|
||||
create_version "2.0.0"
|
||||
cat > "${RBENV_ROOT}/version" <<<"1.9.3"
|
||||
run rbenv-versions
|
||||
assert_success
|
||||
assert_output <<OUT
|
||||
system
|
||||
* 1.9.3 (set by ${RBENV_ROOT}/version)
|
||||
2.0.0
|
||||
OUT
|
||||
}
|
||||
|
||||
@test "per-project version" {
|
||||
create_version "1.9.3"
|
||||
create_version "2.0.0"
|
||||
mkdir -p "$RBENV_TEST_DIR"
|
||||
cd "$RBENV_TEST_DIR"
|
||||
cat > ".ruby-version" <<<"1.9.3"
|
||||
run rbenv-versions
|
||||
assert_success
|
||||
assert_output <<OUT
|
||||
system
|
||||
* 1.9.3 (set by ${RBENV_TEST_DIR}/.ruby-version)
|
||||
2.0.0
|
||||
OUT
|
||||
}
|
30
test/whence.bats
Normal file
30
test/whence.bats
Normal file
|
@ -0,0 +1,30 @@
|
|||
#!/usr/bin/env bats
|
||||
|
||||
load test_helper
|
||||
|
||||
create_executable() {
|
||||
local bin="${RBENV_ROOT}/versions/${1}/bin"
|
||||
mkdir -p "$bin"
|
||||
touch "${bin}/$2"
|
||||
chmod +x "${bin}/$2"
|
||||
}
|
||||
|
||||
@test "finds versions where present" {
|
||||
create_executable "1.8" "ruby"
|
||||
create_executable "1.8" "rake"
|
||||
create_executable "2.0" "ruby"
|
||||
create_executable "2.0" "rspec"
|
||||
|
||||
run rbenv-whence ruby
|
||||
assert_success
|
||||
assert_output <<OUT
|
||||
1.8
|
||||
2.0
|
||||
OUT
|
||||
|
||||
run rbenv-whence rake
|
||||
assert_success "1.8"
|
||||
|
||||
run rbenv-whence rspec
|
||||
assert_success "2.0"
|
||||
}
|
60
test/which.bats
Normal file
60
test/which.bats
Normal file
|
@ -0,0 +1,60 @@
|
|||
#!/usr/bin/env bats
|
||||
|
||||
load test_helper
|
||||
|
||||
create_executable() {
|
||||
local bin
|
||||
if [[ $1 == */* ]]; then bin="$1"
|
||||
else bin="${RBENV_ROOT}/versions/${1}/bin"
|
||||
fi
|
||||
mkdir -p "$bin"
|
||||
touch "${bin}/$2"
|
||||
chmod +x "${bin}/$2"
|
||||
}
|
||||
|
||||
@test "outputs path to executable" {
|
||||
create_executable "1.8" "ruby"
|
||||
create_executable "2.0" "rspec"
|
||||
|
||||
RBENV_VERSION=1.8 run rbenv-which ruby
|
||||
assert_success "${RBENV_ROOT}/versions/1.8/bin/ruby"
|
||||
|
||||
RBENV_VERSION=2.0 run rbenv-which rspec
|
||||
assert_success "${RBENV_ROOT}/versions/2.0/bin/rspec"
|
||||
}
|
||||
|
||||
@test "searches PATH for system version" {
|
||||
create_executable "${RBENV_TEST_DIR}/bin" "kill-all-humans"
|
||||
create_executable "${RBENV_ROOT}/shims" "kill-all-humans"
|
||||
|
||||
RBENV_VERSION=system run rbenv-which kill-all-humans
|
||||
assert_success "${RBENV_TEST_DIR}/bin/kill-all-humans"
|
||||
}
|
||||
|
||||
@test "version not installed" {
|
||||
create_executable "2.0" "rspec"
|
||||
RBENV_VERSION=1.9 run rbenv-which rspec
|
||||
assert_failure "rbenv: version \`1.9' is not installed"
|
||||
}
|
||||
|
||||
@test "no executable found" {
|
||||
create_executable "1.8" "rspec"
|
||||
RBENV_VERSION=1.8 run rbenv-which rake
|
||||
assert_failure "rbenv: rake: command not found"
|
||||
}
|
||||
|
||||
@test "executable found in other versions" {
|
||||
create_executable "1.8" "ruby"
|
||||
create_executable "1.9" "rspec"
|
||||
create_executable "2.0" "rspec"
|
||||
|
||||
RBENV_VERSION=1.8 run rbenv-which rspec
|
||||
assert_failure
|
||||
assert_output <<OUT
|
||||
rbenv: rspec: command not found
|
||||
|
||||
The \`rspec' command exists in these Ruby versions:
|
||||
1.9
|
||||
2.0
|
||||
OUT
|
||||
}
|
Loading…
Reference in a new issue