Merge remote-tracking branch 'origin/master' into version-hooks

This commit is contained in:
Mislav Marohnić 2015-12-23 17:22:43 +01:00
commit 40c1d27445
25 changed files with 347 additions and 103 deletions

1
.gitignore vendored
View file

@ -7,3 +7,4 @@
/libexec/*.dylib
/src/Makefile
/src/*.o
/gems

View file

@ -13,7 +13,7 @@ bulletproof deployments.
**Rock-solid in production.** Your application's executables are its
interface with ops. With rbenv and [Bundler
binstubs](https://github.com/sstephenson/rbenv/wiki/Understanding-binstubs)
binstubs](https://github.com/rbenv/rbenv/wiki/Understanding-binstubs)
you'll never again need to `cd` in a cron job or Chef recipe to
ensure you've selected the right runtime. The Ruby version
dependency lives in one place—your app—so upgrades and rollbacks are
@ -24,12 +24,12 @@ bulletproof deployments.
you tailor it to suit your needs. Compile your own Ruby versions, or
use the [ruby-build][]
plugin to automate the process. Specify per-application environment
variables with [rbenv-vars](https://github.com/sstephenson/rbenv-vars).
variables with [rbenv-vars](https://github.com/rbenv/rbenv-vars).
See more [plugins on the
wiki](https://github.com/sstephenson/rbenv/wiki/Plugins).
wiki](https://github.com/rbenv/rbenv/wiki/Plugins).
[**Why choose rbenv over
RVM?**](https://github.com/sstephenson/rbenv/wiki/Why-rbenv%3F)
RVM?**](https://github.com/rbenv/rbenv/wiki/Why-rbenv%3F)
## Table of Contents
@ -45,6 +45,7 @@ RVM?**](https://github.com/sstephenson/rbenv/wiki/Why-rbenv%3F)
* [How rbenv hooks into your shell](#how-rbenv-hooks-into-your-shell)
* [Installing Ruby Versions](#installing-ruby-versions)
* [Uninstalling Ruby Versions](#uninstalling-ruby-versions)
* [Uninstalling rbenv](#uninstalling-rbenv)
* [Command Reference](#command-reference)
* [rbenv local](#rbenv-local)
* [rbenv global](#rbenv-global)
@ -157,7 +158,7 @@ easy to fork and contribute any changes back upstream.
1. Check out rbenv into `~/.rbenv`.
~~~ sh
$ git clone https://github.com/sstephenson/rbenv.git ~/.rbenv
$ git clone https://github.com/rbenv/rbenv.git ~/.rbenv
~~~
2. Add `~/.rbenv/bin` to your `$PATH` for access to the `rbenv`
@ -298,6 +299,30 @@ Ruby version with the `rbenv prefix` command, e.g. `rbenv prefix
The [ruby-build][] plugin provides an `rbenv uninstall` command to
automate the removal process.
### Uninstalling rbenv
The simplicity of rbenv makes it easy to temporarily disable it, or
uninstall from the system.
1. To **disable** rbenv managing your Ruby versions, simply remove the
`rbenv init` line from your shell startup configuration. This will
remove rbenv shims directory from PATH, and future invocations like
`ruby` will execute the system Ruby version, as before rbenv.
`rbenv` will still be accessible on the command line, but your Ruby
apps won't be affected by version switching.
2. To completely **uninstall** rbenv, perform step (1) and then remove
its root directory. This will **delete all Ruby versions** that were
installed under `` `rbenv root`/versions/ `` directory:
rm -rf `rbenv root`
If you've installed rbenv using a package manager, as a final step
perform the rbenv package removal. For instance, for Homebrew:
brew uninstall rbenv
## Command Reference
Like `git`, the `rbenv` command delegates to subcommands based on its
@ -419,7 +444,7 @@ name | default | description
## Development
The rbenv source code is [hosted on
GitHub](https://github.com/sstephenson/rbenv). It's clean, modular,
GitHub](https://github.com/rbenv/rbenv). It's clean, modular,
and easy to understand, even if you're not a shell hacker.
Tests are executed using [Bats](https://github.com/sstephenson/bats):
@ -428,8 +453,8 @@ Tests are executed using [Bats](https://github.com/sstephenson/bats):
$ bats test/<file>.bats
Please feel free to submit pull requests and file bugs on the [issue
tracker](https://github.com/sstephenson/rbenv/issues).
tracker](https://github.com/rbenv/rbenv/issues).
[ruby-build]: https://github.com/sstephenson/ruby-build#readme
[hooks]: https://github.com/sstephenson/rbenv/wiki/Authoring-plugins#rbenv-hooks
[ruby-build]: https://github.com/rbenv/ruby-build#readme
[hooks]: https://github.com/rbenv/rbenv/wiki/Authoring-plugins#rbenv-hooks

View file

@ -16,7 +16,7 @@ export RBENV_DIR="${1%/*}"
[ -n "$RBENV_SILENCE_WARNINGS" ] || {
echo "rbenv: \`ruby-local-exec' is deprecated and will be removed in the next release."
echo " To upgrade: https://github.com/sstephenson/rbenv/wiki/ruby-local-exec"
echo " To upgrade: https://github.com/rbenv/rbenv/wiki/ruby-local-exec"
echo
} >&2

View file

@ -12,28 +12,31 @@ if [ -n "$RBENV_DEBUG" ]; then
set -x
fi
if enable -f "${0%/*}"/../libexec/rbenv-realpath.dylib realpath 2>/dev/null; then
abort() {
{ if [ "$#" -eq 0 ]; then cat -
else echo "rbenv: $*"
fi
} >&2
exit 1
}
if enable -f "${BASH_SOURCE%/*}"/../libexec/rbenv-realpath.dylib realpath 2>/dev/null; then
abs_dirname() {
local path="$(realpath "$1")"
echo "${path%/*}"
}
else
if [ -n "$RBENV_NATIVE_EXT" ]; then
echo "rbenv: failed to load \`realpath' builtin" >&2
exit 1
fi
[ -z "$RBENV_NATIVE_EXT" ] || abort "failed to load \`realpath' builtin"
READLINK=$(type -p greadlink readlink | head -1)
if [ -z "$READLINK" ]; then
echo "rbenv: cannot find readlink - are you missing GNU coreutils?" >&2
exit 1
fi
[ -n "$READLINK" ] || abort "cannot find readlink - are you missing GNU coreutils?"
resolve_link() {
$READLINK "$1"
}
abs_dirname() {
local cwd="$(pwd)"
local cwd="$PWD"
local path="$1"
while [ -n "$path" ]; do
@ -55,13 +58,10 @@ fi
export RBENV_ROOT
if [ -z "${RBENV_DIR}" ]; then
RBENV_DIR="$(pwd)"
RBENV_DIR="$PWD"
else
cd "$RBENV_DIR" 2>/dev/null || {
echo "rbenv: cannot change working directory to \`$RBENV_DIR'"
exit 1
} >&2
RBENV_DIR="$(pwd)"
cd "$RBENV_DIR" 2>/dev/null || abort "cannot change working directory to \`$RBENV_DIR'"
RBENV_DIR="$PWD"
cd "$OLDPWD"
fi
export RBENV_DIR
@ -91,20 +91,26 @@ shopt -u nullglob
command="$1"
case "$command" in
"" | "-h" | "--help" )
echo -e "$(rbenv---version)\n$(rbenv-help)" >&2
"" )
{ rbenv---version
rbenv-help
} | abort
;;
"-v" )
-v | --version )
exec rbenv---version
;;
-h | --help )
exec rbenv-help
;;
* )
command_path="$(command -v "rbenv-$command" || true)"
if [ -z "$command_path" ]; then
echo "rbenv: no such command \`$command'" >&2
exit 1
fi
[ -n "$command_path" ] || abort "no such command \`$command'"
shift 1
if [ "$1" = --help ]; then
exec rbenv-help "$command"
else
exec "$command_path" "$@"
fi
;;
esac

View file

@ -13,10 +13,14 @@ set -e
[ -n "$RBENV_DEBUG" ] && set -x
version="0.4.0"
git_revision=""
if cd "$RBENV_ROOT" 2>/dev/null; then
for source_dir in "${BASH_SOURCE%/*}" "$RBENV_ROOT"; do
if cd "$source_dir" 2>/dev/null && git remote -v 2>/dev/null | grep -q rbenv; then
git_revision="$(git describe --tags HEAD 2>/dev/null || true)"
git_revision="${git_revision#v}"
[ -z "$git_revision" ] || break
fi
done
echo "rbenv ${git_revision:-$version}"

View file

@ -10,7 +10,16 @@ if [ -z "$COMMAND" ]; then
exit 1
fi
# Provide rbenv completions
if [ "$COMMAND" = "--complete" ]; then
exec rbenv-commands
fi
COMMAND_PATH="$(command -v "rbenv-$COMMAND" || command -v "rbenv-sh-$COMMAND")"
# --help is provided automatically
echo --help
if grep -iE "^([#%]|--|//) provide rbenv completions" "$COMMAND_PATH" >/dev/null; then
shift
exec "$COMMAND_PATH" --complete "$@"

View file

@ -15,6 +15,12 @@
set -e
[ -n "$RBENV_DEBUG" ] && set -x
# Provide rbenv completions
if [ "$1" = "--complete" ]; then
echo --usage
exec rbenv-commands
fi
command_path() {
local command="$1"
command -v rbenv-"$command" || command -v rbenv-sh-"$command" || true
@ -146,7 +152,7 @@ if [ -z "$1" ] || [ "$1" == "rbenv" ]; then
print_summaries commands local global shell install uninstall rehash version versions which whence
echo
echo "See \`rbenv help <command>' for information on a specific command."
echo "For full documentation, see: https://github.com/sstephenson/rbenv#readme"
echo "For full documentation, see: https://github.com/rbenv/rbenv#readme"
else
command="$1"
if [ -n "$(command_path "$command")" ]; then

View file

@ -37,16 +37,17 @@ resolve_link() {
}
realpath() {
local cwd="$(pwd)"
local cwd="$PWD"
local path="$1"
local name
while [ -n "$path" ]; do
cd "${path%/*}"
local name="${path##*/}"
name="${path##*/}"
[ "$name" = "$path" ] || cd "${path%/*}"
path="$(resolve_link "$name" || true)"
done
echo "$(pwd)/$name"
echo "${PWD}/$name"
cd "$cwd"
}
fi

