From 3dc0005032f04d40001cf0542d2b3d154dc2dc11 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mislav=20Marohni=C4=87?= Date: Thu, 2 Jan 2014 22:17:38 +0100 Subject: [PATCH 1/4] Fix test suite running on OpenBSD The error was "bash: no such file or directory" and it was due to bash being located in `/usr/local/bin` on OpenBSD 5.4 instead of `/bin` like on other systems. Fixed by keeping `/usr/local/bin` in PATH during the test run. --- test/init.bats | 4 ++-- test/test_helper.bash | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/test/init.bats b/test/init.bats index 61b30be7..60a3328c 100644 --- a/test/init.bats +++ b/test/init.bats @@ -51,14 +51,14 @@ load test_helper } @test "adds shims to PATH" { - export PATH="${BATS_TEST_DIRNAME}/../libexec:/usr/bin:/bin" + export PATH="${BATS_TEST_DIRNAME}/../libexec:/usr/bin:/bin:/usr/local/bin" run rbenv-init - bash assert_success assert_line 0 'export PATH="'${RBENV_ROOT}'/shims:${PATH}"' } @test "adds shims to PATH (fish)" { - export PATH="${BATS_TEST_DIRNAME}/../libexec:/usr/bin:/bin" + export PATH="${BATS_TEST_DIRNAME}/../libexec:/usr/bin:/bin:/usr/local/bin" run rbenv-init - fish assert_success assert_line 0 "setenv PATH '${RBENV_ROOT}/shims' \$PATH" diff --git a/test/test_helper.bash b/test/test_helper.bash index 01d9fb99..43b04d3b 100644 --- a/test/test_helper.bash +++ b/test/test_helper.bash @@ -8,7 +8,7 @@ if [ "$RBENV_ROOT" != "${RBENV_TEST_DIR}/root" ]; then export RBENV_ROOT="${RBENV_TEST_DIR}/root" export HOME="${RBENV_TEST_DIR}/home" - PATH=/usr/bin:/bin:/usr/sbin:/sbin + PATH=/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin PATH="${RBENV_TEST_DIR}/bin:$PATH" PATH="${BATS_TEST_DIRNAME}/../libexec:$PATH" PATH="${BATS_TEST_DIRNAME}/libexec:$PATH" From 1e1c9cb0dcecf7a4c5126bcd3545967e07429173 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mislav=20Marohni=C4=87?= Date: Thu, 2 Jan 2014 22:30:21 +0100 Subject: [PATCH 2/4] Fix emulating the scenario where system Ruby is missing on OpenBSD On other systems, we expected to find system Ruby in `/usr/bin`, but in OpenBSD 5.4 it will be found in `/usr/local/bin`. This replaces the limited USRBIN_ALT hack with a more generic `path_without` function that will ensure that the given executable is not present in the resulting PATH even if it's found in multiple system paths. --- test/prefix.bats | 11 +---------- test/test_helper.bash | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+), 10 deletions(-) diff --git a/test/prefix.bats b/test/prefix.bats index 0d6cdba6..3fb94086 100644 --- a/test/prefix.bats +++ b/test/prefix.bats @@ -25,15 +25,6 @@ load test_helper } @test "prefix for invalid system" { - USRBIN_ALT="${RBENV_TEST_DIR}/usr-bin-alt" - mkdir -p "$USRBIN_ALT" - for util in head readlink greadlink; do - if [ -x "/usr/bin/$util" ]; then - ln -s "/usr/bin/$util" "${USRBIN_ALT}/$util" - fi - done - PATH_WITHOUT_RUBY="${PATH/\/usr\/bin:/$USRBIN_ALT:}" - - PATH="$PATH_WITHOUT_RUBY" run rbenv-prefix system + PATH="$(path_without ruby)" run rbenv-prefix system assert_failure "rbenv: system version not found in PATH" } diff --git a/test/test_helper.bash b/test/test_helper.bash index 43b04d3b..53ae8e64 100644 --- a/test/test_helper.bash +++ b/test/test_helper.bash @@ -93,3 +93,25 @@ assert() { flunk "failed: $@" fi } + +# Output a modified PATH that ensures that the given executable is not present, +# but in which system utils necessary for rbenv operation are still available. +path_without() { + local exe="$1" + local path="${PATH}:" + local found alt util + for found in $(which -a "$exe"); do + found="${found%/*}" + 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 + if [ -x "${found}/$util" ]; then + ln -s "${found}/$util" "${alt}/$util" + fi + done + path="${path/${found}:/${alt}:}" + fi + done + echo "${path%:}" +} From eda535a9423dfe39cd90197c1c4150bc1da392b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mislav=20Marohni=C4=87?= Date: Thu, 2 Jan 2014 22:33:54 +0100 Subject: [PATCH 3/4] Fix detecting completions support on OpenBSD The non-extended regex pattern didn't work on OpenBSD so this switches grep to extended pattern mode that seems to work consistenty on all systems. --- libexec/rbenv-completions | 2 +- test/completions.bats | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/libexec/rbenv-completions b/libexec/rbenv-completions index 6de09ed2..196212e4 100755 --- a/libexec/rbenv-completions +++ b/libexec/rbenv-completions @@ -11,7 +11,7 @@ if [ -z "$COMMAND" ]; then fi COMMAND_PATH="$(command -v "rbenv-$COMMAND" || command -v "rbenv-sh-$COMMAND")" -if grep -i "^\([#%]\|--\|//\) provide rbenv completions" "$COMMAND_PATH" >/dev/null; then +if grep -iE "^([#%]|--|//) provide rbenv completions" "$COMMAND_PATH" >/dev/null; then shift exec "$COMMAND_PATH" --complete "$@" fi diff --git a/test/completions.bats b/test/completions.bats index 0feccfa9..9091f082 100644 --- a/test/completions.bats +++ b/test/completions.bats @@ -18,7 +18,7 @@ create_command() { @test "command with completion support" { create_command "rbenv-hello" "#!$BASH -# provide rbenv completions +# Provide rbenv completions if [[ \$1 = --complete ]]; then echo hello else From 1a6bada94cad7605188daafca8106a975c193979 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mislav=20Marohni=C4=87?= Date: Thu, 2 Jan 2014 22:36:03 +0100 Subject: [PATCH 4/4] Fix detecting parent shell on OpenBSD and Cygwin It seems that "comm" header can't be relied on cross-platform, but that "ucomm" is more portable. I have no idea whether it's the right value to use here, but it seems to be doing the job. Also strip trailing whitespace because OpenBSD 5.4 `ps` output is padded with spaces for some reason. Fixes #489 --- libexec/rbenv-init | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/libexec/rbenv-init b/libexec/rbenv-init index a3292d66..a28b7fc4 100755 --- a/libexec/rbenv-init +++ b/libexec/rbenv-init @@ -22,8 +22,9 @@ done shell="$1" if [ -z "$shell" ]; then - shell="$(ps c -p $(ps -p $$ -o 'ppid=' 2>/dev/null) -o 'comm=' 2>/dev/null || true)" + shell="$(ps c -p "$PPID" -o 'ucomm=' 2>/dev/null || true)" shell="${shell##-}" + shell="${shell%% *}" shell="$(basename "${shell:-$SHELL}")" fi