2014-01-02 11:48:22 -05:00
|
|
|
unset PYENV_VERSION
|
|
|
|
unset PYENV_DIR
|
|
|
|
|
2015-10-10 13:02:11 -04:00
|
|
|
# guard against executing this block twice due to bats internals
|
2015-11-20 23:13:52 -05:00
|
|
|
if [ -z "$PYENV_TEST_DIR" ]; then
|
2014-11-30 10:20:53 -05:00
|
|
|
PYENV_TEST_DIR="${BATS_TMPDIR}/pyenv"
|
2015-11-20 23:13:52 -05:00
|
|
|
export PYENV_TEST_DIR="$(mktemp -d "${PYENV_TEST_DIR}.XXX" 2>/dev/null || echo "$PYENV_TEST_DIR")"
|
2015-10-10 13:02:11 -04:00
|
|
|
|
2015-11-20 23:13:52 -05:00
|
|
|
if enable -f "${BATS_TEST_DIRNAME}"/../libexec/pyenv-realpath.dylib realpath 2>/dev/null; then
|
|
|
|
export PYENV_TEST_DIR="$(realpath "$PYENV_TEST_DIR")"
|
2015-10-10 13:02:11 -04:00
|
|
|
else
|
2015-11-20 23:13:52 -05:00
|
|
|
if [ -n "$PYENV_NATIVE_EXT" ]; then
|
|
|
|
echo "pyenv: failed to load \`realpath' builtin" >&2
|
2015-10-10 13:02:11 -04:00
|
|
|
exit 1
|
|
|
|
fi
|
2014-01-04 15:59:27 -05:00
|
|
|
fi
|
2014-01-02 11:48:22 -05:00
|
|
|
|
|
|
|
export PYENV_ROOT="${PYENV_TEST_DIR}/root"
|
|
|
|
export HOME="${PYENV_TEST_DIR}/home"
|
2016-03-01 20:39:52 -05:00
|
|
|
export PYENV_HOOK_PATH="${PYENV_ROOT}/pyenv.d"
|
2014-01-02 11:48:22 -05:00
|
|
|
|
2014-01-02 14:58:29 -05:00
|
|
|
PATH=/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin
|
2014-01-02 11:48:22 -05:00
|
|
|
PATH="${PYENV_TEST_DIR}/bin:$PATH"
|
|
|
|
PATH="${BATS_TEST_DIRNAME}/../libexec:$PATH"
|
|
|
|
PATH="${BATS_TEST_DIRNAME}/libexec:$PATH"
|
|
|
|
PATH="${PYENV_ROOT}/shims:$PATH"
|
|
|
|
export PATH
|
2015-10-10 12:30:44 -04:00
|
|
|
|
|
|
|
for xdg_var in `env 2>/dev/null | grep ^XDG_ | cut -d= -f1`; do unset "$xdg_var"; done
|
|
|
|
unset xdg_var
|
2014-01-02 11:48:22 -05:00
|
|
|
fi
|
|
|
|
|
|
|
|
teardown() {
|
|
|
|
rm -rf "$PYENV_TEST_DIR"
|
|
|
|
}
|
|
|
|
|
|
|
|
flunk() {
|
|
|
|
{ if [ "$#" -eq 0 ]; then cat -
|
|
|
|
else echo "$@"
|
|
|
|
fi
|
|
|
|
} | sed "s:${PYENV_TEST_DIR}:TEST_DIR:g" >&2
|
|
|
|
return 1
|
|
|
|
}
|
|
|
|
|
|
|
|
assert_success() {
|
|
|
|
if [ "$status" -ne 0 ]; then
|
2021-09-15 18:55:02 -04:00
|
|
|
flunk "command failed with exit status $status" $'\n'\
|
|
|
|
"output: $output"
|
2014-01-02 11:48:22 -05:00
|
|
|
elif [ "$#" -gt 0 ]; then
|
|
|
|
assert_output "$1"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
assert_failure() {
|
|
|
|
if [ "$status" -eq 0 ]; then
|
2021-09-15 18:55:02 -04:00
|
|
|
flunk "expected failed exit status" $'\n'\
|
|
|
|
"output: $output"
|
2014-01-02 11:48:22 -05:00
|
|
|
elif [ "$#" -gt 0 ]; then
|
|
|
|
assert_output "$1"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
assert_equal() {
|
|
|
|
if [ "$1" != "$2" ]; then
|
|
|
|
{ echo "expected: $1"
|
|
|
|
echo "actual: $2"
|
|
|
|
} | flunk
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
assert_output() {
|
|
|
|
local expected
|
|
|
|
if [ $# -eq 0 ]; then expected="$(cat -)"
|
|
|
|
else expected="$1"
|
|
|
|
fi
|
|
|
|
assert_equal "$expected" "$output"
|
|
|
|
}
|
|
|
|
|
|
|
|
assert_line() {
|
|
|
|
if [ "$1" -ge 0 ] 2>/dev/null; then
|
|
|
|
assert_equal "$2" "${lines[$1]}"
|
|
|
|
else
|
|
|
|
local line
|
|
|
|
for line in "${lines[@]}"; do
|
|
|
|
if [ "$line" = "$1" ]; then return 0; fi
|
|
|
|
done
|
|
|
|
flunk "expected line \`$1'"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
refute_line() {
|
|
|
|
if [ "$1" -ge 0 ] 2>/dev/null; then
|
|
|
|
local num_lines="${#lines[@]}"
|
|
|
|
if [ "$1" -lt "$num_lines" ]; then
|
|
|
|
flunk "output has $num_lines lines"
|
|
|
|
fi
|
|
|
|
else
|
|
|
|
local line
|
|
|
|
for line in "${lines[@]}"; do
|
|
|
|
if [ "$line" = "$1" ]; then
|
|
|
|
flunk "expected to not find line \`$line'"
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
assert() {
|
|
|
|
if ! "$@"; then
|
|
|
|
flunk "failed: $@"
|
|
|
|
fi
|
|
|
|
}
|
2014-01-02 14:58:29 -05:00
|
|
|
|
|
|
|
# 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.
|
|
|
|
path_without() {
|
2015-11-12 15:19:37 -05:00
|
|
|
local path=":${PATH}:"
|
2021-09-15 17:34:00 -04:00
|
|
|
for exe; do
|
|
|
|
local found alt util
|
2021-11-11 13:08:12 -05:00
|
|
|
for found in $(PATH="$path" type -aP "$exe"); do
|
2021-09-15 17:34:00 -04:00
|
|
|
found="${found%/*}"
|
|
|
|
if [ "$found" != "${PYENV_ROOT}/shims" ]; then
|
|
|
|
alt="${PYENV_TEST_DIR}/$(echo "${found#/}" | tr '/' '-')"
|
|
|
|
mkdir -p "$alt"
|
2021-11-11 13:08:12 -05:00
|
|
|
for util in bash head cut readlink greadlink; do
|
2021-09-15 17:34:00 -04:00
|
|
|
if [ -x "${found}/$util" ]; then
|
|
|
|
ln -s "${found}/$util" "${alt}/$util"
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
path="${path/:${found}:/:${alt}:}"
|
|
|
|
fi
|
|
|
|
done
|
2014-01-02 14:58:29 -05:00
|
|
|
done
|
2015-11-12 15:19:37 -05:00
|
|
|
path="${path#:}"
|
2021-09-15 17:34:00 -04:00
|
|
|
path="${path%:}"
|
|
|
|
echo "$path"
|
2014-01-02 14:58:29 -05:00
|
|
|
}
|
2015-12-29 10:53:01 -05:00
|
|
|
|
|
|
|
create_hook() {
|
2016-03-01 20:39:52 -05:00
|
|
|
mkdir -p "${PYENV_HOOK_PATH}/$1"
|
|
|
|
touch "${PYENV_HOOK_PATH}/$1/$2"
|
2015-12-29 10:53:01 -05:00
|
|
|
if [ ! -t 0 ]; then
|
2016-03-01 20:39:52 -05:00
|
|
|
cat > "${PYENV_HOOK_PATH}/$1/$2"
|
2015-12-29 10:53:01 -05:00
|
|
|
fi
|
|
|
|
}
|