nitcc: introduce nitcc
[nit.git] / contrib / nitcc / t / t
1 #!/bin/bash
2
3 # This file is part of Nit ( http://nitlanguage.org ).
4 #
5 # See the NOTICE file distributed with this work for copyright information.
6 #
7 # Licensed under the Apache License, Version 2.0 (the "License");
8 # you may not use this file except in compliance with the License.
9 # You may obtain a copy of the License at
10 #
11 #     http://www.apache.org/licenses/LICENSE-2.0
12 #
13 # Unless required by applicable law or agreed to in writing, software
14 # distributed under the License is distributed on an "AS IS" BASIS,
15 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 # See the License for the specific language governing permissions and
17 # limitations under the License.
18
19 # This program is used to perform regression tests of nitcc.
20
21 NITCC=../nitcc
22 NITC=../../../bin/nitc
23
24 mkdir alt out 2>/dev/null
25
26 if test "x$#" = "x0"
27 then
28         echo usage: `basename $0` [-v] grammar-files*
29         exit
30 fi
31
32
33 verbose=false
34 stop=false
35 while [ $stop = false ]; do
36         case $1 in
37                 -v) verbose=true; shift;;
38                 *) stop=true
39         esac
40 done
41
42 # empty tap output
43 tap="tap.output"
44 >"$tap"
45 tapcount=0
46
47 differ() {
48         tapcount=$((tapcount + 1))
49         r="$1"
50         if test \! -f "sav/$r"
51         then
52                 if test -s "out/$r"
53                 then
54                         echo "[***no sav***] cp 'out/$r' sav/"
55                         test $verbose = true && { cat "out/$r" ; echo ; }
56                         echo >>"$tap" "not ok $tapcount - $name # TODO no sav"
57                 else
58                         echo "[0K]"
59                         echo >>"$tap" "ok $tapcount - $name"
60                 fi
61         elif diff "sav/$r" "out/$r" >/dev/null
62         then
63                 echo "[OK]"
64                 echo >>"$tap" "ok $tapcount - $name"
65         else
66                 echo "[******failed******] diff -u {sav,out}/$r"
67                 test $verbose = true && { diff -u "sav/$r" "out/$r" ; echo ; }
68                 echo >>"$tap" "not ok $tapcount - $name"
69         fi
70 }
71
72 for f in "$@"
73 do
74         for a in "$f" `./alterner.pl $f`
75         do
76                 cla=""
77                 langname=""
78                 echo -n "* $a: "
79                 bn=`basename "$a" .sablecc`
80                 res="$bn".res
81                 $NITCC "$a" >"out/$bn.nitcc.log" 2>&1
82                 if test $? != 0
83                 then
84                         echo -n "!nitcc "
85                 else
86                         t=`grep -o '[^ ]*_test_parser' < "out/$bn.nitcc.log"`
87                         if test -f "${t}.nit"
88                         then
89                                 echo -n ". "
90                                 $NITC -I .. "${t}.nit" >/dev/null 2>&1
91                                 if test $? != 0
92                                 then
93                                         echo -n "!nitc "
94                                 else
95                                         echo -n ". "
96                                         cla="${t}"
97                                         langname="${t/_test_parser}"
98                                 fi
99                         else
100                                 echo -n "!res "
101                                 echo
102                                 tapcount=$((tapcount + 1))
103                                 echo >>"$tap" "not ok $tapcount - $a # TODO no res"
104                                 continue
105                         fi
106                 fi
107
108                 grep -i "error" "out/$bn.nitcc.log" > "out/$res"
109                 name="$a"
110                 differ $res
111
112                 if test \! -z $cla
113                 then
114                         bf=`basename "$f" .sablecc`
115                         for i in "$bf".input*
116                         do
117                                 test -f $i || { echo "   - no input: $i" ; continue ; }
118                                 ni=${i#$bf}
119                                 resi="$bn$ni".res
120                                 rm "$langname.ast.out" 2>/dev/null
121                                 echo -n "  - $i: "
122                                 ./"$cla" "$i" > "out/$bn.$ni.log"
123                                 if test $? != 0
124                                 then
125                                         echo -n "!run "
126                                 else
127                                         echo -n ". "
128                                 fi
129
130                                 cp "$langname.ast.out" "out/$resi"
131                                 name="$a $i"
132                                 differ "$resi"
133                         done
134                 fi
135         done
136 done
137
138 echo >>"$tap" "1..$tapcount"
139 #prove --formatter=TAP::Formatter::JUnit /bin/cat :: tap.output > tap.xml