Tweak tests/runtests.sh to make it pass for older GHCs
[packages/stm.git] / tests / runtests.sh
1 #!/bin/bash
2
3 # Simple runner script used for TravisCI (where GHC's testsuite runner isn't available)
4
5 set -e
6
7 GHCVER=$(ghc --numeric-version)
8
9 echo "using GHC version: $GHCVER"
10
11 # checks if GHC version >= $1
12 ghc_minver () {
13 [ "$1" = "$(echo -e "$1\n${GHCVER}" | sort -V | head -n1)" ]
14 }
15
16 # hard-coded exceptions
17 may_fail () {
18 if [ "$1" = "stm064" ] && ! ghc_minver "7.6"; then
19 echo "EXPECTED FAIL: '$1' may fail for GHC < 7.6"
20 return 0
21 fi
22
23 return 1
24 }
25
26 die () {
27 echo "ERROR: $1" >&2
28 exit 1
29 }
30
31 [ -f tests/runtests.sh ] && cd tests/
32
33 [ -f runtests.sh ] || die "must be called from inside tests folder"
34
35 for T in *.hs;do
36 T=${T%.hs}
37
38 echo "== running test '$T'"
39
40 ghc --make -threaded -O2 --make ${T}.hs
41
42 if ./${T} > ${T}.stdout.run 2> ${T}.stderr.run
43 then
44 echo "${T} exited with code $?"
45 fi
46
47 for FD in stdout stderr; do
48 if [ -f "${T}.${FD}.ignore" ]; then
49 echo "ignoring ${FD} output"
50 continue
51 fi
52
53 # fixup typo in exception message for older GHCs
54 sed -i 's,Transacional invariant,Transactional invariant,g' "${T}.${FD}.run"
55
56 echo "validate ${FD} output..."
57 if [ -f "${T}.${FD}" ]; then REF="${T}.${FD}"; else REF=/dev/null; fi
58
59 diff -w -u "${REF}" "${T}.${FD}.run" || may_fail "${T}"
60 done
61
62 echo "> '${T}' PASSED"
63
64 rm ${T}.hi ${T}.o ${T} ${T}.stdout.run ${T}.stderr.run
65 done
66
67 echo "----------------------------------------------------------------------------"
68 echo "all tests PASSED!"