aboutsummaryrefslogtreecommitdiffstats
path: root/runtests.sh
blob: 390087180f1005eb352c5e80e2e05f0e25360714 (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
#!/bin/sh

if [ -z "$FORTH_CMD" ] ; then
    FORTH_CMD="./forth"
fi

dir='./tests'
if [ "$#" -gt 0 ] ; then
    dir="$1"
fi

n=0
failed=0

runtest () {
    file="$1"

    output="$(mktemp)"
    expectedoutput="$(mktemp)"
    sed '0,/^INPUT$/d;/^OUTPUT$/,$d' "$file" | "$FORTH_CMD" > "$output" &2> /dev/null
    sed '0,/^OUTPUT$/d' "$file" > "$expectedoutput"

    diff="$(diff -w -y "$output" "$expectedoutput")"

    if [ "1" -eq "$?" ] ; then
        echo "Test $n failed: $file" >&2
        echo "Diff: (actual vs expected)" >&2
        echo "$diff"
        exitcode=1
        failed="$(expr "$failed" + 1)"

    fi
}

for f in $dir/*.forth; do
    n="$(expr "$n" + 1)"
    runtest "$f"
done

for f in $dir/*/*.forth; do
    n="$(expr "$n" + 1)"
    runtest "$f"
done

if [ "0" -eq "$failed" ]; then
    echo "All $n tests passed" >&2
    exit 0
else
    echo "$failed/$n tests failed" >&2
    exit 1
fi