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 the engine
29 -v Verbose
(show tests steps
)
31 --tap Produce TAP output
32 --engine Use a specific engine
(default
=nitc
)
33 --noskip Do not skip a
test even
if the .skip
file matches
37 # As argument: the pattern used for the file
38 function process_result
()
40 ((tapcount
=tapcount
+1))
48 if [ -r
"sav/$pattern.sav" ]; then
49 diff -u
"out/$pattern.res" "sav/$pattern.sav" > "out/$pattern.diff.sav.log"
50 if [ "$?" == 0 ]; then
55 sed '/[Ww]arning/d;/[Ee]rror/d' "out/$pattern.res" > "out/$pattern.res2"
56 sed '/[Ww]arning/d;/[Ee]rror/d' "sav/$pattern.sav" > "out/$pattern.sav2"
57 grep '[Ee]rror' "out/$pattern.res" >/dev
/null
&& echo "Error" >> "out/$pattern.res2"
58 grep '[Ee]rror' "sav/$pattern.sav" >/dev
/null
&& echo "Error" >> "out/$pattern.sav2"
59 diff -u
"out/$pattern.res2" "out/$pattern.sav2" > "out/$pattern.diff.sav2.log"
60 if [ "$?" == 0 ]; then
66 if [ -r
"sav/$pattern.fail" ]; then
67 diff -u
"out/$pattern.res" "sav/$pattern.fail" > "out/$pattern.diff.fail.log"
68 if [ "$?" == 0 ]; then
73 sed '/[Ww]arning/d;/[Ee]rror/d' "out/$pattern.res" > "out/$pattern.res2"
74 sed '/[Ww]arning/d;/[Ee]rror/d' "sav/$pattern.fail" > "out/$pattern.fail2"
75 grep '[Ee]rror' "out/$pattern.res" >/dev
/null
&& echo "Error" >> "out/$pattern.res2"
76 grep '[Ee]rror' "sav/$pattern.fail" >/dev
/null
&& echo "Error" >> "out/$pattern.fail2"
77 diff -u
"out/$pattern.res2" "out/$pattern.fail2" > "out/$pattern.diff.fail2.log"
78 if [ "$?" == 0 ]; then
84 grep 'NOT YET IMPLEMENTED' "out/$pattern.res" >/dev
/null
86 if [ "x$SAV" = "xOK" ]; then
87 if [ -n
"$tap" ]; then
88 echo "ok - $description"
89 elif [ "x$FAIL" = "x" ]; then
90 echo "[ok] out/$pattern.res"
92 echo "[ok] out/$pattern.res - but sav/$pattern.fail remains!"
95 elif [ "x$FAIL" = "xOK" ]; then
96 if [ -n
"$tap" ]; then
97 echo "not ok - $description # TODO expected failure"
99 echo "[fail] out/$pattern.res"
102 elif [ "x$SOSO" = "xOK" ]; then
103 if [ -n
"$tap" ]; then
104 echo "ok - $description # SOSO"
106 echo "[soso] out/$pattern.res sav/$pattern.sav"
109 elif [ "x$NYI" = "x0" ]; then
110 if [ -n
"$tap" ]; then
111 echo "not ok - $description # TODO not yet implemented"
113 echo "[todo] out/$pattern.res -> not yet implemented"
116 elif [ "x$SOSOF" = "xOK" ]; then
117 if [ -n
"$tap" ]; then
118 echo "not ok - $description # TODO SOSO expected failure"
120 echo "[fail soso] out/$pattern.res sav/$pattern.fail"
123 elif [ "x$SAV" = "xNOK" ]; then
124 if [ -n
"$tap" ]; then
125 echo "not ok - $description"
127 echo "[======= fail out/$pattern.res sav/$pattern.sav =======]"
130 echo "$ii" >> "$ERRLIST"
131 elif [ "x$FAIL" = "xNOK" ]; then
132 if [ -n
"$tap" ]; then
133 echo "not ok - $description"
135 echo "[======= changed out/$pattern.res sav/$pattern.fail ======]"
138 echo "$ii" >> "$ERRLIST"
140 if [ -n
"$tap" ]; then
141 echo "ok - $description # skip no sav"
143 echo "[=== no sav ===] out/$pattern.res"
151 test "$noskip" = true
&& return 1
152 if grep "$engine" "sav/$1.skip" >/dev
/null
2>&1; then
153 ((tapcount
=tapcount
+1))
154 if [ -n
"$tap" ]; then
155 echo "ok - $2 # skip"
166 ((tapcount
=tapcount
+1))
167 name
="$enginebinname"
168 recent
=`ls -t ../src/$name ../src/$name_[0-9] ../bin/$name ../c_src/$name 2>/dev/null | head -1`
169 if [[ "x$recent" == "x" ]]; then
170 if [ -n
"$tap" ]; then
171 echo "not ok - find engine $name"
172 echo "Bail out! Could not find engine $name, aborting"
174 echo "Could not find engine $name, aborting"
178 if [ -n
"$tap" ]; then
179 echo "ok - find engine $name: $recent"
181 echo "Using engine $name from: $recent"
191 while [ $stop = false
]; do
193 -o
) OPT
="$OPT $2"; shift; shift;;
194 -v
) verbose
=true
; shift;;
196 --tap
) tap
=true
; shift;;
197 --engine
) engine
="$2"; shift; shift;;
198 --noskip
) noskip
=true
; shift;;
202 enginebinname
=$engine
206 niti
) enginebinname
=nit
;;
209 # The default nitc compiler
210 [ -z
"$NITC" ] && find_nitc
212 # Set NIT_DIR if needed
213 [ -z
"$NIT_DIR" ] && export NIT_DIR
=..
216 # Mark to distinguish files among tests
219 # File where error tests are outputed
220 # Old ERRLIST is backuped
221 ERRLIST
=${ERRLIST:-errlist}
222 ERRLIST_TARGET
=$ERRLIST
229 # Initiate new ERRLIST
230 if [ "x$ERRLIST" = "x" ]; then
240 # CLEAN the out directory
241 rm -rf out
/ 2>/dev
/null
242 mkdir out
2>/dev
/null
245 if [ ! -f
$ii ]; then
246 echo "File '$ii' does not exist."
249 f
=`basename "$ii" .nit`
251 # Sould we skip the file for this engine?
252 need_skip
$f $f && continue
255 if [ "x$tmp" = "x$ii" ]; then
256 includes
="-I . -I ../lib/standard -I ../lib/standard/collection -I alt"
261 for i
in "$ii" `./alterner.pl --start '#' --altsep '_' $ii`; do
262 bf
=`basename $i .nit`
265 # Sould we skip the alternative for this engine?
266 need_skip
$bf $bf && continue
268 test -z
"$tap" && echo -n
"=> $bf: "
270 if [ -f
"$f.inputs" ]; then
276 if [ "$engine" = "niti" ]; then
277 cat > "./$ff.bin" <<END
278 exec $NITC --no
-color
$OPT "$i" $includes -- "\$@"
286 if [ "x$verbose" = "xtrue" ]; then
288 echo $NITC --no
-color
$OPT -o
"$ff.bin" "$i" "$includes"
290 $NITC --no
-color
$OPT -o
"$ff.bin" "$i" $includes 2> "$ff.cmp.err" > "$ff.compile.log"
292 if [ "x$verbose" = "xtrue" ]; then
293 cat "$ff.compile.log"
294 cat >&2 "$ff.cmp.err"
297 if [ "$ERR" != 0 ]; then
298 test -z
"$tap" && echo -n
"! "
299 cat "$ff.cmp.err" "$ff.compile.log" > "$ff.res"
300 process_result
$bf $bf
301 elif [ -x
"./$ff.bin" ]; then
302 cp "$ff.cmp.err" "$ff.res"
303 test -z
"$tap" && echo -n
". "
306 if [ "x$verbose" = "xtrue" ]; then
308 echo "NIT_NO_STACK=1 ./$ff.bin" $args
310 NIT_NO_STACK
=1 "./$ff.bin" $args < "$inputs" >> "$ff.res" 2>"$ff.err"
311 if [ "x$verbose" = "xtrue" ]; then
315 if [ -f
"$ff.write" ]; then
316 cat "$ff.write" >> "$ff.res"
317 elif [ -d
"$ff.write" ]; then
318 LANG
=C
/bin
/ls -F
$ff.
write >> "$ff.res"
320 if [ -s
"$ff.err" ]; then
321 cat "$ff.err" >> "$ff.res"
323 process_result
$bf $bf
325 if [ -f
"$f.args" ]; then
334 # Sould we skip the input for this engine?
335 need_skip
$bff " args #$cptr" && continue
337 rm -rf
"$fff.res" "$fff.err" "$fff.write" 2> /dev
/null
338 if [ "x$verbose" = "xtrue" ]; then
340 echo "NIT_NO_STACK=1 ./$ff.bin" $args
342 test -z
"$tap" && echo -n
"==> args #"$cptr " "
343 sh
-c
"NIT_NO_STACK=1 ./$ff.bin ''$args < $inputs > $fff.res 2>$fff.err"
344 if [ "x$verbose" = "xtrue" ]; then
348 if [ -f
"$fff.write" ]; then
349 cat "$fff.write" >> "$fff.res"
350 elif [ -d
"$fff.write" ]; then
351 LANG
=C
/bin
/ls -F
$fff.
write >> "$fff.res"
353 if [ -s
"$fff.err" ]; then
354 cat "$fff.err" >> "$fff.res"
356 process_result
$bff " args #$cptr"
360 test -z
"$tap" && echo -n
"! "
361 cat "$ff.cmp.err" > "$ff.res"
362 echo "Compilation error" > "$ff.res"
363 process_result
$bf "$bf"
368 if [ -n
"$tap" ]; then
370 echo "# ok:" `echo $ok | wc -w`
371 echo "# not ok:" `echo $nok | wc -w`
372 echo "# no sav:" `echo $nos | wc -w`
376 echo "ok: " `echo $ok | wc -w` "/" `echo $ok $nok $nos | wc -w`
378 if [ -n
"$nok" ]; then
380 echo "There were $(echo $nok | wc -w) errors ! (see file $ERRLIST)"
382 if [ -n
"$nos" ]; then
387 if [ "x$ERRLIST" != "x" ]; then
388 if [ -x
"$ERRLIST_TARGET" ]; then
389 mv "$ERRLIST_TARGET" "${ERRLIST_TARGET}.bak"
391 mv $ERRLIST $ERRLIST_TARGET
394 if [ -n
"$nok" ]; then