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 ""
}
-v=1|--verbose=1) o_verbose="1"; shift;;
-v|--verbose|-v=2|--verbose=2) o_verbose="2"; shift;;
--no-color) o_nocolor="true"; shift;;
+ --man-dir) export o_man_dir="$2"; shift; shift;;
--results-dir) o_results_dir="$2"; shift; shift;;
--trash-dir) o_trash_dir="$2"; shift; shift;;
--executables-dir) export o_executables_dir="$2"; shift; shift;;
[[ -z "$o_results_dir" ]] && o_results_dir="$test_dir/test-results"
[[ -z "$o_executables_dir" ]] && o_executables_dir="$test_dir/.."
[[ -z "$o_trash_dir" ]] && o_trash_dir="$test_dir/trashes"
+ [[ -z "$o_man_dir" ]] && o_man_dir="$test_dir/../build/man/man1"
# we want alsolute paths because relative paths become invalid
# after changing to the trash dir
[[ -n "${o_results_dir##/*}" ]] && o_results_dir="$wd/$o_results_dir"
[[ -n "${o_executables_dir##/*}" ]] && o_executables_dir="$wd/$o_results_dir"
+ [[ -n "${o_man_dir##/*}" ]] && o_man_dir="$wd/$o_man_dir"
[[ -n "${o_trash_dir##/*}" ]] && o_trash_dir="$wd/$o_trash_dir"
mkdir -p "$o_results_dir"