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.
This commit is contained in:
Mislav Marohnić 2014-01-02 22:30:21 +01:00
parent 3dc0005032
commit 1e1c9cb0dc
2 changed files with 23 additions and 10 deletions

View file

@ -25,15 +25,6 @@ load test_helper
} }
@test "prefix for invalid system" { @test "prefix for invalid system" {
USRBIN_ALT="${RBENV_TEST_DIR}/usr-bin-alt" PATH="$(path_without ruby)" run rbenv-prefix system
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
assert_failure "rbenv: system version not found in PATH" assert_failure "rbenv: system version not found in PATH"
} }

View file

@ -93,3 +93,25 @@ assert() {
flunk "failed: $@" flunk "failed: $@"
fi 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%:}"
}