Improve integer tests
[vala-lang.git] / tests / testrunner.sh
blob00a624035080bab3a853d138c1c74811366063cb
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"
33 CC="gcc -std=c99"
34 CFLAGS="-O0 -g3 -I$topsrcdir -I$topbuilddir"
35 LDLIBS="-lm"
37 CODE=0
39 function testheader() {
40 if [ "$1" = "Packages:" ]; then
41 shift
42 PACKAGES="$@"
43 for pkg in $PACKAGES; do
44 if [ "$pkg" = "dbus-glib-1" ]; then
45 echo 'eval `dbus-launch --sh-syntax`' >> prepare
46 echo 'trap "kill $DBUS_SESSION_BUS_PID" INT TERM EXIT' >> prepare
48 done
52 function sourceheader() {
53 if [ "$1" = "Program:" ]; then
54 PROGRAM=$2
55 SOURCEFILE=$PROGRAM.vala
59 function sourceend() {
60 if [ -n "$PROGRAM" ]; then
61 echo "$VALAC $VALAFLAGS $(echo $PACKAGES | xargs -n 1 -r echo --pkg) -C $SOURCEFILE" >> build
62 echo "$CC $CFLAGS -o $PROGRAM$EXEEXT $PROGRAM.c \$(pkg-config --cflags --libs glib-2.0 gobject-2.0 $PACKAGES) $LDLIBS" >> build
63 echo "./$PROGRAM$EXEEXT" > check
67 for testfile in "$@"; do
68 testname=$(basename $testfile)
69 testdir=${testname/.test/.d}
70 rm -rf $testdir
71 mkdir $testdir
72 cd $testdir
74 touch prepare build check cleanup
76 echo 'set -e' >> prepare
78 PART=0
79 INHEADER=1
80 PACKAGES=
81 PROGRAM=
82 cat "$builddir/$testfile" | while true; do
83 if IFS="" read -r line; then
84 if [ $PART -eq 0 ]; then
85 if [ -n "$line" ]; then
86 testheader $line
87 else
88 PART=1
90 else
91 if [ $INHEADER -eq 1 ]; then
92 if [ -n "$line" ]; then
93 sourceheader $line
94 else
95 INHEADER=0
97 else
98 if echo "$line" | grep -q "^[A-Za-z]\+:"; then
99 sourceend
100 PART=$(($PART + 1))
101 INHEADER=1
102 PROGRAM=
103 sourceheader $line
104 else
105 echo "$line" >> $SOURCEFILE
109 else
110 sourceend
111 break
113 done
115 cat prepare build check cleanup > script
116 if ! bash script >log 2>&1; then
117 cat log
118 CODE=1
121 cd $builddir
123 if [ $CODE -eq 0 ]; then
124 rm -rf $testdir
126 done
128 exit $CODE