2013-03-07 15:05:49 -05:00
|
|
|
RBENV_TEST_DIR="${BATS_TMPDIR}/rbenv"
|
|
|
|
export RBENV_ROOT="${RBENV_TEST_DIR}/root"
|
|
|
|
export HOME="${RBENV_TEST_DIR}/home"
|
|
|
|
|
|
|
|
unset RBENV_VERSION
|
|
|
|
unset RBENV_DIR
|
|
|
|
|
|
|
|
export PATH="${RBENV_TEST_DIR}/bin:$PATH"
|
|
|
|
export PATH="${BATS_TEST_DIRNAME}/../libexec:$PATH"
|
|
|
|
export PATH="${BATS_TEST_DIRNAME}/libexec:$PATH"
|
|
|
|
export PATH="${RBENV_ROOT}/shims:$PATH"
|
|
|
|
|
|
|
|
teardown() {
|
|
|
|
rm -rf "$RBENV_TEST_DIR"
|
|
|
|
}
|
|
|
|
|
|
|
|
flunk() {
|
2013-03-07 23:55:02 -05:00
|
|
|
{ if [ "$#" -eq 0 ]; then cat -
|
|
|
|
else echo "$@"
|
|
|
|
fi
|
|
|
|
} | sed "s:${RBENV_TEST_DIR}:TEST_DIR:" >&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
|
|
|
|
assert_output "$1"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
assert_failure() {
|
|
|
|
if [ "$status" -eq 0 ]; then
|
|
|
|
flunk "expected failed exit status"
|
|
|
|
elif [ "$#" -gt 0 ]; then
|
|
|
|
assert_output "$1"
|
|
|
|
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() {
|
|
|
|
assert_equal "$1" "$output"
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
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() {
|
|
|
|
for line in "${lines[@]}"; do
|
|
|
|
if [ "$line" = "$1" ]; then flunk "expected to not find line \`$line'"; fi
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
|
|
|
assert() {
|
|
|
|
if ! "$@"; then
|
|
|
|
flunk "failed: $@"
|
|
|
|
fi
|
|
|
|
}
|