1#!/bin/sh -eu
2
3my_cleanup() {
4    [ -n "${workdir:-}" ] && rm -rf "${workdir}"
5}
6
7trap "my_cleanup" EXIT
8for 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}
14done
15
16workdir=$(mktemp -d -t onig.ptest.XXXXXX)
17status="${workdir}/failed"
18touch "${status}"
19
20find tests/ -perm -111 -type f ! -path "tests/.debug/*" -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
37if [ $(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}"
45fi
46
47[ $(stat -c '%s' "${status}") -eq 0 ]
48