New Upstream Release - rbenv
Ready changes
Summary
Merged new upstream version: 1.2.0 (was: 1.1.2).
Resulting package
Built on 2022-11-21T19:43 (took 4m10s)
The resulting binary packages can be installed (if you have the apt repository enabled) by running one of:
apt install -t fresh-releases rbenv
Diff
diff --git a/.agignore b/.agignore
deleted file mode 100644
index 3a0f784..0000000
--- a/.agignore
+++ /dev/null
@@ -1,2 +0,0 @@
-./versions
-./cache
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
new file mode 100644
index 0000000..f550c48
--- /dev/null
+++ b/.github/workflows/ci.yml
@@ -0,0 +1,19 @@
+name: CI
+on: [push, pull_request]
+
+jobs:
+ build:
+ runs-on: ${{ matrix.os }}
+ strategy:
+ matrix:
+ native_ext: ['', '1']
+ os: [ubuntu-latest, macOS-latest]
+
+ steps:
+ - uses: actions/checkout@v2
+ - name: Install bats
+ run: git clone --depth 1 https://github.com/sstephenson/bats.git
+ - name: Run tests
+ env:
+ RBENV_NATIVE_EXT: ${{ matrix.native_ext }}
+ run: PATH="./bats/bin:$PATH" test/run
diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml
new file mode 100644
index 0000000..0fb735a
--- /dev/null
+++ b/.github/workflows/release.yml
@@ -0,0 +1,16 @@
+name: Release
+on:
+ push:
+ tags: 'v*'
+
+jobs:
+ homebrew:
+ name: Bump Homebrew formula
+ runs-on: ubuntu-latest
+ steps:
+ - uses: mislav/bump-homebrew-formula-action@v1.4
+ if: "!contains(github.ref, '-')" # skip prereleases
+ with:
+ formula-name: rbenv
+ env:
+ COMMITTER_TOKEN: ${{ secrets.COMMITTER_TOKEN }}
diff --git a/.travis.yml b/.travis.yml
deleted file mode 100644
index acc69ef..0000000
--- a/.travis.yml
+++ /dev/null
@@ -1,7 +0,0 @@
-sudo: false
-install: git clone --depth 1 https://github.com/sstephenson/bats.git
-script: PATH="./bats/bin:$PATH" test/run
-language: c
-env:
- - RBENV_NATIVE_EXT=
- - RBENV_NATIVE_EXT=1
diff --git a/CONDUCT.md b/CODE_OF_CONDUCT.md
similarity index 100%
rename from CONDUCT.md
rename to CODE_OF_CONDUCT.md
diff --git a/README.md b/README.md
index 8e18191..ba14299 100644
--- a/README.md
+++ b/README.md
@@ -31,35 +31,6 @@ bulletproof deployments.
[**Why choose rbenv over
RVM?**](https://github.com/rbenv/rbenv/wiki/Why-rbenv%3F)
-## Table of Contents
-
-* [How It Works](#how-it-works)
- * [Understanding PATH](#understanding-path)
- * [Understanding Shims](#understanding-shims)
- * [Choosing the Ruby Version](#choosing-the-ruby-version)
- * [Locating the Ruby Installation](#locating-the-ruby-installation)
-* [Installation](#installation)
- * [Homebrew on macOS](#homebrew-on-macos)
- * [Upgrading with Homebrew](#upgrading-with-homebrew)
- * [Basic GitHub Checkout](#basic-github-checkout)
- * [Upgrading with Git](#upgrading-with-git)
- * [How rbenv hooks into your shell](#how-rbenv-hooks-into-your-shell)
- * [Installing Ruby versions](#installing-ruby-versions)
- * [Installing Ruby gems](#installing-ruby-gems)
- * [Uninstalling Ruby versions](#uninstalling-ruby-versions)
- * [Uninstalling rbenv](#uninstalling-rbenv)
-* [Command Reference](#command-reference)
- * [rbenv local](#rbenv-local)
- * [rbenv global](#rbenv-global)
- * [rbenv shell](#rbenv-shell)
- * [rbenv versions](#rbenv-versions)
- * [rbenv version](#rbenv-version)
- * [rbenv rehash](#rbenv-rehash)
- * [rbenv which](#rbenv-which)
- * [rbenv whence](#rbenv-whence)
-* [Environment variables](#environment-variables)
-* [Development](#development)
-
## How It Works
At a high level, rbenv intercepts Ruby commands using shim
@@ -149,19 +120,37 @@ Version names to rbenv are simply the names of the directories in
sure to fully uninstall RVM and remove any references to it from
your shell initialization files before installing rbenv.
-### Homebrew on macOS
+### Using Package Managers
+1. Install rbenv.
+- **macOS**
If you're on macOS, we recommend installing rbenv with
[Homebrew](https://brew.sh).
-1. Install rbenv.
-
~~~ sh
$ brew install rbenv
~~~
-
+
Note that this also installs `ruby-build`, so you'll be ready to
install other Ruby versions out of the box.
+
+ - **Upgrading with Homebrew**
+
+ To upgrade to the latest rbenv and update ruby-build with newly released
+ Ruby versions, upgrade the Homebrew packages:
+
+ ~~~ sh
+ $ brew upgrade rbenv ruby-build
+ ~~~
+- **Debian, Ubuntu and their derivatives**
+ ~~~ sh
+ $ sudo apt install rbenv
+ ~~~
+- **Arch Linux and it's derivatives**
+
+ Archlinux has an [AUR Package](https://aur.archlinux.org/packages/rbenv/) for
+ rbenv and you can install it from the AUR using the instructions from this
+ [wiki page](https://wiki.archlinux.org/index.php/Arch_User_Repository#Installing_and_upgrading_packages).
2. Set up rbenv in your shell.
@@ -175,10 +164,10 @@ If you're on macOS, we recommend installing rbenv with
effect.
4. Verify that rbenv is properly set up using this
- [rbenv-doctor](https://github.com/rbenv/rbenv-installer/blob/master/bin/rbenv-doctor) script:
+ [rbenv-doctor](https://github.com/rbenv/rbenv-installer/blob/main/bin/rbenv-doctor) script:
~~~ sh
- $ curl -fsSL https://github.com/rbenv/rbenv-installer/raw/master/bin/rbenv-doctor | bash
+ $ curl -fsSL https://github.com/rbenv/rbenv-installer/raw/main/bin/rbenv-doctor | bash
Checking for `rbenv' in PATH: /usr/local/bin/rbenv
Checking for rbenv shims in PATH: OK
Checking `rbenv install' support: /usr/local/bin/rbenv-install (ruby-build 20170523)
@@ -194,16 +183,6 @@ If you're on macOS, we recommend installing rbenv with
`rbenv install`.
-#### Upgrading with Homebrew
-
-To upgrade to the latest rbenv and update ruby-build with newly released
-Ruby versions, upgrade the Homebrew packages:
-
-~~~ sh
-$ brew upgrade rbenv ruby-build
-~~~
-
-
### Basic GitHub Checkout
For a more automated install, you can use
@@ -230,14 +209,16 @@ a systemwide install.
command-line utility.
* For **bash**:
- ~~~ bash
- $ echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bash_profile
- ~~~
- * For **Ubuntu Desktop**:
+ Ubuntu Desktop users should configure `~/.bashrc`:
~~~ bash
$ echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bashrc
~~~
+
+ On other platforms, bash is usually configured via `~/.bash_profile`:
+ ~~~ bash
+ $ echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bash_profile
+ ~~~
* For **Zsh**:
~~~ zsh
@@ -261,10 +242,10 @@ a systemwide install.
terminal tab will usually do it.)
5. Verify that rbenv is properly set up using this
- [rbenv-doctor](https://github.com/rbenv/rbenv-installer/blob/master/bin/rbenv-doctor) script:
+ [rbenv-doctor](https://github.com/rbenv/rbenv-installer/blob/main/bin/rbenv-doctor) script:
~~~ sh
- $ curl -fsSL https://github.com/rbenv/rbenv-installer/raw/master/bin/rbenv-doctor | bash
+ $ curl -fsSL https://github.com/rbenv/rbenv-installer/raw/main/bin/rbenv-doctor | bash
Checking for `rbenv' in PATH: /usr/local/bin/rbenv
Checking for rbenv shims in PATH: OK
Checking `rbenv install' support: /usr/local/bin/rbenv-install (ruby-build 20170523)
@@ -289,6 +270,15 @@ $ cd ~/.rbenv
$ git pull
~~~
+#### Updating the list of available Ruby versions
+
+If you're using the `rbenv install` command, then the list of available Ruby versions is not automatically updated when pulling from the rbenv repo. To do this manually:
+
+```sh
+$ cd ~/.rbenv/plugins/ruby-build
+$ git pull
+```
+
### How rbenv hooks into your shell
Skip this section unless you must know what every line in your shell
@@ -329,13 +319,18 @@ as part of GitHub checkout process outlined above or via Homebrew, you
should be able to:
~~~ sh
-# list all available versions:
+# list latest stable versions:
$ rbenv install -l
+# list all local versions:
+$ rbenv install -L
+
# install a Ruby version:
$ rbenv install 2.0.0-p247
~~~
+Set a Ruby version to finish installation and start using commands `rbenv global 2.0.0-p247` or `rbenv local 2.0.0-p247`
+
Alternatively to the `install` command, you can download and compile
Ruby manually as a subdirectory of `~/.rbenv/versions/`. An entry in
that directory can also be a symlink to a Ruby version installed
@@ -398,9 +393,17 @@ uninstall from the system.
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
+ perform the rbenv package removal.
+ - Homebrew:
+
+ `brew uninstall rbenv`
+ - Debian, Ubuntu and their derivatives:
+
+ `sudo apt purge rbenv`
+
+ - Archlinux and it's derivatives:
+
+ `sudo pacman -R rbenv`
## Command Reference
diff --git a/completions/rbenv.bash b/completions/rbenv.bash
index fe0784a..565d77c 100644
--- a/completions/rbenv.bash
+++ b/completions/rbenv.bash
@@ -6,8 +6,8 @@ _rbenv() {
COMPREPLY=( $(compgen -W "$(rbenv commands)" -- "$word") )
else
local words=("${COMP_WORDS[@]}")
- unset words[0]
- unset words[$COMP_CWORD]
+ unset "words[0]"
+ unset "words[$COMP_CWORD]"
local completions=$(rbenv completions "${words[@]}")
COMPREPLY=( $(compgen -W "$completions" -- "$word") )
fi
diff --git a/completions/rbenv.fish b/completions/rbenv.fish
deleted file mode 100644
index d347410..0000000
--- a/completions/rbenv.fish
+++ /dev/null
@@ -1,23 +0,0 @@
-function __fish_rbenv_needs_command
- set cmd (commandline -opc)
- if [ (count $cmd) -eq 1 -a $cmd[1] = 'rbenv' ]
- return 0
- end
- return 1
-end
-
-function __fish_rbenv_using_command
- set cmd (commandline -opc)
- if [ (count $cmd) -gt 1 ]
- if [ $argv[1] = $cmd[2] ]
- return 0
- end
- end
- return 1
-end
-
-complete -f -c rbenv -n '__fish_rbenv_needs_command' -a '(rbenv commands)'
-for cmd in (rbenv commands)
- complete -f -c rbenv -n "__fish_rbenv_using_command $cmd" -a \
- "(rbenv completions (commandline -opc)[2..-1])"
-end
diff --git a/debian/changelog b/debian/changelog
index c514941..bc23a93 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,3 +1,9 @@
+rbenv (1.2.0-1) UNRELEASED; urgency=low
+
+ * New upstream release.
+
+ -- Debian Janitor <janitor@jelmer.uk> Mon, 21 Nov 2022 19:40:06 -0000
+
rbenv (1.1.2-1) unstable; urgency=medium
* Team Upload
diff --git a/libexec/rbenv b/libexec/rbenv
index 4880df3..8a295e9 100755
--- a/libexec/rbenv
+++ b/libexec/rbenv
@@ -7,7 +7,8 @@ if [ "$1" = "--debug" ]; then
fi
if [ -n "$RBENV_DEBUG" ]; then
- export PS4='+ [${BASH_SOURCE##*/}:${LINENO}] '
+ # https://wiki-dev.bash-hackers.org/scripting/debuggingtips#making_xtrace_more_useful
+ export PS4='+(${BASH_SOURCE}:${LINENO}): ${FUNCNAME[0]:+${FUNCNAME[0]}(): }'
set -x
fi
@@ -28,7 +29,7 @@ if enable -f "${BASH_SOURCE%/*}"/../libexec/rbenv-realpath.dylib realpath 2>/dev
else
[ -z "$RBENV_NATIVE_EXT" ] || abort "failed to load \`realpath' builtin"
- READLINK=$(type -p greadlink readlink | head -1)
+ READLINK=$(type -p greadlink readlink 2>/dev/null | head -n1)
[ -n "$READLINK" ] || abort "cannot find readlink - are you missing GNU coreutils?"
resolve_link() {
@@ -67,6 +68,7 @@ else
fi
export RBENV_DIR
+[ -n "$RBENV_ORIG_PATH" ] || export RBENV_ORIG_PATH="$PATH"
shopt -s nullglob
diff --git a/libexec/rbenv---version b/libexec/rbenv---version
index 26f7313..5f14253 100755
--- a/libexec/rbenv---version
+++ b/libexec/rbenv---version
@@ -12,7 +12,7 @@
set -e
[ -n "$RBENV_DEBUG" ] && set -x
-version="1.1.2"
+version="1.2.0"
git_revision=""
if cd "${BASH_SOURCE%/*}" 2>/dev/null && git remote -v 2>/dev/null | grep -q rbenv; then
diff --git a/libexec/rbenv-help b/libexec/rbenv-help
index 0b7e926..fefbaab 100755
--- a/libexec/rbenv-help
+++ b/libexec/rbenv-help
@@ -42,8 +42,15 @@ extract_initial_comment_block() {
}
collect_documentation() {
+ local awk
+ awk="$(type -p gawk awk 2>/dev/null | head -n1)"
+ if [ -z "$awk" ]; then
+ echo "rbenv: cannot find awk" >&2
+ return 1
+ fi
+
# shellcheck disable=SC2016
- $(type -p gawk awk | head -1) '
+ "$awk" '
/^Summary:/ {
summary = substr($0, 10)
next
diff --git a/libexec/rbenv-hooks b/libexec/rbenv-hooks
index 010c705..2fa48e2 100755
--- a/libexec/rbenv-hooks
+++ b/libexec/rbenv-hooks
@@ -26,7 +26,7 @@ if ! enable -f "${BASH_SOURCE%/*}"/rbenv-realpath.dylib realpath 2>/dev/null; th
echo "rbenv: failed to load \`realpath' builtin" >&2
exit 1
fi
-READLINK=$(type -p greadlink readlink | head -1)
+READLINK=$(type -p greadlink readlink 2>/dev/null | head -n1)
if [ -z "$READLINK" ]; then
echo "rbenv: cannot find readlink - are you missing GNU coreutils?" >&2
exit 1
diff --git a/libexec/rbenv-init b/libexec/rbenv-init
index 855e9a5..ae2da55 100755
--- a/libexec/rbenv-init
+++ b/libexec/rbenv-init
@@ -38,6 +38,7 @@ if [ -z "$shell" ]; then
shell="${shell##-}"
shell="${shell:-$SHELL}"
shell="${shell##*/}"
+ shell="${shell%%-*}"
fi
root="${0%/*}/.."
@@ -70,10 +71,10 @@ if [ -z "$print" ]; then
echo
case "$shell" in
fish )
- echo 'status --is-interactive; and source (rbenv init -|psub)'
+ echo 'status --is-interactive; and rbenv init - fish | source'
;;
* )
- echo 'eval "$(rbenv init -)"'
+ printf 'eval "$(rbenv init - %s)"\n' "$shell"
;;
esac
echo
@@ -92,14 +93,14 @@ fish )
* )
echo 'export PATH="'${RBENV_ROOT}'/shims:${PATH}"'
echo "export RBENV_SHELL=$shell"
+
+ completion="${root}/completions/rbenv.${shell}"
+ if [ -r "$completion" ]; then
+ echo "source '$completion'"
+ fi
;;
esac
-completion="${root}/completions/rbenv.${shell}"
-if [ -r "$completion" ]; then
- echo "source '$completion'"
-fi
-
if [ -z "$no_rehash" ]; then
echo 'command rbenv rehash 2>/dev/null'
fi
@@ -114,7 +115,7 @@ function rbenv
switch "\$command"
case ${commands[*]}
- source (rbenv "sh-\$command" \$argv|psub)
+ rbenv "sh-\$command" \$argv|source
case '*'
command rbenv "\$command" \$argv
end
diff --git a/libexec/rbenv-rehash b/libexec/rbenv-rehash
index b84de7f..c5f8d55 100755
--- a/libexec/rbenv-rehash
+++ b/libexec/rbenv-rehash
@@ -34,6 +34,22 @@ remove_prototype_shim() {
rm -f "$PROTOTYPE_SHIM_PATH"
}
+# Locates rbenv as found in the user's PATH. Otherwise, returns an
+# absolute path to the rbenv executable itself.
+rbenv_path() {
+ local found
+ found="$(PATH="$RBENV_ORIG_PATH" command -v rbenv)"
+ if [[ $found == /* ]]; then
+ echo "$found"
+ elif [[ -n "$found" ]]; then
+ echo "$PWD/${found#./}"
+ else
+ # Assume rbenv isn't in PATH.
+ local here="${BASH_SOURCE%/*}"
+ echo "${here%/*}/bin/rbenv"
+ fi
+}
+
# The prototype shim file is a script that re-execs itself, passing
# its filename and any arguments to `rbenv exec`. This file is
# hard-linked for every executable and then removed. The linking
@@ -61,7 +77,7 @@ if [ "\$program" = "ruby" ]; then
fi
export RBENV_ROOT="$RBENV_ROOT"
-exec "$(command -v rbenv)" exec "\$program" "\$@"
+exec "$(rbenv_path)" exec "\$program" "\$@"
SH
chmod +x "$PROTOTYPE_SHIM_PATH"
}
@@ -97,21 +113,19 @@ make_shims() {
local file shim
for file; do
shim="${file##*/}"
- register_shim "$shim"
+ registered_shims+=("$shim")
done
}
-registered_shims=" "
-
# Registers the name of a shim to be generated.
register_shim() {
- registered_shims="${registered_shims}${1} "
+ registered_shims+=("$1")
}
# Install all the shims registered via `make_shims` or `register_shim` directly.
install_registered_shims() {
local shim file
- for shim in $registered_shims; do
+ for shim in "${registered_shims[@]}"; do
file="${SHIM_PATH}/${shim}"
[ -e "$file" ] || cp "$PROTOTYPE_SHIM_PATH" "$file"
done
@@ -123,8 +137,9 @@ install_registered_shims() {
# removed.
remove_stale_shims() {
local shim
+ local known_shims=" ${registered_shims[*]} "
for shim in "$SHIM_PATH"/*; do
- if [[ "$registered_shims" != *" ${shim##*/} "* ]]; then
+ if [[ "$known_shims" != *" ${shim##*/} "* ]]; then
rm -f "$shim"
fi
done
@@ -136,9 +151,8 @@ shopt -s nullglob
# executables.
create_prototype_shim
remove_outdated_shims
-# shellcheck disable=SC2046
-make_shims $(list_executable_names | sort -u)
-
+# shellcheck disable=SC2207
+registered_shims=( $(list_executable_names | sort -u) )
# Allow plugins to register shims.
OLDIFS="$IFS"
diff --git a/libexec/rbenv-sh-shell b/libexec/rbenv-sh-shell
index 8c71185..c44c74f 100755
--- a/libexec/rbenv-sh-shell
+++ b/libexec/rbenv-sh-shell
@@ -49,7 +49,7 @@ if [ "$version" = "--unset" ]; then
echo "set -e RBENV_VERSION"
;;
* )
- echo 'RBENV_VERSION_OLD="$RBENV_VERSION"'
+ echo 'RBENV_VERSION_OLD="${RBENV_VERSION-}"'
echo "unset RBENV_VERSION"
;;
esac
@@ -107,7 +107,7 @@ if rbenv-prefix "$version" >/dev/null; then
echo "set -gx RBENV_VERSION \"$version\""
;;
* )
- echo 'RBENV_VERSION_OLD="$RBENV_VERSION"'
+ echo 'RBENV_VERSION_OLD="${RBENV_VERSION-}"'
echo "export RBENV_VERSION=\"$version\""
;;
esac
diff --git a/libexec/rbenv-version b/libexec/rbenv-version
index d1fefcc..c95ab0d 100755
--- a/libexec/rbenv-version
+++ b/libexec/rbenv-version
@@ -8,4 +8,11 @@
set -e
[ -n "$RBENV_DEBUG" ] && set -x
-echo "$(rbenv-version-name) (set by $(rbenv-version-origin))"
+version_name="$(rbenv-version-name)"
+version_origin="$(rbenv-version-origin)"
+
+if [ "$version_origin" = "${RBENV_ROOT}/version" ] && [ ! -e "$version_origin" ]; then
+ echo "$version_name"
+else
+ echo "$version_name (set by $version_origin)"
+fi
diff --git a/libexec/rbenv-version-file-read b/libexec/rbenv-version-file-read
index 2f04696..c94404c 100755
--- a/libexec/rbenv-version-file-read
+++ b/libexec/rbenv-version-file-read
@@ -11,7 +11,9 @@ if [ -e "$VERSION_FILE" ]; then
words=( $(cut -b 1-1024 "$VERSION_FILE") )
version="${words[0]}"
- if [ -n "$version" ]; then
+ if [ "$version" = ".." ] || [[ $version == */* ]]; then
+ echo "rbenv: invalid version in \`$VERSION_FILE'" >&2
+ elif [ -n "$version" ]; then
echo "$version"
exit
fi
diff --git a/libexec/rbenv-versions b/libexec/rbenv-versions
index d1a110c..9b7d757 100755
--- a/libexec/rbenv-versions
+++ b/libexec/rbenv-versions
@@ -33,7 +33,7 @@ if ! enable -f "${BASH_SOURCE%/*}"/rbenv-realpath.dylib realpath 2>/dev/null; th
exit 1
fi
- READLINK=$(type -p greadlink readlink | head -1)
+ READLINK=$(type -p greadlink readlink 2>/dev/null | head -n1)
if [ -z "$READLINK" ]; then
echo "rbenv: cannot find readlink - are you missing GNU coreutils?" >&2
exit 1
@@ -63,47 +63,47 @@ if [ -d "$versions_dir" ]; then
versions_dir="$(realpath "$versions_dir")"
fi
+list_versions() {
+ shopt -s nullglob
+ 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
+ echo "${path##*/}"
+ fi
+ done
+ shopt -u nullglob
+}
+
if [ -n "$bare" ]; then
- hit_prefix=""
- miss_prefix=""
- current_version=""
- include_system=""
-else
- hit_prefix="* "
- miss_prefix=" "
- current_version="$(rbenv-version-name || true)"
- include_system="1"
+ list_versions
+ exit 0
fi
-num_versions=0
-
-print_version() {
- if [ "$1" == "$current_version" ]; then
- echo "${hit_prefix}$(rbenv-version 2>/dev/null)"
- else
- echo "${miss_prefix}$1"
- fi
- num_versions=$((num_versions + 1))
+sort_versions() {
+ sed 'h; s/[+-]/./g; s/.p\([[:digit:]]\)/.z.\1/; s/$/.z/; G; s/\n/ /' | \
+ LC_ALL=C sort -t. -k 1,1 -k 2,2n -k 3,3n -k 4,4n -k 5,5n | awk '{print $2}'
}
-# Include "system" in the non-bare output, if it exists
-if [ -n "$include_system" ] && RBENV_VERSION=system rbenv-which ruby >/dev/null 2>&1; then
- print_version system
-fi
-
-shopt -s nullglob
-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##*/}"
+versions="$(
+ if RBENV_VERSION=system rbenv-which ruby >/dev/null 2>&1; then
+ echo system
fi
-done
-shopt -u nullglob
+ list_versions | sort_versions
+)"
-if [ "$num_versions" -eq 0 ] && [ -n "$include_system" ]; then
+if [ -z "$versions" ]; then
echo "Warning: no Ruby detected on the system" >&2
exit 1
fi
+
+current_version="$(rbenv-version-name || true)"
+while read -r version; do
+ if [ "$version" == "$current_version" ]; then
+ echo "* $(rbenv-version 2>/dev/null)"
+ else
+ echo " $version"
+ fi
+done <<<"$versions"
diff --git a/test/exec.bats b/test/exec.bats
index 5413912..1ee7435 100644
--- a/test/exec.bats
+++ b/test/exec.bats
@@ -87,7 +87,7 @@ OUT
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
+ if head -n1 "\$found" | grep ruby >/dev/null; then
\$BASH "\$found"
else
echo "ruby: no Ruby script found in input (LoadError)" >&2
diff --git a/test/init.bats b/test/init.bats
index 6cf64e8..63fc8c6 100755
--- a/test/init.bats
+++ b/test/init.bats
@@ -39,21 +39,28 @@ eval "\$(rbenv-init -)"
echo \$RBENV_SHELL
OUT
chmod +x myscript.sh
- run ./myscript.sh /bin/zsh
+ run ./myscript.sh
assert_success "sh"
}
-@test "setup shell completions (fish)" {
+@test "skip shell completions (fish)" {
root="$(cd $BATS_TEST_DIRNAME/.. && pwd)"
run rbenv-init - fish
assert_success
- assert_line "source '${root}/test/../libexec/../completions/rbenv.fish'"
+ local line="$(grep '^source' <<<"$output")"
+ [ -z "$line" ] || flunk "did not expect line: $line"
+}
+
+@test "posix shell instructions" {
+ run rbenv-init bash
+ assert [ "$status" -eq 1 ]
+ assert_line 'eval "$(rbenv init - bash)"'
}
@test "fish instructions" {
run rbenv-init fish
assert [ "$status" -eq 1 ]
- assert_line 'status --is-interactive; and source (rbenv init -|psub)'
+ assert_line 'status --is-interactive; and rbenv init - fish | source'
}
@test "option to skip rehash" {
diff --git a/test/run b/test/run
index 9d3b9e5..7f0025c 100755
--- a/test/run
+++ b/test/run
@@ -6,4 +6,4 @@ if [ -n "$RBENV_NATIVE_EXT" ]; then
make -C src
fi
-exec bats ${CI:+--tap} test
+exec bats ${CI:+--tap} "${@:-test}"
diff --git a/test/shell.bats b/test/shell.bats
index bbb146e..38b0f42 100644
--- a/test/shell.bats
+++ b/test/shell.bats
@@ -47,7 +47,7 @@ load test_helper
RBENV_SHELL=bash run rbenv-sh-shell --unset
assert_success
assert_output <<OUT
-RBENV_VERSION_OLD="\$RBENV_VERSION"
+RBENV_VERSION_OLD="\${RBENV_VERSION-}"
unset RBENV_VERSION
OUT
}
@@ -75,7 +75,7 @@ SH
RBENV_SHELL=bash run rbenv-sh-shell 1.2.3
assert_success
assert_output <<OUT
-RBENV_VERSION_OLD="\$RBENV_VERSION"
+RBENV_VERSION_OLD="\${RBENV_VERSION-}"
export RBENV_VERSION="1.2.3"
OUT
}
diff --git a/test/test_helper.bash b/test/test_helper.bash
index aef883a..6e40d6c 100644
--- a/test/test_helper.bash
+++ b/test/test_helper.bash
@@ -119,7 +119,7 @@ path_without() {
if [ "$found" != "${RBENV_ROOT}/shims" ]; then
alt="${RBENV_TEST_DIR}/$(echo "${found#/}" | tr '/' '-')"
mkdir -p "$alt"
- for util in bash head cut readlink greadlink; do
+ for util in bash head cut readlink greadlink sed sort awk; do
if [ -x "${found}/$util" ]; then
ln -s "${found}/$util" "${alt}/$util"
fi
diff --git a/test/version-file-read.bats b/test/version-file-read.bats
index bf7bf91..9dc6232 100644
--- a/test/version-file-read.bats
+++ b/test/version-file-read.bats
@@ -70,3 +70,19 @@ IN
run rbenv-version-file-read my-version
assert_success "1.9.3"
}
+
+@test "prevents directory traversal" {
+ cat > my-version <<<".."
+ run rbenv-version-file-read my-version
+ assert_failure "rbenv: invalid version in \`my-version'"
+
+ cat > my-version <<<"../foo"
+ run rbenv-version-file-read my-version
+ assert_failure "rbenv: invalid version in \`my-version'"
+}
+
+@test "disallows path segments in version string" {
+ cat > my-version <<<"foo/bar"
+ run rbenv-version-file-read my-version
+ assert_failure "rbenv: invalid version in \`my-version'"
+}
diff --git a/test/version-name.bats b/test/version-name.bats
index c240757..6df1cfa 100644
--- a/test/version-name.bats
+++ b/test/version-name.bats
@@ -17,7 +17,7 @@ setup() {
assert_success "system"
}
-@test "system version is not checked for existance" {
+@test "system version is not checked for existence" {
RBENV_VERSION=system run rbenv-version-name
assert_success "system"
}
diff --git a/test/version.bats b/test/version.bats
index 886d0ef..f75af97 100644
--- a/test/version.bats
+++ b/test/version.bats
@@ -14,7 +14,7 @@ setup() {
@test "no version selected" {
assert [ ! -d "${RBENV_ROOT}/versions" ]
run rbenv-version
- assert_success "system (set by ${RBENV_ROOT}/version)"
+ assert_success "system"
}
@test "set by RBENV_VERSION" {
diff --git a/test/versions.bats b/test/versions.bats
index 3273b37..e083ffa 100644
--- a/test/versions.bats
+++ b/test/versions.bats
@@ -21,7 +21,7 @@ stub_system_ruby() {
stub_system_ruby
assert [ ! -d "${RBENV_ROOT}/versions" ]
run rbenv-versions
- assert_success "* system (set by ${RBENV_ROOT}/version)"
+ assert_success "* system"
}
@test "not even system ruby available" {
@@ -42,7 +42,7 @@ stub_system_ruby() {
run rbenv-versions
assert_success
assert_output <<OUT
-* system (set by ${RBENV_ROOT}/version)
+* system
1.9
OUT
}
@@ -56,15 +56,21 @@ OUT
@test "multiple versions" {
stub_system_ruby
create_version "1.8.7"
- create_version "1.9.3"
- create_version "2.0.0"
+ create_version "1.9.3-p13"
+ create_version "1.9.3-p2"
+ create_version "2.2.10"
+ create_version "2.2.3"
+ create_version "2.2.3-pre.2"
run rbenv-versions
assert_success
assert_output <<OUT
-* system (set by ${RBENV_ROOT}/version)
+* system
1.8.7
- 1.9.3
- 2.0.0
+ 1.9.3-p2
+ 1.9.3-p13
+ 2.2.3-pre.2
+ 2.2.3
+ 2.2.10
OUT
}