Merge: Contract implementation
[nit.git] / contrib / nitcc / tests / 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=../src/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                         return 1
58                 else
59                         echo "[0K]"
60                         echo >>"$tap" "ok $tapcount - $name"
61                         return 0
62                 fi
63         elif diff "sav/$r" "out/$r" >/dev/null
64         then
65                 echo "[OK]"
66                 echo >>"$tap" "ok $tapcount - $name"
67                 return 0
68         else
69                 echo "[******failed******] diff -u {sav,out}/$r"
70                 test $verbose = true && { diff -u "sav/$r" "out/$r" ; echo ; }
71                 echo >>"$tap" "not ok $tapcount - $name"
72                 return 1
73         fi
74 }
75
76 err=0
77 for f in "$@"
78 do
79         for a in "$f" `./alterner.pl $f`
80         do
81                 cla=""
82                 langname=""
83                 echo -n "* $a: "
84                 bn=`basename "$a" .sablecc`
85                 res="$bn".res
86                 $NITCC "$a" >"out/$bn.nitcc.log" 2>&1
87                 if test $? != 0
88                 then
89                         echo -n "!nitcc "
90                 else
91                         t=`grep -o '[^ ]*_test_parser' < "out/$bn.nitcc.log"`
92                         if test -f "${t}.nit"
93                         then
94                                 echo -n ". "
95                                 $NITC "${t}.nit" >/dev/null 2>&1
96                                 if test $? != 0
97                                 then
98                                         echo -n "!nitc "
99                                 else
100                                         echo -n ". "
101                                         cla="${t}"
102                                         langname="${t/_test_parser}"
103                                 fi
104                         else
105                                 echo -n "!res "
106                                 echo
107                                 tapcount=$((tapcount + 1))
108                                 echo >>"$tap" "not ok $tapcount - $a # TODO no res"
109                                 continue
110                         fi
111                 fi
112
113                 grep -i "error" "out/$bn.nitcc.log" > "out/$res"
114                 name="$a"
115                 differ $res || err=1
116
117                 if test \! -z $cla
118                 then
119                         bf=`basename "$f" .sablecc`
120                         for i in "$bf".input*
121                         do
122                                 test -f $i || { echo "   - no input: $i" ; continue ; }
123                                 ni=${i#$bf}
124                                 resi="$bn$ni".res
125                                 rm "$langname.ast.out" 2>/dev/null
126                                 echo -n "  - $i: "
127                                 ./"$cla" "$i" > "out/$bn.$ni.log"
128                                 if test $? != 0
129                                 then
130                                         echo -n "!run "
131                                 else
132                                         echo -n ". "
133                                 fi
134
135                                 cp "$langname.ast.out" "out/$resi"
136                                 name="$a $i"
137                                 differ "$resi" || err=1
138                         done
139                 fi
140         done
141 done
142
143 echo >>"$tap" "1..$tapcount"
144 #prove --formatter=TAP::Formatter::JUnit /bin/cat :: tap.output > tap.xml
145 exit "$err"