25c058a2a2
This prevents some odd interactions with the EXIT trap, and our last command's status is seemingly not preserved for the script's real exit. Add a BASH override to the Makefile as well, as it might be useful for debugging or testing against other versions of bash.
46 lines
694 B
Bash
46 lines
694 B
Bash
#!/bin/bash
|
|
|
|
fail=0
|
|
testcount=0
|
|
|
|
EXPECT_success() {
|
|
(( ++testcount ))
|
|
if ! "$@"; then
|
|
(( ++fail ))
|
|
printf 'expectation failed: did not succeed: %s\n' "$*" >&2
|
|
fi
|
|
}
|
|
|
|
EXPECT_failure() {
|
|
(( ++testcount ))
|
|
if "$@"; then
|
|
(( ++fail ))
|
|
printf 'expectation failed: did not fail: %s\n' "$*" >&2
|
|
fi
|
|
}
|
|
|
|
TEST_exit() {
|
|
local result
|
|
|
|
trap -- EXIT
|
|
|
|
(( fail == 0 )) && result=PASS || result=FAIL
|
|
|
|
printf '%s: %s\n' "$result" "$1"
|
|
|
|
exit $(( fail != 0 ))
|
|
}
|
|
|
|
ASSERT_streq() {
|
|
if [[ $1 != "$2" ]]; then
|
|
printf 'assertion failed [line %d]: [[ %s = "%s" ]]\n' "$BASH_LINENO" "$1" "$2" >&2
|
|
fi
|
|
}
|
|
|
|
TEST_start() {
|
|
trap "TEST_exit '$1'" EXIT
|
|
}
|
|
|
|
TEST_start "${0##*/test_}"
|
|
|