2017-03-31 06:19:47 -07:00
|
|
|
# HACK: get newline for use in strings given that "\n" and $'' do not work.
|
|
|
|
NL="$(printf '\nE')"
|
|
|
|
NL="${NL%E}"
|
|
|
|
|
2017-03-31 06:02:53 -07:00
|
|
|
FAIL_SUMMARY=""
|
|
|
|
|
2017-04-04 10:15:30 -07:00
|
|
|
# Test success marker. If END_MARKER file exists, we know that all tests
|
|
|
|
# finished. If FAIL_SUMMARY_FILE exists we know that some tests failed, this
|
|
|
|
# file will contain information about failed tests. Build is considered
|
|
|
|
# successful if tests ended without any of them failing.
|
|
|
|
END_MARKER="$BUILD_DIR/.tests_finished"
|
|
|
|
FAIL_SUMMARY_FILE="$BUILD_DIR/.test_errors"
|
|
|
|
|
2017-04-30 20:45:24 -07:00
|
|
|
ANSI_CLEAR="\033[0K"
|
|
|
|
|
|
|
|
travis_fold() {
|
|
|
|
local action="$1"
|
|
|
|
local name="$2"
|
|
|
|
name="$(echo -n "$name" | tr '\n\0' '--' | sed 's/[^A-Za-z0-9]\+/-/g')"
|
|
|
|
name="$(echo -n "$name" | sed 's/-$//')"
|
|
|
|
echo -en "travis_fold:${action}:${name}\r${ANSI_CLEAR}"
|
|
|
|
}
|
|
|
|
|
|
|
|
if test "$TRAVIS" != "true" ; then
|
|
|
|
travis_fold() {
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
fi
|
|
|
|
|
2017-03-31 06:02:53 -07:00
|
|
|
enter_suite() {
|
2017-04-30 20:45:24 -07:00
|
|
|
set +x
|
2017-04-04 10:15:30 -07:00
|
|
|
FAILED=0
|
|
|
|
rm -f "${END_MARKER}"
|
2017-03-31 06:02:53 -07:00
|
|
|
local suite_name="$1"
|
|
|
|
export NVIM_TEST_CURRENT_SUITE="${NVIM_TEST_CURRENT_SUITE}/$suite_name"
|
2017-04-30 20:45:24 -07:00
|
|
|
travis_fold start "${NVIM_TEST_CURRENT_SUITE}"
|
|
|
|
set -x
|
2017-03-31 06:02:53 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
exit_suite() {
|
2017-04-30 20:45:24 -07:00
|
|
|
set +x
|
|
|
|
travis_fold end "${NVIM_TEST_CURRENT_SUITE}"
|
2017-03-31 06:02:53 -07:00
|
|
|
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%/*}"
|
2017-04-24 13:11:13 -07:00
|
|
|
if test "$1" != "--continue" ; then
|
2017-03-31 06:02:53 -07:00
|
|
|
exit $FAILED
|
2017-04-04 10:15:30 -07:00
|
|
|
else
|
|
|
|
local saved_failed=$FAILED
|
|
|
|
FAILED=0
|
|
|
|
return $saved_failed
|
2017-03-31 06:02:53 -07:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
fail() {
|
|
|
|
local test_name="$1"
|
2017-04-04 10:15:30 -07:00
|
|
|
local fail_char="$2"
|
2017-03-31 06:02:53 -07:00
|
|
|
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}"
|
2017-04-04 10:15:30 -07:00
|
|
|
echo "${full_msg}" >> "${FAIL_SUMMARY_FILE}"
|
2017-03-31 06:02:53 -07:00
|
|
|
echo "Failed: $full_msg"
|
2017-04-04 10:15:30 -07:00
|
|
|
FAILED=1
|
2017-03-31 06:02:53 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
run_test() {
|
|
|
|
local cmd="$1"
|
2017-03-31 10:52:05 -07:00
|
|
|
test $# -gt 0 && shift
|
2017-03-31 06:02:53 -07:00
|
|
|
local test_name="$1"
|
|
|
|
: ${test_name:=$cmd}
|
2017-03-31 10:52:05 -07:00
|
|
|
test $# -gt 0 && shift
|
2017-03-31 06:02:53 -07:00
|
|
|
if ! eval "$cmd" ; then
|
|
|
|
fail "${test_name}" "$@"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2017-03-31 09:42:18 -07:00
|
|
|
run_test_wd() {
|
2017-04-07 14:46:32 -07:00
|
|
|
local hang_ok=
|
2017-04-24 13:11:13 -07:00
|
|
|
if test "$1" = "--allow-hang" ; then
|
2017-04-07 14:46:32 -07:00
|
|
|
hang_ok=1
|
|
|
|
shift
|
|
|
|
fi
|
|
|
|
|
2017-03-31 09:42:18 -07:00
|
|
|
local timeout="$1"
|
2017-03-31 10:52:05 -07:00
|
|
|
test $# -gt 0 && shift
|
2017-04-03 17:58:10 -07:00
|
|
|
|
2017-03-31 09:42:18 -07:00
|
|
|
local cmd="$1"
|
2017-03-31 10:52:05 -07:00
|
|
|
test $# -gt 0 && shift
|
2017-04-03 17:58:10 -07:00
|
|
|
|
|
|
|
local restart_cmd="$1"
|
|
|
|
: ${restart_cmd:=true}
|
|
|
|
test $# -gt 0 && shift
|
|
|
|
|
2017-03-31 09:42:18 -07:00
|
|
|
local test_name="$1"
|
|
|
|
: ${test_name:=$cmd}
|
2017-03-31 10:52:05 -07:00
|
|
|
test $# -gt 0 && shift
|
2017-04-03 17:58:10 -07:00
|
|
|
|
2017-03-31 09:42:18 -07:00
|
|
|
local output_file="$(mktemp)"
|
|
|
|
local status_file="$(mktemp)"
|
2017-04-24 08:27:33 -07:00
|
|
|
local sid_file="$(mktemp)"
|
2017-04-03 17:58:10 -07:00
|
|
|
|
2017-03-31 09:42:18 -07:00
|
|
|
local restarts=5
|
|
|
|
local prev_tmpsize=-1
|
|
|
|
while test $restarts -gt 0 ; do
|
2017-04-24 08:34:47 -07:00
|
|
|
: > "$status_file"
|
|
|
|
: > "$sid_file"
|
2017-04-24 08:27:33 -07:00
|
|
|
setsid \
|
|
|
|
env \
|
|
|
|
output_file="$output_file" \
|
|
|
|
status_file="$status_file" \
|
|
|
|
sid_file="$sid_file" \
|
|
|
|
cmd="$cmd" \
|
2017-04-24 12:17:34 -07:00
|
|
|
CI_DIR="$CI_DIR" \
|
2017-04-24 08:27:33 -07:00
|
|
|
sh -c '
|
2017-04-24 12:17:34 -07:00
|
|
|
. "${CI_DIR}/common/test.sh"
|
2017-04-24 08:27:33 -07:00
|
|
|
ps -o sid= > "$sid_file"
|
2017-04-24 11:43:27 -07:00
|
|
|
(
|
|
|
|
ret=0
|
|
|
|
if ! eval "$cmd" 2>&1 ; then
|
|
|
|
ret=1
|
|
|
|
fi
|
|
|
|
echo "$ret" > "$status_file"
|
|
|
|
) | tee -a "$output_file"
|
2017-04-24 08:27:33 -07:00
|
|
|
'
|
2017-03-31 09:42:18 -07:00
|
|
|
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
|
2017-04-24 08:27:33 -07:00
|
|
|
restarts=$(( restarts - 1 ))
|
2017-03-31 09:42:18 -07:00
|
|
|
if test "$(stat -c "%s" "$status_file")" -eq 0 ; then
|
2017-04-24 08:34:47 -07:00
|
|
|
# Status file not updated, assuming hang
|
|
|
|
|
|
|
|
# SID not known, this should not ever happen
|
|
|
|
if test "$(stat -c "%s" "$sid_file")" -eq 0 ; then
|
|
|
|
fail "$test_name" E "Shell did not run"
|
|
|
|
break
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Kill all processes which belong to one session: should get rid of test
|
|
|
|
# processes as well as sh itself.
|
2017-04-24 08:27:33 -07:00
|
|
|
pkill -KILL -s$(cat "$sid_file")
|
2017-04-24 08:34:47 -07:00
|
|
|
|
2017-04-03 18:59:30 -07:00
|
|
|
if test $restarts -eq 0 ; then
|
2017-04-24 13:11:13 -07:00
|
|
|
if test -z "$hang_ok" ; then
|
2017-04-24 08:27:33 -07:00
|
|
|
fail "$test_name" E "Test hang up"
|
2017-04-07 14:46:32 -07:00
|
|
|
fi
|
2017-04-03 18:59:30 -07:00
|
|
|
else
|
|
|
|
echo "Test ${test_name} hang up, restarting"
|
|
|
|
eval "$restart_cmd"
|
|
|
|
fi
|
2017-03-31 09:42:18 -07:00
|
|
|
else
|
|
|
|
local new_failed="$(cat "$status_file")"
|
2017-04-24 13:11:13 -07:00
|
|
|
if test "$new_failed" != "0" ; then
|
2017-04-24 08:27:33 -07:00
|
|
|
fail "$test_name" F "Test failed in run_test_wd"
|
2017-03-31 09:42:18 -07:00
|
|
|
fi
|
2017-04-24 08:27:33 -07:00
|
|
|
break
|
2017-03-31 09:42:18 -07:00
|
|
|
fi
|
|
|
|
done
|
2017-04-24 08:27:33 -07:00
|
|
|
|
|
|
|
rm -f "$output_file"
|
|
|
|
rm -f "$status_file"
|
|
|
|
rm -f "$sid_file"
|
2017-03-31 09:42:18 -07:00
|
|
|
}
|
|
|
|
|
2017-04-04 10:15:30 -07:00
|
|
|
ended_successfully() {
|
2017-04-24 12:14:32 -07:00
|
|
|
if test -f "${FAIL_SUMMARY_FILE}" ; then
|
2017-04-04 10:15:30 -07:00
|
|
|
echo 'Test failed, complete summary:'
|
|
|
|
cat "${FAIL_SUMMARY_FILE}"
|
|
|
|
return 1
|
|
|
|
fi
|
2017-04-24 12:14:32 -07:00
|
|
|
if ! test -f "${END_MARKER}" ; then
|
2017-04-04 10:15:30 -07:00
|
|
|
echo 'ended_successfully called before end marker was touched'
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
|
|
|
end_tests() {
|
|
|
|
touch "${END_MARKER}"
|
|
|
|
ended_successfully
|
2017-03-31 06:02:53 -07:00
|
|
|
}
|