/
run_tests.sh.in
96 lines (96 loc) · 2.95 KB
/
run_tests.sh.in
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
#!/bin/bash
_XPG=1
result=0
errcnt=0
tstcnt=0;
if test "$1" == "--valgrind"; then
valgrind=`which valgrind`
shift
else
valgrind=
fi
diff -u $0 $0 >/dev/null 2>&1 && diff='diff -u' || diff='diff'
#diff="${diff} -I '#line [0-9]*'"
if uname|grep -q -i 'CYGWIN' && test -x "@WINBUILDDIR@/re2j.exe"; then
re2j='@WINBUILDDIR@/re2j.exe'
else
re2j='@builddir@/re2j'
fi
if test ! -x "${re2j}"; then
echo "Cannot find re2j executable (${re2j})."
fi
if test -n "${valgrind}"; then
valgrind="${valgrind} -q "
echo "Using valgrind"
fi
re2j="${valgrind}${re2j}"
echo "Testing: ${re2j}"
if ${re2j} -v|grep -q 're2j @PACKAGE_VERSION@ *\r*'; then
echo "Version: @PACKAGE_VERSION@"
else
echo "Warning: test build for @PACKAGE_VERSION@ but testing `${re2j} -v`"
fi
echo "Diffing: ${diff}"
if test $# = 0; then
tests=`for i in test lessons; do find @top_srcdir@/$i -name '*.re'; done|sort`
else
tests="$@"
fi;
for x in $tests; do
tstcnt=$(($tstcnt+1))
switches=`basename $x|sed -e 's/^[^.]*\.\(.*\)\.re$/-\1/g' -e 's/^[^-].*//g' -e 's/\([^ ]\)--/\1 --/g'`
genname=`echo $switches|sed -e 's,--.*$,,g' -e 's,^.[^o]*$,,g' -e 's,^[^ot]*t.*o.*$,,g' -e 's,^-[^o]*o\(.*\),@builddir@/test/\1,g'`
headers=`echo $switches|sed -e 's,--.*$,,g' -e 's,^.[^t]*$,,g' -e 's,^[^ot]*o.*t.*$,,g' -e 's,^-[^t]*t\(.*\),@builddir@/test/\1,g'`
switches=`echo $switches|sed -e 's,^-\([^ot-]*[ot]\)\(.*\)$,-\1@builddir@/test/\2,g'`
# don't use the -o flag, since it makes it harder to diff.
echo $x: $switches
outname=@builddir@/test/`basename ${x%.re}.c.temp`
outdiff=@builddir@/test/`basename ${x%.re}.c.diff`
typname=@builddir@/test/`basename ${x%.re}.h.temp`
typdiff=@builddir@/test/`basename ${x%.re}.h.diff`
$re2j $switches $x 2>&1 | sed -e "s,$x,`basename $x`,g" -e "s,/\* Generated by re2j .*\*/,/\* Generated by re2j \*/,g" > $outname
if test -n "$genname"; then
cat $genname | sed -e 's,@builddir@/test/,,g' -e "s,/\* Generated by re2j .*\*/,/\* Generated by re2j \*/,g" > $outname
rm $genname
fi
ok=1
if test -n "$headers"; then
cat $headers | sed -e 's,@builddir@/test/,,g' -e "s,/\* Generated by re2j .*\*/,/\* Generated by re2j \*/,g" > $typname
rm $headers
if test ! -f ${x%.re}.h; then
echo "Missing: ${x%.re}.h"
result=1
errcnt=$(($errcnt+1))
elif ${diff} ${x%.re}.h $typname > $typdiff; then
echo "Passed header test."
rm $typname
else
echo "Failed: ${x%.re}.h ${x%.re}.h.temp differ."
result=1
errcnt=$(($errcnt+1))
ok=0
fi
fi
if test ! -f ${x%.re}.c; then
echo "Missing: ${x%.re}.c"
result=1
errcnt=$(($errcnt+1))
elif ${diff} ${x%.re}.c $outname > $outdiff; then
if test $ok = 1; then
echo "Passed."
fi
rm $outname
else
echo "Failed: ${x%.re}.c ${x%.re}.c.temp differ."
result=1
errcnt=$(($errcnt+1))
fi
test -f $outdiff -a ! -s $outdiff && rm -f $outdiff
test -f $typdiff -a ! -s $typdiff && rm -f $typdiff
done
if test $result = 0; then
echo "All $tstcnt tests passed successfully."
else
echo "Error: $errcnt out $tstcnt tests failed."
fi
exit $result