1#!/bin/bash
2
3# Generates the tests in tests/test/cg/variants by
4# a) generating the test programs
5# b) compiling them with kylix and running them
6# c) changing them based on the Kylix compilation and running result, so
7#    they become self-checking
8# Only tested under Linux with Kylix installed, might also work under cygwin
9
10./genvartests
11BIGTEST=tnofalvarol.pp
12BIGTESTMAIN=tnofalvarol.inc
13rm ivarol*
14rm $BIGTEST
15rm $BIGTESTMAIN
16
17echo '{$ifdef fpc}' > $BIGTEST
18echo '{$mode delphi}' >> $BIGTEST
19echo '{$else fpc}' >> $BIGTEST
20echo '{$define FPC_HAS_TYPE_EXTENDED}' >> $BIGTEST
21echo '{$endif fpc}' >> $BIGTEST
22echo '{$define bigfile}' >> $BIGTEST
23echo >> $BIGTEST
24
25for file in tvarol*.pp
26do
27  dcc $file
28  if [ $? -ne 0 ]; then
29    echo '{ %fail }' > $file.new
30    cat $file >> $file.new
31    mv $file.new $file
32  else
33    ./`basename $file .pp` > output
34
35    if grep XXX output >/dev/null; then
36      sed -e "s/writeln('YYY')/halt(1)/" < $file > $file.new
37      grep -v "writeln('XXX')" < $file.new > $file
38      rm $file.new
39    fi
40
41    if grep YYY output >/dev/null; then
42      sed -e "s/writeln('XXX')/halt(1)/" < $file > $file.new
43      grep -v "writeln('YYY')" < $file.new > $file
44      rm $file.new
45    fi
46
47    if grep VVV output >/dev/null; then
48      sed -e "s/writeln('COMPFAILV')/raise tobject.create/" < $file > $file.new
49    else
50      sed -e "s/writeln('VVV')/halt(1)/" < $file > $file.new
51    fi
52    mv $file.new $file
53
54    if grep QQQ output >/dev/null; then
55      sed -e "s/writeln('COMPFAILQ')/raise tobject.create/" < $file > $file.new
56    else
57      sed -e "s/writeln('QQQ')/halt(1)/" < $file > $file.new
58    fi
59    mv $file.new $file
60
61    if ! grep "ifdef FPC_HAS_TYPE_EXTENDED" $file >/dev/null; then
62      namenr=`echo $file | sed -e 's/tvarol//' -e 's/\.pp//'`
63#      lines=`wc -l < $file`
64#      lines=$(($lines - 5))
65#      tail -$lines < $file >> $BIGTEST
66      echo "  dotest${namenr};" >> $BIGTESTMAIN
67      newname=`echo $file | sed -e 's/tvarol/ivarol/'`
68      mv $file $newname
69      echo '{$i' $newname '}' >> $BIGTEST
70    fi
71  fi
72done
73
74echo >> $BIGTEST
75echo Begin >> $BIGTEST
76cat $BIGTESTMAIN >> $BIGTEST
77echo End. >> $BIGTEST
78rm $BIGTESTMAIN
79