aboutsummaryrefslogtreecommitdiffstats
path: root/meta-oe/recipes-support/onig/onig/run-ptest
blob: fbce33699070f7cae9dfb2c1511f6fc678c77fed (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#!/bin/sh -eu

my_cleanup() {
    [ -n "${workdir:-}" ] && rm -rf "${workdir}"
}

trap "my_cleanup" EXIT
for sig in INT TERM ; do
    # We want sig to expand right here and now, as it's
    # a loop variable, not when signalled. For $$ it
    # doesn't matter.
    # shellcheck disable=SC2064
    trap "my_cleanup ; trap - EXIT ; trap - ${sig} ; kill -s ${sig} $$" ${sig}
done

workdir=$(mktemp -d -t onig.ptest.XXXXXX)
status="${workdir}/failed"
touch "${status}"

find tests/ -perm -111 -type f ! -path "tests/.debug/*" -exec sh -c '
    workdir="${1}"
    status="${2}"
    t="${3}"
    t_log="${workdir}/$(basename ${t}).log"

    res=0
    ./${t} > "${t_log}" 2>&1 \
        || res=$?
    if [ $res -eq 0 ] ; then
        echo "PASS: ${t}"
    else
        echo "FAIL: ${t}"
        echo "$(basename ${t}): ${t_log}" >> "${status}"
    fi
    ' _ "${workdir}" "${status}" {} \;

if [ $(stat -c '%s' "${status}") -ne 0 ] ; then
    exec >&2
    while IFS=': ' read -r t t_log ; do
        printf "\n=========================\n"
        printf "ERROR: %s:\n" "${t}"
        printf --  "-------------------------\n"
        cat "${t_log}"
    done < "${status}"
fi

[ $(stat -c '%s' "${status}") -eq 0 ]