View file

@ -5,6 +5,17 @@
set -e
[ -n "$RBENV_DEBUG" ] && set -x
# Provide rbenv completions
if [ "$1" = "--complete" ]; then
echo -
echo --no-rehash
echo bash
echo fish
echo ksh
echo zsh
exit
fi
print=""
no_rehash=""
for args in "$@"
@ -25,7 +36,8 @@ if [ -z "$shell" ]; then
shell="$(ps c -p "$PPID" -o 'ucomm=' 2>/dev/null || true)"
shell="${shell##-}"
shell="${shell%% *}"
shell="$(basename "${shell:-$SHELL}")"
shell="${shell:-$SHELL}"
shell="${shell##*/}"
fi
root="${0%/*}/.."
@ -33,7 +45,11 @@ root="${0%/*}/.."
if [ -z "$print" ]; then
case "$shell" in
bash )
if [ -f "${HOME}/.bashrc" ] && [ ! -f "${HOME}/.bash_profile" ]; then
profile='~/.bashrc'
else
profile='~/.bash_profile'
fi
;;
zsh )
profile='~/.zshrc'
@ -49,7 +65,7 @@ if [ -z "$print" ]; then
;;
esac
{ echo "# Load rbenv automatically by adding"
{ echo "# Load rbenv automatically by appending"
echo "# the following to ${profile}:"
echo
case "$shell" in
@ -88,7 +104,7 @@ if [ -r "$completion" ]; then
fi
if [ -z "$no_rehash" ]; then
echo 'rbenv rehash 2>/dev/null'
echo 'command rbenv rehash 2>/dev/null'
fi
commands=(`rbenv-commands --sh`)
@ -101,7 +117,7 @@ function rbenv
switch "\$command"
case ${commands[*]}
eval (rbenv "sh-\$command" \$argv)
. (rbenv "sh-\$command" \$argv|psub)
case '*'
command rbenv "\$command" \$argv
end
@ -132,7 +148,7 @@ cat <<EOS
case "\$command" in
${commands[*]})
eval "\`rbenv "sh-\$command" "\$@"\`";;
eval "\$(rbenv "sh-\$command" "\$@")";;
*)
command rbenv "\$command" "\$@";;
esac

