From 248525742446d58f38c3ef9a5c3186fdc9d17cd9 Mon Sep 17 00:00:00 2001 From: "Yamashita, Yuu" Date: Mon, 1 Aug 2016 00:30:29 +0000 Subject: [PATCH 1/6] Add a test to confirm the prefix doesn't work fine with `/bin/ruby` --- test/prefix.bats | 9 +++++++++ test/test_helper.bash | 2 +- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/test/prefix.bats b/test/prefix.bats index 3fb94086..b78b8f94 100644 --- a/test/prefix.bats +++ b/test/prefix.bats @@ -24,6 +24,15 @@ load test_helper assert_success "$RBENV_TEST_DIR" } +@test "prefix for system in /" { + mkdir -p "${RBENV_TEST_DIR}/bin" + touch "${RBENV_TEST_DIR}/bin/rbenv-which" + echo "echo /bin/ruby" >"${RBENV_TEST_DIR}/bin/rbenv-which" + chmod +x "${RBENV_TEST_DIR}/bin/rbenv-which" + RBENV_VERSION="system" run rbenv-prefix + assert_success "/" +} + @test "prefix for invalid 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 aef883a4..a6cbb74e 100644 --- a/test/test_helper.bash +++ b/test/test_helper.bash @@ -20,10 +20,10 @@ if [ -z "$RBENV_TEST_DIR" ]; then export RBENV_HOOK_PATH="${RBENV_ROOT}/rbenv.d" 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" PATH="${RBENV_ROOT}/shims:$PATH" + PATH="${RBENV_TEST_DIR}/bin:$PATH" export PATH for xdg_var in `env 2>/dev/null | grep ^XDG_ | cut -d= -f1`; do unset "$xdg_var"; done From 6030ea51e4e4bdefa188529ed7bca8e45b1b078e Mon Sep 17 00:00:00 2001 From: "Yamashita, Yuu" Date: Mon, 1 Aug 2016 00:32:50 +0000 Subject: [PATCH 2/6] Add a workaround for system executables in `/bin` --- libexec/rbenv-prefix | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/libexec/rbenv-prefix b/libexec/rbenv-prefix index 5376cf5d..e65be834 100755 --- a/libexec/rbenv-prefix +++ b/libexec/rbenv-prefix @@ -24,7 +24,8 @@ fi if [ "$RBENV_VERSION" = "system" ]; then if RUBY_PATH="$(rbenv-which ruby 2>/dev/null)"; then RUBY_PATH="${RUBY_PATH%/*}" - echo "${RUBY_PATH%/bin}" + RBENV_PREFIX_PATH="${RUBY_PATH%/bin}" + echo "${RBENV_PREFIX_PATH:-/}" exit else echo "rbenv: system version not found in PATH" >&2 From a456528be82cc76e9a851b781426ad3fffe40b90 Mon Sep 17 00:00:00 2001 From: "Yamashita, Yuu" Date: Tue, 2 Aug 2016 00:21:28 +0000 Subject: [PATCH 3/6] Keep original ordering of PATH configuration --- test/prefix.bats | 9 +++++---- test/test_helper.bash | 2 +- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/test/prefix.bats b/test/prefix.bats index b78b8f94..0376954a 100644 --- a/test/prefix.bats +++ b/test/prefix.bats @@ -25,12 +25,13 @@ load test_helper } @test "prefix for system in /" { - mkdir -p "${RBENV_TEST_DIR}/bin" - touch "${RBENV_TEST_DIR}/bin/rbenv-which" - echo "echo /bin/ruby" >"${RBENV_TEST_DIR}/bin/rbenv-which" - chmod +x "${RBENV_TEST_DIR}/bin/rbenv-which" + mkdir -p "${BATS_TEST_DIRNAME}/libexec" + touch "${BATS_TEST_DIRNAME}/libexec/rbenv-which" + echo "echo /bin/ruby" >"${BATS_TEST_DIRNAME}/libexec/rbenv-which" + chmod +x "${BATS_TEST_DIRNAME}/libexec/rbenv-which" RBENV_VERSION="system" run rbenv-prefix assert_success "/" + rm -f "${BATS_TEST_DIRNAME}/libexec/rbenv-which" } @test "prefix for invalid system" { diff --git a/test/test_helper.bash b/test/test_helper.bash index a6cbb74e..aef883a4 100644 --- a/test/test_helper.bash +++ b/test/test_helper.bash @@ -20,10 +20,10 @@ if [ -z "$RBENV_TEST_DIR" ]; then export RBENV_HOOK_PATH="${RBENV_ROOT}/rbenv.d" 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" PATH="${RBENV_ROOT}/shims:$PATH" - PATH="${RBENV_TEST_DIR}/bin:$PATH" export PATH for xdg_var in `env 2>/dev/null | grep ^XDG_ | cut -d= -f1`; do unset "$xdg_var"; done From 8eefa41a4d4f00628423e87c11b24ef374fc3af0 Mon Sep 17 00:00:00 2001 From: "Yamashita, Yuu" Date: Wed, 3 Aug 2016 00:58:05 +0000 Subject: [PATCH 4/6] Remove useless `touch` line --- test/prefix.bats | 1 - 1 file changed, 1 deletion(-) diff --git a/test/prefix.bats b/test/prefix.bats index 0376954a..87ab9864 100644 --- a/test/prefix.bats +++ b/test/prefix.bats @@ -26,7 +26,6 @@ load test_helper @test "prefix for system in /" { mkdir -p "${BATS_TEST_DIRNAME}/libexec" - touch "${BATS_TEST_DIRNAME}/libexec/rbenv-which" echo "echo /bin/ruby" >"${BATS_TEST_DIRNAME}/libexec/rbenv-which" chmod +x "${BATS_TEST_DIRNAME}/libexec/rbenv-which" RBENV_VERSION="system" run rbenv-prefix From 83e874a165a9aae7a174308765ed64013e62d0d3 Mon Sep 17 00:00:00 2001 From: "Yamashita, Yuu" Date: Wed, 3 Aug 2016 01:33:35 +0000 Subject: [PATCH 5/6] Add explicit shebang to executable for testing --- test/prefix.bats | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/test/prefix.bats b/test/prefix.bats index 87ab9864..47541e2a 100644 --- a/test/prefix.bats +++ b/test/prefix.bats @@ -26,7 +26,9 @@ load test_helper @test "prefix for system in /" { mkdir -p "${BATS_TEST_DIRNAME}/libexec" - echo "echo /bin/ruby" >"${BATS_TEST_DIRNAME}/libexec/rbenv-which" + { echo "#!/bin/sh" + echo "echo /bin/ruby" + } >"${BATS_TEST_DIRNAME}/libexec/rbenv-which" chmod +x "${BATS_TEST_DIRNAME}/libexec/rbenv-which" RBENV_VERSION="system" run rbenv-prefix assert_success "/" From 36138f4901e201bfe5c7ac858bfcb3f0d3bf762a Mon Sep 17 00:00:00 2001 From: "Yamashita, Yuu" Date: Wed, 3 Aug 2016 06:29:59 +0000 Subject: [PATCH 6/6] Rewrite with using here document syntax --- test/prefix.bats | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/test/prefix.bats b/test/prefix.bats index 47541e2a..bdee6f06 100644 --- a/test/prefix.bats +++ b/test/prefix.bats @@ -26,9 +26,10 @@ load test_helper @test "prefix for system in /" { mkdir -p "${BATS_TEST_DIRNAME}/libexec" - { echo "#!/bin/sh" - echo "echo /bin/ruby" - } >"${BATS_TEST_DIRNAME}/libexec/rbenv-which" + cat >"${BATS_TEST_DIRNAME}/libexec/rbenv-which" <