2013-02-24 08:52:50 -05:00
|
|
|
#!/usr/bin/env bats
|
|
|
|
|
|
|
|
load test_helper
|
|
|
|
|
2013-03-31 20:58:58 -04:00
|
|
|
create_executable() {
|
2013-11-03 05:18:28 -05:00
|
|
|
name="${1?}"
|
2013-04-01 20:48:04 -04:00
|
|
|
shift 1
|
2013-11-03 05:18:28 -05:00
|
|
|
bin="${RBENV_ROOT}/versions/${RBENV_VERSION}/bin"
|
|
|
|
mkdir -p "$bin"
|
2013-04-01 20:48:04 -04:00
|
|
|
{ if [ $# -eq 0 ]; then cat -
|
|
|
|
else echo "$@"
|
|
|
|
fi
|
2013-11-03 05:18:28 -05:00
|
|
|
} | sed -Ee '1s/^ +//' > "${bin}/$name"
|
|
|
|
chmod +x "${bin}/$name"
|
2013-03-31 20:58:58 -04:00
|
|
|
}
|
|
|
|
|
2013-03-31 21:01:37 -04:00
|
|
|
@test "fails with invalid version" {
|
|
|
|
export RBENV_VERSION="2.0"
|
|
|
|
run rbenv-exec ruby -v
|
2015-07-17 11:10:33 -04:00
|
|
|
assert_failure "rbenv: version \`2.0' is not installed (set by RBENV_VERSION environment variable)"
|
2013-03-31 21:01:37 -04:00
|
|
|
}
|
|
|
|
|
2015-11-13 22:53:27 -05:00
|
|
|
@test "fails with invalid version set from file" {
|
2015-11-20 09:51:21 -05:00
|
|
|
mkdir -p "$RBENV_TEST_DIR"
|
|
|
|
cd "$RBENV_TEST_DIR"
|
2015-11-13 22:53:27 -05:00
|
|
|
echo 1.9 > .ruby-version
|
|
|
|
run rbenv-exec rspec
|
|
|
|
assert_failure "rbenv: version \`1.9' is not installed (set by $PWD/.ruby-version)"
|
|
|
|
}
|
|
|
|
|
2013-03-31 21:44:19 -04:00
|
|
|
@test "completes with names of executables" {
|
|
|
|
export RBENV_VERSION="2.0"
|
2013-04-01 20:48:04 -04:00
|
|
|
create_executable "ruby" "#!/bin/sh"
|
|
|
|
create_executable "rake" "#!/bin/sh"
|
2013-03-31 21:44:19 -04:00
|
|
|
|
|
|
|
rbenv-rehash
|
|
|
|
run rbenv-completions exec
|
2013-04-06 08:10:44 -04:00
|
|
|
assert_success
|
|
|
|
assert_output <<OUT
|
2015-11-17 15:01:33 -05:00
|
|
|
--help
|
2013-04-06 08:10:44 -04:00
|
|
|
rake
|
|
|
|
ruby
|
|
|
|
OUT
|
2013-03-31 21:44:19 -04:00
|
|
|
}
|
|
|
|
|
2013-02-24 08:52:50 -05:00
|
|
|
@test "supports hook path with spaces" {
|
|
|
|
hook_path="${RBENV_TEST_DIR}/custom stuff/rbenv hooks"
|
|
|
|
mkdir -p "${hook_path}/exec"
|
|
|
|
echo "export HELLO='from hook'" > "${hook_path}/exec/hello.bash"
|
|
|
|
|
|
|
|
export RBENV_VERSION=system
|
|
|
|
RBENV_HOOK_PATH="$hook_path" run rbenv-exec env
|
|
|
|
assert_success
|
|
|
|
assert_line "HELLO=from hook"
|
|
|
|
}
|
2013-03-31 20:58:58 -04:00
|
|
|
|
2013-04-16 08:01:04 -04:00
|
|
|
@test "carries original IFS within hooks" {
|
|
|
|
hook_path="${RBENV_TEST_DIR}/rbenv.d"
|
|
|
|
mkdir -p "${hook_path}/exec"
|
|
|
|
cat > "${hook_path}/exec/hello.bash" <<SH
|
|
|
|
hellos=(\$(printf "hello\\tugly world\\nagain"))
|
|
|
|
echo HELLO="\$(printf ":%s" "\${hellos[@]}")"
|
|
|
|
SH
|
|
|
|
|
|
|
|
export RBENV_VERSION=system
|
|
|
|
RBENV_HOOK_PATH="$hook_path" IFS=$' \t\n' run rbenv-exec env
|
|
|
|
assert_success
|
|
|
|
assert_line "HELLO=:hello:ugly:world:again"
|
|
|
|
}
|
|
|
|
|
2013-03-31 20:58:58 -04:00
|
|
|
@test "forwards all arguments" {
|
|
|
|
export RBENV_VERSION="2.0"
|
2013-04-01 20:48:04 -04:00
|
|
|
create_executable "ruby" <<SH
|
|
|
|
#!$BASH
|
|
|
|
echo \$0
|
|
|
|
for arg; do
|
|
|
|
# hack to avoid bash builtin echo which can't output '-e'
|
2013-04-06 08:10:44 -04:00
|
|
|
printf " %s\\n" "\$arg"
|
2013-04-01 20:48:04 -04:00
|
|
|
done
|
|
|
|
SH
|
2013-03-31 20:58:58 -04:00
|
|
|
|
2013-04-06 08:10:44 -04:00
|
|
|
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
|
2013-03-31 20:58:58 -04:00
|
|
|
}
|
|
|
|
|
2013-11-03 05:18:28 -05:00
|
|
|
@test "supports ruby -S <cmd>" {
|
2013-06-20 11:22:15 -04:00
|
|
|
export RBENV_VERSION="2.0"
|
2013-04-01 20:48:27 -04:00
|
|
|
|
2013-11-03 05:18:28 -05:00
|
|
|
# emulate `ruby -S' behavior
|
2013-06-20 11:22:15 -04:00
|
|
|
create_executable "ruby" <<SH
|
|
|
|
#!$BASH
|
2013-11-03 05:18:28 -05:00
|
|
|
if [[ \$1 == "-S"* ]]; then
|
|
|
|
found="\$(PATH="\${RUBYPATH:-\$PATH}" which \$2)"
|
|
|
|
# assert that the found executable has ruby for shebang
|
|
|
|
if head -1 "\$found" | grep ruby >/dev/null; then
|
|
|
|
\$BASH "\$found"
|
|
|
|
else
|
|
|
|
echo "ruby: no Ruby script found in input (LoadError)" >&2
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
else
|
|
|
|
echo 'ruby 2.0 (rbenv test)'
|
|
|
|
fi
|
2013-06-20 11:22:15 -04:00
|
|
|
SH
|
|
|
|
|
2013-04-06 08:10:44 -04:00
|
|
|
create_executable "rake" <<SH
|
|
|
|
#!/usr/bin/env ruby
|
|
|
|
echo hello rake
|
|
|
|
SH
|
2013-03-31 20:58:58 -04:00
|
|
|
|
|
|
|
rbenv-rehash
|
|
|
|
run ruby -S rake
|
2013-04-01 20:48:27 -04:00
|
|
|
assert_success "hello rake"
|
2013-03-31 20:58:58 -04:00
|
|
|
}
|