View file

@ -81,10 +81,13 @@ remove_outdated_shims() {
# List basenames of executables for every Ruby version
list_executable_names() {
local file
for file in "$RBENV_ROOT"/versions/*/bin/*; do
local version file
rbenv-versions --bare --skip-aliases | \
while read version; do
for file in "${RBENV_ROOT}/versions/${version}/bin/"*; do
echo "${file##*/}"
done
done
}
# The basename of each argument passed to `make_shims` will be
@ -110,7 +113,7 @@ install_registered_shims() {
local shim file
for shim in $registered_shims; do
file="${SHIM_PATH}/${shim}"
[ -e "$file" ] || ln -f "$PROTOTYPE_SHIM_PATH" "$file"
[ -e "$file" ] || cp "$PROTOTYPE_SHIM_PATH" "$file"
done
}

View file

@ -5,7 +5,8 @@ set -e
find_local_version_file() {
local root="$1"
while [ -n "$root" ]; do
while true; do
[[ "$root" =~ ^//[^/]*$ ]] && break
if [ -e "${root}/.ruby-version" ]; then
echo "${root}/.ruby-version"
exit
@ -13,6 +14,7 @@ find_local_version_file() {
echo "${root}/.rbenv-version"
exit
fi
[ -n "$root" ] || break
root="${root%/*}"
done
}

View file

@ -30,6 +30,6 @@ if version_exists "$RBENV_VERSION"; then
elif version_exists "${RBENV_VERSION#ruby-}"; then
echo "${RBENV_VERSION#ruby-}"
else
echo "rbenv: version \`$RBENV_VERSION' is not installed" >&2
echo "rbenv: version \`$RBENV_VERSION' is not installed (set by $(rbenv-version-origin))" >&2
exit 1
fi

View file

@ -1,13 +1,69 @@
#!/usr/bin/env bash
# Summary: List all Ruby versions available to rbenv
# Usage: rbenv versions [--bare]
# Usage: rbenv versions [--bare] [--skip-aliases]
#
# Lists all Ruby versions found in `$RBENV_ROOT/versions/*'.
set -e
[ -n "$RBENV_DEBUG" ] && set -x
if [ "$1" = "--bare" ]; then
unset bare
unset skip_aliases
# Provide rbenv completions
for arg; do
case "$arg" in
--complete )
echo --bare
echo --skip-aliases
exit ;;
--bare ) bare=1 ;;
--skip-aliases ) skip_aliases=1 ;;
* )
rbenv-help --usage versions >&2
exit 1
;;
esac
done
versions_dir="${RBENV_ROOT}/versions"
if ! enable -f "${BASH_SOURCE%/*}"/../libexec/rbenv-realpath.dylib realpath 2>/dev/null; then
if [ -n "$RBENV_NATIVE_EXT" ]; then
echo "rbenv: failed to load \`realpath' builtin" >&2
exit 1
fi
READLINK=$(type -p greadlink readlink | head -1)
if [ -z "$READLINK" ]; then
echo "rbenv: cannot find readlink - are you missing GNU coreutils?" >&2
exit 1
fi
resolve_link() {
$READLINK "$1"
}
realpath() {
local cwd="$PWD"
local path="$1"
local name
while [ -n "$path" ]; do
name="${path##*/}"
[ "$name" = "$path" ] || cd "${path%/*}"
path="$(resolve_link "$name" || true)"
done
echo "${PWD}/$name"
cd "$cwd"
}
fi
if [ -d "$versions_dir" ]; then
versions_dir="$(realpath "$versions_dir")"
fi
if [ -n "$bare" ]; then
hit_prefix=""
miss_prefix=""
current_version=""
@ -36,8 +92,12 @@ if [ -n "$include_system" ] && RBENV_VERSION=system rbenv-which ruby >/dev/null
fi
shopt -s nullglob
for path in "${RBENV_ROOT}/versions/"*; do
for path in "$versions_dir"/*; do
if [ -d "$path" ]; then
if [ -n "$skip_aliases" ] && [ -L "$path" ]; then
target="$(realpath "$path")"
[ "${target%/*}" != "$versions_dir" ] || continue
fi
print_version "${path##*/}"
fi
done

