Release 0.7.8
[vala-lang.git] / tests / testrunner.sh
blob5eb436b0b1046f9d3c62ebe1bd554bf6ba996ce8
1 #!/bin/bash
2 # testrunner.sh
4 # Copyright (C) 2006-2008 Jürg Billeter
6 # This library is free software; you can redistribute it and/or
7 # modify it under the terms of the GNU Lesser General Public
8 # License as published by the Free Software Foundation; either
9 # version 2.1 of the License, or (at your option) any later version.
11 # This library is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 # Lesser General Public License for more details.
16 # You should have received a copy of the GNU Lesser General Public
17 # License along with this library; if not, write to the Free Software
18 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 # Author:
21 # Jürg Billeter <j@bitron.ch>
23 builddir=$PWD
24 topbuilddir=$builddir/..
25 srcdir=$PWD/`dirname $0`
26 topsrcdir=$srcdir/..
27 vapidir=$topsrcdir/vapi
29 export G_DEBUG=fatal_warnings
31 VALAC=$topbuilddir/compiler/valac
32 VALAFLAGS="--vapidir $vapidir --disable-warnings --main main --save-temps -X -O0 -X -pipe -X -lm -X -Werror=return-type"
34 function testheader() {
35 if [ "$1" = "Packages:" ]; then
36 shift
37 PACKAGES="$PACKAGES $@"
38 for pkg in "$@"; do
39 if [ "$pkg" = "dbus-glib-1" ]; then
40 echo 'eval `dbus-launch --sh-syntax`' >> prepare
41 echo 'trap "kill $DBUS_SESSION_BUS_PID" INT TERM EXIT' >> prepare
43 done
47 function sourceheader() {
48 if [ "$1" = "Program:" ]; then
49 testpath=${testfile/.test/}/$2
50 ns=${testpath//\//.}
51 ns=${ns//-/_}
52 SOURCEFILE=$ns.vala
53 SOURCEFILES="$SOURCEFILES $SOURCEFILE"
54 echo " case \"/$testpath\": $ns.main (); break;" >> main.vala
55 echo "namespace $ns {" > $SOURCEFILE
59 function sourceend() {
60 if [ -n "$testpath" ]; then
61 echo "}" >> $SOURCEFILE
62 echo "./test$EXEEXT /$testpath" > check
66 testdir=_test
67 rm -rf $testdir
68 mkdir $testdir
69 cd $testdir
71 echo -n -e "TEST: Building...\033[72G"
73 cat << "EOF" > checkall
74 all=0
75 fail=0
76 EOF
78 cat << "EOF" > main.vala
79 void main (string[] args) {
80 switch (args[1]) {
81 EOF
83 PACKAGES=
84 SOURCEFILES=
85 for testfile in "$@"; do
86 rm -f prepare check
87 echo 'set -e' >> prepare
89 case "$testfile" in
90 *.vala)
91 testpath=${testfile/.vala/}
92 ns=${testpath//\//.}
93 ns=${ns//-/_}
94 SOURCEFILE=$ns.vala
95 SOURCEFILES="$SOURCEFILES $SOURCEFILE"
97 echo " case \"/$testpath\": $ns.main (); break;" >> main.vala
98 echo "namespace $ns {" > $SOURCEFILE
99 cat "$srcdir/$testfile" >> $SOURCEFILE
100 echo "}" >> $SOURCEFILE
102 echo "./test$EXEEXT /$testpath" > check
104 *.test)
105 PART=0
106 INHEADER=1
107 testpath=
108 while IFS="" read -r line; do
109 if [ $PART -eq 0 ]; then
110 if [ -n "$line" ]; then
111 testheader $line
112 else
113 PART=1
115 else
116 if [ $INHEADER -eq 1 ]; then
117 if [ -n "$line" ]; then
118 sourceheader $line
119 else
120 INHEADER=0
122 else
123 if echo "$line" | grep -q "^[A-Za-z]\+:"; then
124 sourceend
125 PART=$(($PART + 1))
126 INHEADER=1
127 testpath=
128 sourceheader $line
129 else
130 echo "$line" >> $SOURCEFILE
134 done < "$srcdir/$testfile"
135 sourceend
137 esac
139 cat prepare check > $ns.check
140 cat << EOF >> checkall
141 echo -n -e " /$testpath: \033[72G"
142 ((all++))
143 if bash $ns.check &>log; then
144 echo -e "\033[0;32mOK\033[m"
145 else
146 ((fail++))
147 echo -e "\033[0;31mFAIL\033[m"
148 cat log
151 done
153 cat << "EOF" >> checkall
154 if [ $fail -eq 0 ]; then
155 echo "All $all tests passed"
156 else
157 echo "$fail of $all tests failed"
158 exit 1
162 cat << "EOF" >> main.vala
163 default: assert_not_reached ();
168 cat $SOURCEFILES >> main.vala
170 if $VALAC $VALAFLAGS -o test$EXEEXT $(echo $PACKAGES | xargs -n 1 -r echo -n " --pkg") main.vala &>log; then
171 echo -e "\033[0;32mOK\033[m"
172 else
173 echo -e "\033[0;31mFAIL\033[m"
174 cat log
176 cd $builddir
177 exit 1
180 if bash checkall; then
181 cd $builddir
182 rm -rf $testdir
183 else
184 cd $builddir
185 exit 1