-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathrun-tests.sh
executable file
·59 lines (47 loc) · 1.14 KB
/
run-tests.sh
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
58
59
#!/bin/bash
die() {
echo "!! $1, aborting" >&2
exit 1
}
make-deterministic() {
prog="$1"
case "$prog" in
example)
sed -r 's/thread [AB] done/thread A or B done/'
;;
*) cat # no changes
;;
esac
}
run() {
prog="$1"
temp="$(tempfile)"
echo "$1"
echo " compiling..."
idris -p python --codegen python examples/"$1".idr -o examples/"$1".py \
|| die "could not compile $1"
expected=examples/"$1".expected.txt
echo " running..."
if [ "$update_expected" = 1 ]; then
{ python examples/"$1".py \
|| die "could not run $1"
} | make-deterministic "$1" \
> "$expected"
else
{ python examples/"$1".py \
|| die "could not run $1"
} | make-deterministic "$1" \
> "$temp"
diff "$temp" "$expected" \
|| die "unexpected output (see: vimdiff $temp $expected)"
rm "$temp"
fi
}
if [ "$1" = "update-expected" ]; then
update_expected=1
else
update_expected=0
fi
(cd examples; ls -1 *.idr) | while read fname; do
run "${fname%.idr}"
done