diff options
author | ZyX <kp-pav@yandex.ru> | 2017-04-08 01:54:58 +0300 |
---|---|---|
committer | ZyX <kp-pav@yandex.ru> | 2017-04-08 01:54:58 +0300 |
commit | 043d8ff9f2389f8deab7934aa0ab4ce88a747f01 (patch) | |
tree | 4d6fa32d7c1ddaa99c15f80c1a4ba95d5f3ca2da /ci/common/suite.sh | |
parent | 5992cdf3c27ee9c73cea22e288c6ea6d54867394 (diff) | |
parent | 13352c00f1909d9296c5f276a3735f5e6f231b39 (diff) | |
download | rneovim-043d8ff9f2389f8deab7934aa0ab4ce88a747f01.tar.gz rneovim-043d8ff9f2389f8deab7934aa0ab4ce88a747f01.tar.bz2 rneovim-043d8ff9f2389f8deab7934aa0ab4ce88a747f01.zip |
Merge branch 'master' into luaviml'/lua
Diffstat (limited to 'ci/common/suite.sh')
-rw-r--r-- | ci/common/suite.sh | 121 |
1 files changed, 121 insertions, 0 deletions
diff --git a/ci/common/suite.sh b/ci/common/suite.sh new file mode 100644 index 0000000000..46207754fa --- /dev/null +++ b/ci/common/suite.sh @@ -0,0 +1,121 @@ +# HACK: get newline for use in strings given that "\n" and $'' do not work. +NL="$(printf '\nE')" +NL="${NL%E}" + +FAILED=0 + +FAIL_SUMMARY="" + +enter_suite() { + local suite_name="$1" + export NVIM_TEST_CURRENT_SUITE="${NVIM_TEST_CURRENT_SUITE}/$suite_name" +} + +exit_suite() { + if test $FAILED -ne 0 ; then + echo "Suite ${NVIM_TEST_CURRENT_SUITE} failed, summary:" + echo "${FAIL_SUMMARY}" + fi + export NVIM_TEST_CURRENT_SUITE="${NVIM_TEST_CURRENT_SUITE%/*}" + if test "x$1" != "x--continue" ; then + exit $FAILED + fi +} + +fail() { + local allow_failure= + if test "x$1" = "x--allow-failure" ; then + shift + allow_failure=A + fi + local test_name="$1" + local fail_char="$allow_failure$2" + local message="$3" + + : ${fail_char:=F} + : ${message:=Test $test_name failed} + + local full_msg="$fail_char $NVIM_TEST_CURRENT_SUITE|$test_name :: $message" + FAIL_SUMMARY="${FAIL_SUMMARY}${NL}${full_msg}" + echo "Failed: $full_msg" + if test "x$allow_failure" = "x" ; then + FAILED=1 + fi +} + +run_test() { + local cmd="$1" + test $# -gt 0 && shift + local test_name="$1" + : ${test_name:=$cmd} + test $# -gt 0 && shift + if ! eval "$cmd" ; then + fail "${test_name}" "$@" + fi +} + +run_test_wd() { + local timeout="$1" + test $# -gt 0 && shift + + local cmd="$1" + test $# -gt 0 && shift + + local restart_cmd="$1" + : ${restart_cmd:=true} + test $# -gt 0 && shift + + local test_name="$1" + : ${test_name:=$cmd} + test $# -gt 0 && shift + + local output_file="$(mktemp)" + local status_file="$(mktemp)" + + local restarts=5 + local prev_tmpsize=-1 + while test $restarts -gt 0 ; do + : > "${status_file}" + ( + FAILED=0 + if ! ( + set -o pipefail + eval "$cmd" 2>&1 | tee -a "$output_file" + ) ; then + fail "${test_name}" "$@" + fi + echo "$FAILED" > "$status_file" + ) & + local pid=$! + while test "$(stat -c "%s" "$status_file")" -eq 0 ; do + prev_tmpsize=$tmpsize + sleep $timeout + tmpsize="$(stat -c "%s" "$output_file")" + if test $tempsize -eq $prev_temsize ; then + # no output, assuming either hang or exit + break + fi + done + restarts=$[ restarts - 1 ] + if test "$(stat -c "%s" "$status_file")" -eq 0 ; then + # status file not updated, assuming hang + kill -KILL $pid + if test $restarts -eq 0 ; then + fail "${test_name}" E "Test hang up" + else + echo "Test ${test_name} hang up, restarting" + eval "$restart_cmd" + fi + else + local new_failed="$(cat "$status_file")" + if test "x$new_failed" != "x0" ; then + fail "${test_name}" F "Test failed in run_test_wd" + fi + return 0 + fi + done +} + +succeeded() { + return $FAILED +} |