say_color info "$*"
}
+retval_ok()
+{
+ local rv="$1" expectation="$2"
+
+ if [[ "$expectation" == "success" ]]; then
+ (($rv == 0)) && return 0 || return 1
+ fi
+ if (($rv > 129 && $rv <= 192)); then
+ echo >&2 "died by signal"
+ return 1
+ fi
+ if (($rv == 127)); then
+ echo >&2 "command not found"
+ return 1
+ fi
+ if (($rv == 0)); then
+ echo >&2 "command was supposed to fail but succeeded"
+ return 1
+ fi
+ return 0
+}
+
_test_run()
{
- local f
+ local f expectation="$3" ret
let test_count++
eval >&3 2>&4 "$2"
- if (($? == 0)); then
+ ret=$?
+ if retval_ok "$ret" "$expectation"; then
let test_success++
say_color ok "ok $test_count - $1"
return
test_expect_success()
{
(($# != 2)) && error "bug: not 2 parameters to test_expect_success()"
- say >&3 "expecting success: $2"
- _test_run "$1" "$2"
+ echo >&3 "expecting success: $2"
+ _test_run "$1" "$2" "success"
+ echo >&3 ""
+}
+
+test_expect_failure()
+{
+ (($# != 2)) && error "bug: not 2 parameters to test_expect_failure()"
+ echo >&3 "expecting failure: $2"
+ _test_run "$1" "$2" "failure"
echo >&3 ""
}