Bats: path_without: support multiple args

This commit is contained in:
Ivan Pozdeev 2021-09-16 00:34:00 +03:00
parent 6185bb55e6
commit 876be1bb04
3 changed files with 19 additions and 17 deletions

View file

@ -46,6 +46,6 @@ OUT
} }
@test "prefix for invalid system" { @test "prefix for invalid system" {
PATH="$(path_without python)" run pyenv-prefix system PATH="$(path_without python python2 python3)" run pyenv-prefix system
assert_failure "pyenv: system version not found in PATH" assert_failure "pyenv: system version not found in PATH"
} }

View file

@ -111,24 +111,26 @@ assert() {
# Output a modified PATH that ensures that the given executable is not present, # Output a modified PATH that ensures that the given executable is not present,
# but in which system utils necessary for pyenv operation are still available. # but in which system utils necessary for pyenv operation are still available.
path_without() { path_without() {
local exe="$1"
local path=":${PATH}:" local path=":${PATH}:"
local found alt util for exe; do
for found in $(which -a "$exe"); do local found alt util
found="${found%/*}" for found in $(PATH="$path" which -a "$exe"); do
if [ "$found" != "${PYENV_ROOT}/shims" ]; then found="${found%/*}"
alt="${PYENV_TEST_DIR}/$(echo "${found#/}" | tr '/' '-')" if [ "$found" != "${PYENV_ROOT}/shims" ]; then
mkdir -p "$alt" alt="${PYENV_TEST_DIR}/$(echo "${found#/}" | tr '/' '-')"
for util in bash head cut readlink greadlink; do mkdir -p "$alt"
if [ -x "${found}/$util" ]; then for util in bash head cut readlink greadlink which; do
ln -s "${found}/$util" "${alt}/$util" if [ -x "${found}/$util" ]; then
fi ln -s "${found}/$util" "${alt}/$util"
done fi
path="${path/:${found}:/:${alt}:}" done
fi path="${path/:${found}:/:${alt}:}"
fi
done
done done
path="${path#:}" path="${path#:}"
echo "${path%:}" path="${path%:}"
echo "$path"
} }
create_hook() { create_hook() {

View file

@ -25,7 +25,7 @@ stub_system_python() {
} }
@test "not even system python available" { @test "not even system python available" {
PATH="$(path_without python)" run pyenv-versions PATH="$(path_without python python2 python3)" run pyenv-versions
assert_failure assert_failure
assert_output "Warning: no Python detected on the system" assert_output "Warning: no Python detected on the system"
} }