Brad Bishop | e42b3e3 | 2020-01-15 22:08:42 -0500 | [diff] [blame] | 1 | #!/bin/sh -eu |
| 2 | |
| 3 | my_cleanup() { |
| 4 | [ -n "${workdir:-}" ] && rm -rf "${workdir}" |
| 5 | } |
| 6 | |
| 7 | trap "my_cleanup" EXIT |
| 8 | for sig in INT TERM ; do |
| 9 | # We want sig to expand right here and now, as it's |
| 10 | # a loop variable, not when signalled. For $$ it |
| 11 | # doesn't matter. |
| 12 | # shellcheck disable=SC2064 |
| 13 | trap "my_cleanup ; trap - EXIT ; trap - ${sig} ; kill -s ${sig} $$" ${sig} |
| 14 | done |
| 15 | |
| 16 | workdir=$(mktemp -d -t onig.ptest.XXXXXX) |
| 17 | status="${workdir}/failed" |
| 18 | touch "${status}" |
| 19 | |
| 20 | find tests/ -perm -111 -type f -exec sh -c ' |
| 21 | workdir="${1}" |
| 22 | status="${2}" |
| 23 | t="${3}" |
| 24 | t_log="${workdir}/$(basename ${t}).log" |
| 25 | |
| 26 | res=0 |
| 27 | ./${t} > "${t_log}" 2>&1 \ |
| 28 | || res=$? |
| 29 | if [ $res -eq 0 ] ; then |
| 30 | echo "PASS: ${t}" |
| 31 | else |
| 32 | echo "FAIL: ${t}" |
| 33 | echo "$(basename ${t}): ${t_log}" >> "${status}" |
| 34 | fi |
| 35 | ' _ "${workdir}" "${status}" {} \; |
| 36 | |
| 37 | if [ $(stat -c '%s' "${status}") -ne 0 ] ; then |
| 38 | exec >&2 |
| 39 | while IFS=': ' read -r t t_log ; do |
| 40 | printf "\n=========================\n" |
| 41 | printf "ERROR: %s:\n" "${t}" |
| 42 | printf -- "-------------------------\n" |
| 43 | cat "${t_log}" |
| 44 | done < "${status}" |
| 45 | fi |
| 46 | |
| 47 | [ $(stat -c '%s' "${status}") -eq 0 ] |