codegen: Internally generated delegates don't require a typedef
[vala-gnome.git] / tests / testrunner.sh
blob7e0fef939335a03da9992914f8e059e46950ee29
1 #!/usr/bin/env 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
28 run_prefix=""
30 VALAC=$topbuilddir/compiler/valac$EXEEXT
31 VALAFLAGS="$VALAFLAGS \
32 --vapidir $vapidir \
33 --disable-warnings \
34 --main main \
35 --save-temps \
36 -X -g \
37 -X -O0 \
38 -X -pipe \
39 -X -lm \
40 -X -DGETTEXT_PACKAGE=\"valac\" \
41 -X -Werror=return-type \
42 -X -Werror=init-self \
43 -X -Werror=implicit \
44 -X -Werror=sequence-point \
45 -X -Werror=return-type \
46 -X -Werror=uninitialized \
47 -X -Werror=pointer-arith \
48 -X -Werror=int-to-pointer-cast \
49 -X -Werror=pointer-to-int-cast \
50 -X -Wformat \
51 -X -Werror=format-security \
52 -X -Werror=format-nonliteral \
53 -X -Werror=redundant-decls \
54 -X -Werror=int-conversion"
55 VAPIGEN=$topbuilddir/vapigen/vapigen$EXEEXT
56 VAPIGENFLAGS="--vapidir $vapidir"
58 # Incorporate the user's CFLAGS. Matters if the user decided to insert
59 # -m32 in CFLAGS, for example.
60 for cflag in ${CFLAGS} ${CPPFLAGS} ${LDFLAGS}; do
61 VALAFLAGS="${VALAFLAGS} -X ${cflag}"
62 done
64 function testheader() {
65 if [ "$1" = "Packages:" ]; then
66 shift
67 PACKAGES="$PACKAGES $@"
68 elif [ "$*" = "Invalid Code" ]; then
69 INVALIDCODE=1
70 INHEADER=0
71 testpath=${testfile/.test/}
72 ns=${testpath//\//.}
73 ns=${ns//-/_}
74 SOURCEFILE=$ns.vala
75 elif [ "$1" = "D-Bus" ]; then
76 run_prefix="dbus-run-session -- $run_prefix"
77 elif [ "$1" = "GIR" ]; then
78 GIRTEST=1
82 function sourceheader() {
83 if [ "$1" = "Program:" ]; then
84 testpath=${testfile/.test/}/$2
85 ns=${testpath//\//.}
86 ns=${ns//-/_}
87 SOURCEFILE=$ns.vala
88 SOURCEFILES="$SOURCEFILES $SOURCEFILE"
89 echo " case \"/$testpath\": $ns.main (); break;" >> main.vala
90 echo "namespace $ns {" > $SOURCEFILE
91 elif [ $GIRTEST -eq 1 ]; then
92 if [ "$1" = "Input:" ]; then
93 testpath=${testfile/.test/}
94 ns=${testpath//\//.}
95 ns=${ns//-/_}
96 SOURCEFILE=$ns.gir
97 cat <<EOF > $SOURCEFILE
98 <?xml version="1.0"?>
99 <repository version="1.2"
100 xmlns="http://www.gtk.org/introspection/core/1.0"
101 xmlns:c="http://www.gtk.org/introspection/c/1.0"
102 xmlns:glib="http://www.gtk.org/introspection/glib/1.0">
103 <include name="GLib" version="2.0"/>
104 <include name="GObject" version="2.0"/>
105 <c:include name="test.h"/>
106 <namespace name="Test"
107 version="1.2"
108 c:identifier-prefixes="Test"
109 c:symbol-prefixes="test">
111 elif [ "$1" = "Output:" ]; then
112 testpath=${testfile/.test/}
113 ns=${testpath//\//.}
114 ns=${ns//-/_}
115 SOURCEFILE=$ns.vapi.ref
120 function sourceend() {
121 if [ -n "$testpath" ]; then
122 if [ $INVALIDCODE -eq 1 ]; then
123 echo "! $VALAC $VALAFLAGS -C $SOURCEFILE" > check
124 elif [ $GIRTEST -eq 1 ]; then
125 if [ $PART -eq 1 ]; then
126 echo " </namespace>" >> $SOURCEFILE
127 echo "</repository>" >> $SOURCEFILE
129 echo "$VAPIGEN $VAPIGENFLAGS --library $ns $ns.gir && tail -n +5 $ns.vapi|sed '\$d'|diff -wu $ns.vapi.ref -" > check
130 else
131 echo "}" >> $SOURCEFILE
132 echo "./test$EXEEXT /$testpath" > check
137 testdir=_test
138 rm -rf $testdir
139 mkdir $testdir
140 cd $testdir
142 echo -n -e "TEST: Building...\033[72G"
144 cat << "EOF" > checkall
145 all=0
146 fail=0
149 cat << "EOF" > main.vala
150 void main (string[] args) {
151 switch (args[1]) {
154 PACKAGES=gio-2.0
155 SOURCEFILES=
156 for testfile in "$@"; do
157 rm -f prepare check
158 echo 'set -e' >> prepare
160 case "$testfile" in
161 *.vala)
162 testpath=${testfile/.vala/}
163 ns=${testpath//\//.}
164 ns=${ns//-/_}
165 SOURCEFILE=$ns.vala
166 SOURCEFILES="$SOURCEFILES $SOURCEFILE"
168 echo " case \"/$testpath\": $ns.main (); break;" >> main.vala
169 echo "namespace $ns {" > $SOURCEFILE
170 cat "$srcdir/$testfile" >> $SOURCEFILE
171 echo "}" >> $SOURCEFILE
173 echo "G_DEBUG=fatal-warnings ./test$EXEEXT /$testpath" > check
175 *.test)
176 PART=0
177 INHEADER=1
178 INVALIDCODE=0
179 GIRTEST=0
180 testpath=
181 while IFS="" read -r line; do
182 if [ $PART -eq 0 ]; then
183 if [ -n "$line" ]; then
184 testheader $line
185 else
186 PART=1
188 else
189 if [ $INHEADER -eq 1 ]; then
190 if [ -n "$line" ]; then
191 sourceheader $line
192 else
193 INHEADER=0
195 else
196 if echo "$line" | grep -q "^[A-Za-z]\+:"; then
197 sourceend
198 PART=$(($PART + 1))
199 INHEADER=1
200 testpath=
201 sourceheader $line
202 else
203 echo "$line" >> $SOURCEFILE
207 done < "$srcdir/$testfile"
208 sourceend
210 esac
212 cat prepare check > $ns.check
213 cat << EOF >> checkall
214 echo -n -e " /$testpath: \033[72G"
215 ((all++))
216 if $run_prefix bash $ns.check &>log; then
217 echo -e "\033[0;32mOK\033[m"
218 else
219 ((fail++))
220 echo -e "\033[0;31mFAIL\033[m"
221 cat log
224 done
226 cat << "EOF" >> checkall
227 if [ $fail -eq 0 ]; then
228 echo "All $all tests passed"
229 else
230 echo "$fail of $all tests failed"
231 exit 1
235 cat << "EOF" >> main.vala
236 default: assert_not_reached ();
241 cat $SOURCEFILES >> main.vala
243 if $VALAC $VALAFLAGS -o test$EXEEXT $([ -z "$PACKAGES" ] || echo $PACKAGES | xargs -n 1 echo -n " --pkg") main.vala &>log; then
244 echo -e "\033[0;32mOK\033[m"
245 else
246 echo -e "\033[0;31mFAIL\033[m"
247 cat log
249 cd $builddir
250 exit 1
253 if bash checkall; then
254 cd $builddir
255 rm -rf $testdir
256 else
257 cd $builddir
258 exit 1