if_parser
[mala.git] / tests / test.sh
blobbb361951fa0ab3d1209faeef9d25cfb2e5f8f751
1 #!/bin/sh
2 # Copyright (C) 2004, Christian Thaeter <chth@gmx.net>
4 # This file is part of the MaLa extension Language.
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License version 2 as
8 # published by the Free Software Foundation.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, contact me.
18 # TESTMODE=FULL yet unimplemented
19 # run all tests, PLANNED which fail count as error
21 # TESTMODE=FAST
22 # run only tests which recently failed
24 arg0="$0"
25 srcdir=$(dirname "$arg0")
27 ulimit -St 1
28 valgrind=""
29 if [ "$VALGRINDFLAGS" = 'DISABLE' ]; then
30 echo "valgrind explicit disabled"
31 else
32 if [ "$(which valgrind)" ]; then
33 valgrind="$(which valgrind) --tool=addrcheck --leak-check=yes -q $VALGRINDFLAGS"
34 ulimit -St 10
35 else
36 echo "no valgrind found, go without it"
40 echo
41 echo ================ $0 ================
43 TESTCNT=0
44 SKIPCNT=0
45 FAILCNT=0
47 if test -f ,testlog; then
48 mv ,testlog ,testlog.pre
49 else
50 touch ,testlog.pre
53 date >,testlog
55 function TEST()
57 name="$1"
58 shift
59 cat >,cmp
60 echo -n "" >,out
61 echo -n "TEST $name: "
62 echo -en "\nTEST $name: $* " >>,testlog
64 case $TESTMODE in
65 FAST)
66 if grep "^TEST $name: .* FAILED" ,testlog.pre >&/dev/null; then
67 MSGOK=" (fixed)"
68 MSGFAIL=" (still broken)"
69 elif grep "^TEST $name: .* \\(SKIPPED (ok)\\|OK\\)" ,testlog.pre >&/dev/null; then
70 echo ".. SKIPPED (ok)"
71 echo ".. SKIPPED (ok)" >>,testlog
72 SKIPCNT=$(($SKIPCNT + 1))
73 TESTCNT=$(($TESTCNT + 1))
74 return
75 else
76 MSGOK=" (new)"
77 MSGFAIL=" (new)"
81 MSGOK=""
82 MSGFAIL=""
84 esac
86 if $valgrind $TESTBIN "$@" 2>&1 | tee ,tmp | grep -v 'DEBUG:' | cmp ,cmp - &>/dev/null; then
87 echo ".. OK$MSGOK"
88 echo ".. OK$MSGOK" >>,testlog
89 else
90 echo ".. FAILED$MSGFAIL";
91 echo ".. FAILED$MSGFAIL" >>,testlog
92 grep -v 'DEBUG:' <,tmp >,out
93 diff -ua ,cmp ,out >>,testlog
94 # grep 'DEBUG:\|==.*==' <,tmp >>,testlog
95 cat ,tmp >>,testlog
96 echo END >>,testlog
97 FAILCNT=$(($FAILCNT + 1))
99 TESTCNT=$(($TESTCNT + 1))
102 function PLANNED()
104 echo -n "PLANNED $1: "
105 echo -en "\nPLANNED $* " >>,testlog
106 echo ".. SKIPPED (planned)"
107 echo ".. SKIPPED (planned)" >>,testlog
108 SKIPCNT=$(($SKIPCNT + 1))
109 TESTCNT=$(($TESTCNT + 1))
112 function RUNTESTS()
114 for i in $srcdir/*.tests; do
115 source $i
116 done
117 echo
118 rm ,cmp ,out ,tmp
119 if [ $FAILCNT = 0 ]; then
120 echo " ... PASSED $(($TESTCNT - $SKIPCNT)) TESTS, $SKIPCNT SKIPPED"
121 #rm ,testlog
122 else
123 echo " ... SUCCEDED $(($TESTCNT - $FAILCNT - $SKIPCNT)) TESTS"
124 echo " ... FAILED $FAILCNT TESTS"
125 echo " ... SKIPPED $SKIPCNT TESTS"
126 echo " see ',testlog' for details"
127 exit 1
131 function TESTING()
133 echo
134 echo "$1"
135 TESTBIN=$2
138 RUNTESTS
140 # arch-tag: f4d06a47-6e17-40de-bba8-17240ae3f435