View file

@ -23,7 +23,8 @@ remove_from_path() {
path_before="$result"
result="${result//:$path_to_remove:/:}"
done
echo "${result%:}"
result="${result%:}"
echo "${result#:}"
}
RBENV_COMMAND="$1"
@ -51,8 +52,8 @@ done
if [ -x "$RBENV_COMMAND_PATH" ]; then
echo "$RBENV_COMMAND_PATH"
elif ! [ -d "${RBENV_ROOT}/versions/${RBENV_VERSION}" ]; then
echo "rbenv: version \`$RBENV_VERSION' is not installed" >&2
elif [ "$RBENV_VERSION" != "system" ] && [ ! -d "${RBENV_ROOT}/versions/${RBENV_VERSION}" ]; then
echo "rbenv: version \`$RBENV_VERSION' is not installed (set by $(rbenv-version-origin))" >&2
exit 1
else
echo "rbenv: $RBENV_COMMAND: command not found" >&2

View file

@ -6,13 +6,38 @@ hook = lambda do |installer|
`rbenv rehash`
end
rescue
warn "rbenv: error in gem-rehash (#{$!})"
warn "rbenv: error in gem-rehash (#{$!.class.name}: #{$!.message})"
end
end
if defined?(Bundler::Installer) && Bundler::Installer.respond_to?(:install) && !Bundler::Installer.respond_to?(:install_without_rbenv_rehash)
Bundler::Installer.class_eval do
class << self
alias install_without_rbenv_rehash install
def install(root, definition, options = {})
begin
if Gem.default_path.include?(Bundler.bundle_path.to_s)
bin_dir = Gem.bindir(Bundler.bundle_path.to_s)
bins_before = File.exist?(bin_dir) ? Dir.entries(bin_dir).size : 2
end
rescue
warn "rbenv: error in Bundler post-install hook (#{$!.class.name}: #{$!.message})"
end
result = install_without_rbenv_rehash(root, definition, options)
if bin_dir && File.exist?(bin_dir) && Dir.entries(bin_dir).size > bins_before
`rbenv rehash`
end
result
end
end
end
else
begin
Gem.post_install(&hook)
Gem.post_uninstall(&hook)
rescue
warn "rbenv: error installing gem-rehash hooks (#{$!})"
warn "rbenv: error installing gem-rehash hooks (#{$!.class.name}: #{$!.message})"
end
end

