2013-03-07 15:05:49 -05:00
|
|
|
unset RBENV_VERSION
|
|
|
|
unset RBENV_DIR
|
|
|
|
|
2015-10-10 13:02:11 -04:00
|
|
|
# guard against executing this block twice due to bats internals
|
|
|
|
if [ -z "$RBENV_TEST_DIR" ]; then
|
|
|
|
RBENV_TEST_DIR="${BATS_TMPDIR}/rbenv"
|
|
|
|
export RBENV_TEST_DIR="$(mktemp -d "${RBENV_TEST_DIR}.XXX" 2>/dev/null || echo "$RBENV_TEST_DIR")"
|
|
|
|
|
|
|
|
if enable -f "${BATS_TEST_DIRNAME}"/../libexec/rbenv-realpath.dylib realpath 2>/dev/null; then
|
|
|
|
export RBENV_TEST_DIR="$(realpath "$RBENV_TEST_DIR")"
|
|
|
|
else
|
|
|
|
if [ -n "$RBENV_NATIVE_EXT" ]; then
|
|
|
|
echo "rbenv: failed to load \`realpath' builtin" >&2
|
|
|
|
exit 1
|
|
|
|
fi
|
2014-01-04 15:59:27 -05:00
|
|
|
fi
|
2013-06-20 14:38:07 -04:00
|
|
|
|
|
|
|
export RBENV_ROOT="${RBENV_TEST_DIR}/root"
|
|
|
|
export HOME="${RBENV_TEST_DIR}/home"
|
2015-12-29 10:53:01 -05:00
|
|
|
export RBENV_HOOK_PATH="${RBENV_ROOT}/rbenv.d"
|
2013-06-20 14:38:07 -04:00
|
|
|
|
2014-01-02 16:17:38 -05:00
|
|
|
PATH=/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin
|
2013-06-20 14:38:07 -04:00
|
|
|
PATH="${BATS_TEST_DIRNAME}/../libexec:$PATH"
|
|
|
|
PATH="${BATS_TEST_DIRNAME}/libexec:$PATH"
|
|
|
|
PATH="${RBENV_ROOT}/shims:$PATH"
|
2016-07-31 20:30:29 -04:00
|
|
|
PATH="${RBENV_TEST_DIR}/bin:$PATH"
|
2013-06-20 14:38:07 -04:00
|
|
|
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
|
2013-06-20 14:38:07 -04:00
|
|
|
fi
|
2013-03-07 15:05:49 -05:00
|
|
|
|
|
|
|
teardown() {
|
|
|
|
rm -rf "$RBENV_TEST_DIR"
|
|
|
|
}
|
|
|
|
|
|
|
|
flunk() {
|
2013-03-07 23:55:02 -05:00
|
|
|
{ if [ "$#" -eq 0 ]; then cat -
|
|
|
|
else echo "$@"
|
|
|
|
fi
|
2013-06-20 14:38:07 -04:00
|
|
|
} | sed "s:${RBENV_TEST_DIR}:TEST_DIR:g" >&2
|
2013-03-07 15:05:49 -05:00
|
|
|
return 1
|
|
|
|
}
|
|
|
|
|
|
|
|
assert_success() {
|
|
|
|
if [ "$status" -ne 0 ]; then
|
|
|
|
flunk "command failed with exit status $status"
|
|
|
|
elif [ "$#" -gt 0 ]; then
|
2013-04-06 08:10:44 -04:00
|
|
|
assert_output "$1"
|
2013-03-07 15:05:49 -05:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
assert_failure() {
|
|
|
|
if [ "$status" -eq 0 ]; then
|
|
|
|
flunk "expected failed exit status"
|
|
|
|
elif [ "$#" -gt 0 ]; then
|
2013-04-06 08:10:44 -04:00
|
|
|
assert_output "$1"
|
2013-03-07 15:05:49 -05:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2013-03-07 23:55:02 -05:00
|
|
|
assert_equal() {
|
|
|
|
if [ "$1" != "$2" ]; then
|
|
|
|
{ echo "expected: $1"
|
|
|
|
echo "actual: $2"
|
|
|
|
} | flunk
|
2013-03-07 15:05:49 -05:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2013-03-07 23:55:02 -05:00
|
|
|
assert_output() {
|
2013-04-06 08:10:44 -04:00
|
|
|
local expected
|
|
|
|
if [ $# -eq 0 ]; then expected="$(cat -)"
|
|
|
|
else expected="$1"
|
|
|
|
fi
|
|
|
|
assert_equal "$expected" "$output"
|
2013-04-01 18:27:27 -04:00
|
|
|
}
|
|
|
|
|
2013-03-07 15:05:49 -05:00
|
|
|
assert_line() {
|
2013-03-07 23:55:02 -05:00
|
|
|
if [ "$1" -ge 0 ] 2>/dev/null; then
|
|
|
|
assert_equal "$2" "${lines[$1]}"
|
|
|
|
else
|
2013-04-01 18:27:27 -04:00
|
|
|
local line
|
2013-03-07 23:55:02 -05:00
|
|
|
for line in "${lines[@]}"; do
|
|
|
|
if [ "$line" = "$1" ]; then return 0; fi
|
|
|
|
done
|
|
|
|
flunk "expected line \`$1'"
|
|
|
|
fi
|
2013-03-07 15:05:49 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
refute_line() {
|
2013-03-31 20:58:58 -04:00
|
|
|
if [ "$1" -ge 0 ] 2>/dev/null; then
|
2013-04-01 18:27:27 -04:00
|
|
|
local num_lines="${#lines[@]}"
|
2013-03-31 20:58:58 -04:00
|
|
|
if [ "$1" -lt "$num_lines" ]; then
|
|
|
|
flunk "output has $num_lines lines"
|
|
|
|
fi
|
|
|
|
else
|
2013-04-01 18:27:27 -04:00
|
|
|
local line
|
2013-03-31 20:58:58 -04:00
|
|
|
for line in "${lines[@]}"; do
|
|
|
|
if [ "$line" = "$1" ]; then
|
|
|
|
flunk "expected to not find line \`$line'"
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
fi
|
2013-03-07 15:05:49 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
assert() {
|
|
|
|
if ! "$@"; then
|
|
|
|
flunk "failed: $@"
|
|
|
|
fi
|
|
|
|
}
|
2014-01-02 16:30:21 -05:00
|
|
|
|
|
|
|
# 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"
|
2015-11-12 15:19:37 -05:00
|
|
|
local path=":${PATH}:"
|
2014-01-02 16:30:21 -05:00
|
|
|
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
|
2015-11-12 15:19:37 -05:00
|
|
|
path="${path/:${found}:/:${alt}:}"
|
2014-01-02 16:30:21 -05:00
|
|
|
fi
|
|
|
|
done
|
2015-11-12 15:19:37 -05:00
|
|
|
path="${path#:}"
|
2014-01-02 16:30:21 -05:00
|
|
|
echo "${path%:}"
|
|
|
|
}
|
2015-12-29 10:53:01 -05:00
|
|
|
|
|
|
|
create_hook() {
|
|
|
|
mkdir -p "${RBENV_HOOK_PATH}/$1"
|
|
|
|
touch "${RBENV_HOOK_PATH}/$1/$2"
|
|
|
|
if [ ! -t 0 ]; then
|
|
|
|
cat > "${RBENV_HOOK_PATH}/$1/$2"
|
|
|
|
fi
|
|
|
|
}
|