glib-2.0: Add (u)long.parse/try_parse()
[vala-gnome.git] / tests / testrunner.sh
blob6025cac0c0bbabe4825b86cb0feede21422c4669
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 PACKAGEFLAGS=$([ -z "$PACKAGES" ] || echo $PACKAGES | xargs -n 1 echo -n " --pkg")
124 echo "! $VALAC $VALAFLAGS $PACKAGEFLAGS -C $SOURCEFILE" > check
125 elif [ $GIRTEST -eq 1 ]; then
126 if [ $PART -eq 1 ]; then
127 echo " </namespace>" >> $SOURCEFILE
128 echo "</repository>" >> $SOURCEFILE
130 echo "$VAPIGEN $VAPIGENFLAGS --library $ns $ns.gir && tail -n +5 $ns.vapi|sed '\$d'|diff -wu $ns.vapi.ref -" > check
131 else
132 echo "}" >> $SOURCEFILE
133 echo "./test$EXEEXT /$testpath" > check
138 testdir=_test
139 rm -rf $testdir
140 mkdir $testdir
141 cd $testdir
143 echo -n -e "TEST: Building...\033[72G"
145 cat << "EOF" > checkall
146 all=0
147 fail=0
150 cat << "EOF" > main.vala
151 void main (string[] args) {
152 switch (args[1]) {
155 PACKAGES=gio-2.0
156 SOURCEFILES=
157 for testfile in "$@"; do
158 rm -f prepare check
159 echo 'set -e' >> prepare
161 case "$testfile" in
162 *.vala)
163 testpath=${testfile/.vala/}
164 ns=${testpath//\//.}
165 ns=${ns//-/_}
166 SOURCEFILE=$ns.vala
167 SOURCEFILES="$SOURCEFILES $SOURCEFILE"
169 echo " case \"/$testpath\": $ns.main (); break;" >> main.vala
170 echo "namespace $ns {" > $SOURCEFILE
171 cat "$srcdir/$testfile" >> $SOURCEFILE
172 echo "}" >> $SOURCEFILE
174 echo "G_DEBUG=fatal-warnings ./test$EXEEXT /$testpath" > check
176 *.test)
177 PART=0
178 INHEADER=1
179 INVALIDCODE=0
180 GIRTEST=0
181 testpath=
182 while IFS="" read -r line; do
183 if [ $PART -eq 0 ]; then
184 if [ -n "$line" ]; then
185 testheader $line
186 else
187 PART=1
189 else
190 if [ $INHEADER -eq 1 ]; then
191 if [ -n "$line" ]; then
192 sourceheader $line
193 else
194 INHEADER=0
196 else
197 if echo "$line" | grep -q "^[A-Za-z]\+:"; then
198 sourceend
199 PART=$(($PART + 1))
200 INHEADER=1
201 testpath=
202 sourceheader $line
203 else
204 echo "$line" >> $SOURCEFILE
208 done < "$srcdir/$testfile"
209 sourceend
211 esac
213 cat prepare check > $ns.check
214 cat << EOF >> checkall
215 echo -n -e " /$testpath: \033[72G"
216 ((all++))
217 if $run_prefix bash $ns.check &>log; then
218 echo -e "\033[0;32mOK\033[m"
219 else
220 ((fail++))
221 echo -e "\033[0;31mFAIL\033[m"
222 cat log
225 done
227 cat << "EOF" >> checkall
228 if [ $fail -eq 0 ]; then
229 echo "All $all tests passed"
230 else
231 echo "$fail of $all tests failed"
232 exit 1
236 cat << "EOF" >> main.vala
237 default: assert_not_reached ();
242 cat $SOURCEFILES >> main.vala
244 if $VALAC $VALAFLAGS -o test$EXEEXT $([ -z "$PACKAGES" ] || echo $PACKAGES | xargs -n 1 echo -n " --pkg") main.vala &>log; then
245 echo -e "\033[0;32mOK\033[m"
246 else
247 echo -e "\033[0;31mFAIL\033[m"
248 cat log
250 cd $builddir
251 exit 1
254 if bash checkall; then
255 cd $builddir
256 rm -rf $testdir
257 else
258 cd $builddir
259 exit 1