View file

@ -6,6 +6,18 @@ setup() {
mkdir -p "$HOME"
git config --global user.name "Tester"
git config --global user.email "tester@test.local"
mkdir -p "${RBENV_TEST_DIR}/bin"
cat > "${RBENV_TEST_DIR}/bin/git" <<CMD
#!$BASH
if [[ \$1 == remote && \$PWD != "\$RBENV_TEST_DIR"/* ]]; then
echo "not allowed" >&2
exit 1
else
exec $(which git) "\$@"
fi
CMD
chmod +x "${RBENV_TEST_DIR}/bin/git"
}
git_commit() {
@ -19,10 +31,25 @@ git_commit() {
[[ $output == "rbenv 0."* ]]
}
@test "doesn't read version from non-rbenv repo" {
mkdir -p "$RBENV_ROOT"
cd "$RBENV_ROOT"
git init
git remote add origin https://github.com/homebrew/homebrew.git
git_commit
git tag v1.0
cd "$RBENV_TEST_DIR"
run rbenv---version
assert_success
[[ $output == "rbenv 0."* ]]
}
@test "reads version from git repo" {
mkdir -p "$RBENV_ROOT"
cd "$RBENV_ROOT"
git init
git remote add origin https://github.com/rbenv/rbenv.git
git_commit
git tag v0.4.1
git_commit
@ -38,6 +65,7 @@ git_commit() {
mkdir -p "$RBENV_ROOT"
cd "$RBENV_ROOT"
git init
git remote add origin https://github.com/rbenv/rbenv.git
git_commit
cd "$RBENV_TEST_DIR"

View file

@ -13,7 +13,7 @@ create_command() {
create_command "rbenv-hello" "#!$BASH
echo hello"
run rbenv-completions hello
assert_success ""
assert_success "--help"
}
@test "command with completion support" {
@ -25,7 +25,11 @@ else
exit 1
fi"
run rbenv-completions hello
assert_success "hello"
assert_success
assert_output <<OUT
--help
hello
OUT
}
@test "forwards extra arguments" {
@ -40,6 +44,7 @@ fi"
run rbenv-completions hello happy world
assert_success
assert_output <<OUT
--help
happy
world
OUT

View file

@ -17,7 +17,15 @@ create_executable() {
@test "fails with invalid version" {
export RBENV_VERSION="2.0"
run rbenv-exec ruby -v
assert_failure "rbenv: version \`2.0' is not installed"
assert_failure "rbenv: version \`2.0' is not installed (set by RBENV_VERSION environment variable)"
}
@test "fails with invalid version set from file" {
mkdir -p "$RBENV_TEST_DIR"
cd "$RBENV_TEST_DIR"
echo 1.9 > .ruby-version
run rbenv-exec rspec
assert_failure "rbenv: version \`1.9' is not installed (set by $PWD/.ruby-version)"
}
@test "completes with names of executables" {
@ -29,6 +37,7 @@ create_executable() {
run rbenv-completions exec
assert_success
assert_output <<OUT
--help
rake
ruby
OUT

View file

@ -59,7 +59,13 @@ OUT
mkdir -p "$HOME"
touch "${HOME}/hola.bash"
ln -s "../../home/hola.bash" "${path}/exec/hello.bash"
touch "${path}/exec/bright.sh"
ln -s "bright.sh" "${path}/exec/world.bash"
RBENV_HOOK_PATH="$path" run rbenv-hooks exec
assert_success "${HOME}/hola.bash"
assert_success
assert_output <<OUT
${HOME}/hola.bash
${RBENV_TEST_DIR}/rbenv.d/exec/bright.sh
OUT
}

View file

@ -14,7 +14,7 @@ load test_helper
@test "auto rehash" {
run rbenv-init -
assert_success
assert_line "rbenv rehash 2>/dev/null"
assert_line "command rbenv rehash 2>/dev/null"
}
@test "setup shell completions" {

View file

@ -4,8 +4,8 @@ load test_helper
@test "blank invocation" {
run rbenv
assert_success
assert [ "${lines[0]}" = "rbenv 0.4.0" ]
assert_failure
assert_line 0 "$(rbenv---version)"
}
@test "invalid command" {

View file

@ -1,18 +1,20 @@
unset RBENV_VERSION
unset RBENV_DIR
# guard against executing this block twice due to bats internals
if [ -z "$RBENV_TEST_DIR" ]; then
RBENV_TEST_DIR="${BATS_TMPDIR}/rbenv"
export RBENV_TEST_DIR="$(mktemp -d "${RBENV_TEST_DIR}.XXX" 2>/dev/null || echo "$RBENV_TEST_DIR")"
if enable -f "${BATS_TEST_DIRNAME}"/../libexec/rbenv-realpath.dylib realpath 2>/dev/null; then
RBENV_TEST_DIR="$(realpath "$BATS_TMPDIR")/rbenv"
export RBENV_TEST_DIR="$(realpath "$RBENV_TEST_DIR")"
else
if [ -n "$RBENV_NATIVE_EXT" ]; then
echo "rbenv: failed to load \`realpath' builtin" >&2
exit 1
fi
RBENV_TEST_DIR="${BATS_TMPDIR}/rbenv"
fi
# guard against executing this block twice due to bats internals
if [ "$RBENV_ROOT" != "${RBENV_TEST_DIR}/root" ]; then
export RBENV_ROOT="${RBENV_TEST_DIR}/root"
export HOME="${RBENV_TEST_DIR}/home"
@ -22,6 +24,9 @@ if [ "$RBENV_ROOT" != "${RBENV_TEST_DIR}/root" ]; then
PATH="${BATS_TEST_DIRNAME}/libexec:$PATH"
PATH="${RBENV_ROOT}/shims:$PATH"
export PATH
for xdg_var in `env 2>/dev/null | grep ^XDG_ | cut -d= -f1`; do unset "$xdg_var"; done
unset xdg_var
fi
teardown() {
@ -106,7 +111,7 @@ assert() {
# but in which system utils necessary for rbenv operation are still available.
path_without() {
local exe="$1"
local path="${PATH}:"
local path=":${PATH}:"
local found alt util
for found in $(which -a "$exe"); do
found="${found%/*}"
@ -118,8 +123,9 @@ path_without() {
ln -s "${found}/$util" "${alt}/$util"
fi
done
path="${path/${found}:/${alt}:}"
path="${path/:${found}:/:${alt}:}"
fi
done
path="${path#:}"
echo "${path%:}"
}

View file

@ -68,7 +68,7 @@ setup() {
@test "missing version" {
RBENV_VERSION=1.2 run rbenv-version-name
assert_failure "rbenv: version \`1.2' is not installed"
assert_failure "rbenv: version \`1.2' is not installed (set by RBENV_VERSION environment variable)"
}
@test "version with prefix in name" {

View file

@ -139,3 +139,18 @@ OUT
1.8.7
OUT
}
@test "doesn't list symlink aliases when --skip-aliases" {
create_version "1.8.7"
ln -s "1.8.7" "${RBENV_ROOT}/versions/1.8"
mkdir moo
ln -s "${PWD}/moo" "${RBENV_ROOT}/versions/1.9"
run rbenv-versions --bare --skip-aliases
assert_success
assert_output <<OUT
1.8.7
1.9
OUT
}

View file

@ -56,10 +56,20 @@ create_executable() {
assert_success "${RBENV_TEST_DIR}/bin/kill-all-humans"
}
@test "doesn't include current directory in PATH search" {
export PATH="$(path_without "kill-all-humans")"
mkdir -p "$RBENV_TEST_DIR"
cd "$RBENV_TEST_DIR"
touch kill-all-humans
chmod +x kill-all-humans
RBENV_VERSION=system run rbenv-which kill-all-humans
assert_failure "rbenv: kill-all-humans: command not found"
}
@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"
assert_failure "rbenv: version \`1.9' is not installed (set by RBENV_VERSION environment variable)"
}
@test "no executable found" {
@ -68,6 +78,12 @@ create_executable() {
assert_failure "rbenv: rake: command not found"
}
@test "no executable found for system version" {
export PATH="$(path_without "rake")"
RBENV_VERSION=system 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"