summaryrefslogtreecommitdiffstats
path: root/debian/tests/run-testsuite
blob: 91082ee1b4a9f18552b111496785ef0473f49ee3 (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
48
49
50
51
52
53
54
55
56
57
#!/bin/sh

set -eu

export TZ=UTC

cd tests

failing=0

for i in *.testfile; do
    t=${i%%.testfile}
    printf "Running test: %s ... " "$t"

    m=
    for j in $(eval echo "${t}"*.magic); do
        if [ -f "$j" ]; then
            if [ -z "$m" ]; then
                m="$j"
            else
                m="$m:$j"
            fi
        fi
    done
    if [ "$m" ]; then
        export MAGIC="$m"
    else
        unset MAGIC
    fi

    if [ -f "${t}.flags" ]; then
        f="-$(cat "${t}.flags")"
    else
        f=
    fi

    expect="$(cat "${i%%.testfile}.result")"
    # shellcheck disable=SC2086
    got="$(file -b $f "$i" 2>/dev/null)"
    if [ "$got" = "$expect" ]; then
        echo 'pass'
    else
        cat <<__EOS__
FAIL:
    expect: $expect
    got:    $got
__EOS__
        failing=$((failing+1))
    fi
done

if [ "$failing" -gt 0 ]; then
    echo "Fail count: $failing"
    exit 1
fi

exit 0