2 # This file is part of NIT ( http://www.nitlanguage.org ).
4 # Copyright 2004-2008 Jean Privat <jean@pryen.org>
6 # Licensed under the Apache License, Version 2.0 (the "License");
7 # you may not use this file except in compliance with the License.
8 # You may obtain a copy of the License at
10 # http://www.apache.org/licenses/LICENSE-2.0
12 # Unless required by applicable law or agreed to in writing, software
13 # distributed under the License is distributed on an "AS IS" BASIS,
14 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 # See the License for the specific language governing permissions and
16 # limitations under the License.
18 # This shell script compile, run and verify Nit program files
20 # Set lang do default to avoid failed tests because of locale
27 Usage
: $e [options
] modulenames
28 -o option Pass option to nitc
29 -v Verbose
(show tests steps
)
31 --tap Produce TAP output
35 # As argument: the pattern used for the file
36 function process_result
()
38 ((tapcount
=tapcount
+1))
46 if [ -r
"sav/$pattern.sav" ]; then
47 diff -u
"out/$pattern.res" "sav/$pattern.sav" > "out/$pattern.diff.sav.log"
48 if [ "$?" == 0 ]; then
53 sed '/[Ww]arning/d;/[Ee]rror/d' "out/$pattern.res" > "out/$pattern.res2"
54 sed '/[Ww]arning/d;/[Ee]rror/d' "sav/$pattern.sav" > "out/$pattern.sav2"
55 grep '[Ee]rror' "out/$pattern.res" >/dev
/null
&& echo "Error" >> "out/$pattern.res2"
56 grep '[Ee]rror' "sav/$pattern.sav" >/dev
/null
&& echo "Error" >> "out/$pattern.sav2"
57 diff -u
"out/$pattern.res2" "out/$pattern.sav2" > "out/$pattern.diff.sav2.log"
58 if [ "$?" == 0 ]; then
64 if [ -r
"sav/$pattern.fail" ]; then
65 diff -u
"out/$pattern.res" "sav/$pattern.fail" > "out/$pattern.diff.fail.log"
66 if [ "$?" == 0 ]; then
71 sed '/[Ww]arning/d;/[Ee]rror/d' "out/$pattern.res" > "out/$pattern.res2"
72 sed '/[Ww]arning/d;/[Ee]rror/d' "sav/$pattern.fail" > "out/$pattern.fail2"
73 grep '[Ee]rror' "out/$pattern.res" >/dev
/null
&& echo "Error" >> "out/$pattern.res2"
74 grep '[Ee]rror' "sav/$pattern.fail" >/dev
/null
&& echo "Error" >> "out/$pattern.fail2"
75 diff -u
"out/$pattern.res2" "out/$pattern.fail2" > "out/$pattern.diff.fail2.log"
76 if [ "$?" == 0 ]; then
82 grep 'NOT YET IMPLEMENTED' "out/$pattern.res" >/dev
/null
84 if [ "x$SAV" = "xOK" ]; then
85 if [ -n
"$tap" ]; then
86 echo "ok - $description"
87 elif [ "x$FAIL" = "x" ]; then
88 echo "[ok] out/$pattern.res"
90 echo "[ok] out/$pattern.res - but sav/$pattern.fail remains!"
93 elif [ "x$FAIL" = "xOK" ]; then
94 if [ -n
"$tap" ]; then
95 echo "not ok - $description # TODO expected failure"
97 echo "[fail] out/$pattern.res"
100 elif [ "x$SOSO" = "xOK" ]; then
101 if [ -n
"$tap" ]; then
102 echo "ok - $description # SOSO"
104 echo "[soso] out/$pattern.res sav/$pattern.sav"
107 elif [ "x$NYI" = "x0" ]; then
108 if [ -n
"$tap" ]; then
109 echo "not ok - $description # TODO not yet implemented"
111 echo "[todo] out/$pattern.res -> not yet implemented"
114 elif [ "x$SOSOF" = "xOK" ]; then
115 if [ -n
"$tap" ]; then
116 echo "not ok - $description # TODO SOSO expected failure"
118 echo "[fail soso] out/$pattern.res sav/$pattern.fail"
121 elif [ "x$SAV" = "xNOK" ]; then
122 if [ -n
"$tap" ]; then
123 echo "not ok - $description"
125 echo "[======= fail out/$pattern.res sav/$pattern.sav =======]"
128 echo "$ii" >> "$ERRLIST"
129 elif [ "x$FAIL" = "xNOK" ]; then
130 if [ -n
"$tap" ]; then
131 echo "not ok - $description"
133 echo "[======= changed out/$pattern.res sav/$pattern.fail ======]"
136 echo "$ii" >> "$ERRLIST"
138 if [ -n
"$tap" ]; then
139 echo "ok - $description # skip no sav"
141 echo "[=== no sav ===] out/$pattern.res"
149 ((tapcount
=tapcount
+1))
150 recent
=`ls -t ../src/nitc ../src/nitc_[0-9] ../bin/nitc ../c_src/nitc 2>/dev/null | head -1`
151 if [[ "x$recent" == "x" ]]; then
152 if [ -n
"$tap" ]; then
153 echo "not ok - find nitc"
154 echo "Bail out! Could not find nitc, aborting"
156 echo 'Could not find nitc, aborting'
160 if [ -n
"$tap" ]; then
161 echo "ok - find nitc: $recent"
163 echo 'Using nitc from: '$recent
171 while [ $stop = false
]; do
173 -o
) OPT
="$OPT $2"; shift; shift;;
174 -v
) verbose
=true
; shift;;
176 --tap
) tap
=true
; shift;;
181 # The default nitc compiler
182 [ -z
"$NITC" ] && find_nitc
184 # Set NIT_DIR if needed
185 [ -z
"$NIT_DIR" ] && export NIT_DIR
=..
188 # Mark to distinguish files among tests
191 # File where error tests are outputed
192 # Old ERRLIST is backuped
193 ERRLIST
=${ERRLIST:-errlist}
194 ERRLIST_TARGET
=$ERRLIST
201 # Initiate new ERRLIST
202 if [ "x$ERRLIST" = "x" ]; then
212 # CLEAN the out directory
213 rm -rf out
/ 2>/dev
/null
214 mkdir out
2>/dev
/null
217 if [ ! -f
$ii ]; then
218 echo "File '$ii' does not exist."
223 if [ "x$tmp" = "x$ii" ]; then
224 includes
="-I . -I ../lib/standard -I ../lib/standard/collection -I alt"
229 f
=`basename "$ii" .nit`
230 for i
in "$ii" `./alterner.pl --start '#' --altsep '_' $ii`; do
231 bf
=`basename $i .nit`
233 test -z
"$tap" && echo -n
"=> $bf: "
235 if [ -f
"$f.inputs" ]; then
242 if [ "x$verbose" = "xtrue" ]; then
244 echo $NITC --no
-color
$OPT -o
"$ff.bin" "$i" "$includes"
246 $NITC --no
-color
$OPT -o
"$ff.bin" "$i" $includes <"$inputs" 2> "$ff.cmp.err" > "$ff.compile.log"
248 if [ "x$verbose" = "xtrue" ]; then
249 cat "$ff.compile.log"
250 cat >&2 "$ff.cmp.err"
252 egrep '^[A-Z0-9_]*$' "$ff.compile.log" > "$ff.res"
253 if [ "$ERR" != 0 ]; then
254 test -z
"$tap" && echo -n
"! "
255 cat "$ff.cmp.err" "$ff.compile.log" > "$ff.res"
256 process_result
$bf $bf
257 elif [ -x
"./$ff.bin" ]; then
258 cp "$ff.cmp.err" "$ff.res"
259 test -z
"$tap" && echo -n
". "
262 if [ "x$verbose" = "xtrue" ]; then
264 echo "NIT_NO_STACK=1 ./$ff.bin" $args
266 NIT_NO_STACK
=1 "./$ff.bin" $args < "$inputs" >> "$ff.res" 2>"$ff.err"
267 if [ "x$verbose" = "xtrue" ]; then
271 if [ -f
"$ff.write" ]; then
272 cat "$ff.write" >> "$ff.res"
273 elif [ -d
"$ff.write" ]; then
274 LANG
=C
/bin
/ls -F
$ff.
write >> "$ff.res"
276 if [ -s
"$ff.err" ]; then
277 cat "$ff.err" >> "$ff.res"
279 process_result
$bf $bf
281 if [ -f
"$f.args" ]; then
289 rm -rf
"$fff.res" "$fff.err" "$fff.write" 2> /dev
/null
290 if [ "x$verbose" = "xtrue" ]; then
292 echo "NIT_NO_STACK=1 ./$ff.bin" $args
294 test -z
"$tap" && echo -n
"==> args #"$cptr " "
295 sh
-c
"NIT_NO_STACK=1 ./$ff.bin ''$args < $inputs > $fff.res 2>$fff.err"
296 if [ "x$verbose" = "xtrue" ]; then
300 if [ -f
"$fff.write" ]; then
301 cat "$fff.write" >> "$fff.res"
302 elif [ -d
"$fff.write" ]; then
303 LANG
=C
/bin
/ls -F
$fff.
write >> "$fff.res"
305 if [ -s
"$fff.err" ]; then
306 cat "$fff.err" >> "$fff.res"
308 process_result
$bff " args #$cptr"
312 test -z
"$tap" && echo -n
"! "
313 cat "$ff.cmp.err" "$ff.compile.log" > "$ff.res"
314 #echo "Compilation error" > "$ff.res"
315 process_result
$bf "$bf"
320 if [ -n
"$tap" ]; then
322 echo "# ok:" `echo $ok | wc -w`
323 echo "# not ok:" `echo $nok | wc -w`
324 echo "# no sav:" `echo $nos | wc -w`
328 echo "ok: " `echo $ok | wc -w` "/" `echo $ok $nok $nos | wc -w`
330 if [ -n
"$nok" ]; then
332 echo "There were $(echo $nok | wc -w) errors ! (see file $ERRLIST)"
334 if [ -n
"$nos" ]; then
339 if [ "x$ERRLIST" != "x" ]; then
340 if [ -x
"$ERRLIST_TARGET" ]; then
341 mv "$ERRLIST_TARGET" "${ERRLIST_TARGET}.bak"
343 mv $ERRLIST $ERRLIST_TARGET
346 if [ -n
"$nok" ]; then