97 lines
1.8 KiB
Bash
97 lines
1.8 KiB
Bash
unset BASH_IT_THEME
|
|
unset GIT_HOSTING
|
|
unset NGINX_PATH
|
|
unset IRC_CLIENT
|
|
unset TODO
|
|
unset SCM_CHECK
|
|
|
|
BASH_IT_TEST_DIR="${BATS_TMPDIR}/.bash_it"
|
|
|
|
# guard against executing this block twice due to bats internals
|
|
if [ "$BASH_IT_ROOT" != "${BASH_IT_TEST_DIR}/root" ]; then
|
|
export BASH_IT_ROOT="${BASH_IT_TEST_DIR}/root"
|
|
export BASH_IT=$BASH_IT_TEST_DIR
|
|
fi
|
|
|
|
setup() {
|
|
mkdir -p -- "${BASH_IT_ROOT}"
|
|
}
|
|
|
|
teardown() {
|
|
rm -rf "${BASH_IT_TEST_DIR}"
|
|
}
|
|
|
|
assert() {
|
|
if ! "$@"; then
|
|
flunk "failed: $@"
|
|
fi
|
|
}
|
|
|
|
flunk() {
|
|
{ if [ "$#" -eq 0 ]; then cat -
|
|
else echo "$@"
|
|
fi
|
|
} | sed "s:${BASH_IT_TEST_DIR}:TEST_DIR:g" >&2
|
|
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
|
|
}
|
|
|
|
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
|
|
}
|