]> git.tuebingen.mpg.de Git - paraslash.git/blobdiff - t/test-lib.sh
test suite: Add sanity check for generated man pages.
[paraslash.git] / t / test-lib.sh
index e444e5780d2f152eb9755916375996c9340016cd..f3768b65d573f755ea505bf282a1e106809621a2 100644 (file)
@@ -61,13 +61,36 @@ say()
        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
@@ -139,8 +162,16 @@ test_duration()
 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 ""
 }
 
@@ -204,6 +235,7 @@ parse_options()
                -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;;
@@ -234,11 +266,13 @@ fixup_dirs()
        [[ -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"