Make cql test work if srcdir != .
[yaz-moved-to-github.git] / test / tstcql.sh
1 #!/bin/sh
2 srcdir=${srcdir:-.}
3 oIFS="$IFS"
4 IFS='
5 '
6 secno=0
7 testno=0
8 comment=0
9 ecode=0
10 test -f ${srcdir}/cqlsample || exit 1
11 test -d cql || mkdir cql
12 for f in `cat ${srcdir}/cqlsample`; do
13         if echo $f | grep '^#' >/dev/null; then
14                 comment=1
15         else
16                 if test "$comment" = "1"; then
17                         secno=`expr $secno + 1`
18                         testno=0
19                 fi
20                 comment=0
21                 testno=`expr $testno + 1`
22                 OUT1=${srcdir}/cql/$secno.$testno.out
23                 ERR1=${srcdir}/cql/$secno.$testno.err
24                 OUT2=cql/$secno.$testno.out.tmp
25                 ERR2=cql/$secno.$testno.err.tmp
26                 DIFF=cql/$secno.$testno.diff
27                 ../util/cql2xcql "$f" >$OUT2 2>$ERR2
28                 if test -f $OUT1 -a -f $ERR1; then
29                         if diff $OUT1 $OUT2 >$DIFF; then
30                                 rm $DIFF
31                         else
32                                 echo "diff out $secno $testno $f"
33                                 cat $DIFF
34                                 ecode=1 
35                         fi
36                         if diff $ERR1 $ERR2 >$DIFF; then
37                                 rm $DIFF
38                         else
39                                 echo "diff err $secno $testno $f"
40                                 cat $DIFF
41                                 ecode=1
42                         fi
43                 else
44                         echo "making test $secno $testno $f"
45                         mv $OUT2 $OUT1
46                         mv $ERR2 $ERR1
47                         ecode=1
48                 fi      
49         fi              
50 done
51 IFS="$oIFS"
52 exit $ecode