blob: a3363310bf18621927d48e109b0496488de97492 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
|
#!/usr/bin/env bash
# testrunner.sh
#
# Copyright (C) 2006-2008 Jürg Billeter
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
#
# Author:
# Jürg Billeter <j@bitron.ch>
EXTRA_ENVIRONMENT_FILE=tests-extra-environment.sh
testfile=$1
testdirname="$(dirname $testfile)"
if test -f $testdirname/$EXTRA_ENVIRONMENT_FILE; then
source $testdirname/$EXTRA_ENVIRONMENT_FILE
fi
vapidir=$abs_top_srcdir/vapi
run_prefix=""
VALAC=$abs_top_builddir/compiler/valac$EXEEXT
VALAFLAGS="$VALAFLAGS \
--vapidir $vapidir \
--enable-checking \
--disable-warnings \
--save-temps \
--cc $CC \
-X -g \
-X -O0 \
-X -pipe \
-X -lm \
-X -DGETTEXT_PACKAGE=\\\"valac\\\""
VAPIGEN=$abs_top_builddir/vapigen/vapigen$EXEEXT
VAPIGENFLAGS="--vapidir $vapidir"
# Incorporate the TEST_CFLAGS.
for cflag in ${TEST_CFLAGS}; do
VALAFLAGS="${VALAFLAGS} -X ${cflag}"
done
# Incorporate the user's CFLAGS. Matters if the user decided to insert
# -m32 in CFLAGS, for example.
for cflag in ${CFLAGS} ${CPPFLAGS} ${LDFLAGS}; do
if [[ ! $cflag =~ ^\-O[0-9]$ ]]; then
VALAFLAGS="${VALAFLAGS} -X ${cflag}"
fi
done
function testheader() {
if [ "$1" = "Packages:" ]; then
shift
PACKAGES="$PACKAGES $@"
elif [ "$*" = "Invalid Code" ]; then
INVALIDCODE=1
INHEADER=0
testpath=${testfile/.test/}
ns=${testpath//\//_}
ns=${ns//-/_}\_invalid
SOURCEFILE=$ns.vala
elif [ "$1" = "D-Bus" ]; then
DBUSTEST=1
run_prefix="dbus-run-session -- $run_prefix"
elif [ "$1" = "GIR" ]; then
GIRTEST=1
fi
}
function sourceheader() {
if [ "$1" = "Program:" ]; then
if [ "$2" = "server" ]; then
ISSERVER=1
fi
testpath=${testfile/.test/}/$2
ns=${testpath//\//_}
ns=${ns//-/_}
SOURCEFILE=$ns.vala
SOURCEFILES="$SOURCEFILES $SOURCEFILE"
elif [ $GIRTEST -eq 1 ]; then
if [ "$1" = "Input:" ]; then
testpath=${testfile/.test/}
ns=${testpath//\//_}
ns=${ns//-/_}
SOURCEFILE=$ns.gir
cat <<EOF > $SOURCEFILE
<?xml version="1.0"?>
<repository version="1.2"
xmlns="http://www.gtk.org/introspection/core/1.0"
xmlns:c="http://www.gtk.org/introspection/c/1.0"
xmlns:glib="http://www.gtk.org/introspection/glib/1.0">
<include name="GLib" version="2.0"/>
<include name="GObject" version="2.0"/>
<c:include name="test.h"/>
<namespace name="Test"
version="1.2"
c:identifier-prefixes="Test"
c:symbol-prefixes="test">
EOF
elif [ "$1" = "Output:" ]; then
testpath=${testfile/.test/}
ns=${testpath//\//_}
ns=${ns//-/_}
SOURCEFILE=$ns.vapi.ref
fi
fi
}
function sourceend() {
if [ -n "$testpath" ]; then
if [ $INVALIDCODE -eq 1 ]; then
PACKAGEFLAGS=$([ -z "$PACKAGES" ] || echo $PACKAGES | xargs -n 1 echo -n " --pkg")
echo '' > prepare
echo "G_DEBUG=fatal-warnings $VALAC $VALAFLAGS $PACKAGEFLAGS -C $SOURCEFILE" > check
echo "RET=\$?" >> check
echo "if [ \$RET -ne 1 ]; then exit 1; fi" >> check
echo "exit 0" >> check
elif [ $GIRTEST -eq 1 ]; then
if [ $PART -eq 1 ]; then
echo " </namespace>" >> $SOURCEFILE
echo "</repository>" >> $SOURCEFILE
fi
echo "G_DEBUG=fatal-warnings $VAPIGEN $VAPIGENFLAGS --library $ns $ns.gir && tail -n +5 $ns.vapi|sed '\$d'|diff -wu $ns.vapi.ref -" > check
else
PACKAGEFLAGS=$([ -z "$PACKAGES" ] || echo $PACKAGES | xargs -n 1 echo -n " --pkg")
echo "G_DEBUG=fatal-warnings $VALAC $VALAFLAGS $PACKAGEFLAGS -o $ns$EXEEXT $SOURCEFILE" >> prepare
if [ $DBUSTEST -eq 1 ]; then
if [ $ISSERVER -eq 1 ]; then
echo "G_DEBUG=fatal-warnings ./$ns$EXEEXT" >> check
fi
else
echo "G_DEBUG=fatal-warnings ./$ns$EXEEXT" >> check
fi
fi
fi
}
testdir=_test.$$
rm -rf $testdir
mkdir $testdir
cd $testdir
echo -n -e "TEST: Preparing..."
cat << "EOF" > checkall
all=0
fail=0
EOF
PACKAGES=$([ -z "$PACKAGES" ] && echo "gio-2.0" || echo $PACKAGES)
testfile=${testfile#$srcdir/}
rm -f prepare check
echo 'set -e' >> prepare
run_prefix=""
case "$testfile" in
*.vala)
testpath=${testfile/.vala/}
ns=${testpath//\//_}
ns=${ns//-/_}
SOURCEFILE=$ns.vala
cat "$abs_srcdir/$testfile" >> $SOURCEFILE
PACKAGEFLAGS=$([ -z "$PACKAGES" ] || echo $PACKAGES | xargs -n 1 echo -n " --pkg")
echo "G_DEBUG=fatal-warnings $VALAC $VALAFLAGS $PACKAGEFLAGS -o $ns$EXEEXT $SOURCEFILE" >> prepare
echo "G_DEBUG=fatal-warnings ./$ns$EXEEXT" >> check
;;
*.gs)
testpath=${testfile/.gs/}
ns=${testpath//\//_}
ns=${ns//-/_}
SOURCEFILE=$ns.gs
cat "$abs_srcdir/$testfile" >> $SOURCEFILE
PACKAGEFLAGS=$([ -z "$PACKAGES" ] || echo $PACKAGES | xargs -n 1 echo -n " --pkg")
echo "G_DEBUG=fatal-warnings $VALAC $VALAFLAGS $PACKAGEFLAGS -o $ns$EXEEXT $SOURCEFILE" >> prepare
echo "G_DEBUG=fatal-warnings ./$ns$EXEEXT" >> check
;;
*.test)
PART=0
INHEADER=1
INVALIDCODE=0
GIRTEST=0
DBUSTEST=0
ISSERVER=0
testpath=
while IFS="" read -r line; do
if [ $PART -eq 0 ]; then
if [ -n "$line" ]; then
testheader $line
else
PART=1
fi
else
if [ $INHEADER -eq 1 ]; then
if [ -n "$line" ]; then
sourceheader $line
else
INHEADER=0
fi
else
if echo "$line" | grep -q "^[A-Za-z]\+:"; then
sourceend
PART=$(($PART + 1))
INHEADER=1
testpath=
sourceheader $line
else
echo "$line" >> $SOURCEFILE
fi
fi
fi
done < "$abs_srcdir/$testfile"
sourceend
;;
esac
cat prepare check > $ns.check
cat << EOF >> checkall
echo -n -e " $testpath: "
((all++))
if $run_prefix bash $ns.check &>log; then
echo -e "OK"
else
((fail++))
echo -e "FAIL"
cat log
fi
EOF
cat << "EOF" >> checkall
if [ $fail -eq 0 ]; then
echo "All $all tests passed"
else
echo "$fail of $all tests failed"
exit 1
fi
EOF
echo -e "DONE"
if bash checkall; then
cd $abs_builddir
rm -rf $testdir
else
cd $abs_builddir
exit 1
fi
|