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
22 export NIT_TESTING
=true
30 Usage
: $e [options
] modulenames
31 -o option Pass option to the engine
32 -v Verbose
(show tests steps
)
34 --tap Produce TAP output
35 --engine Use a specific engine
(default
=nitc
)
36 --noskip Do not skip a
test even
if the .skip
file matches
37 --[no
]soso Force
enable (or disable
) SOSO
41 # $1 is the pattern of the test
42 # $2 is the file to compare to
44 # 0: if the file to compare to do not exists
45 # 1: if the file match
46 # 2: if the file match with soso
47 # 3: if the file do not match
48 function compare_to_result
()
52 if [ ! -r
"$sav" ]; then return 0; fi
53 diff -u
"$sav" "out/$pattern.res" > "out/$pattern.diff.sav.log"
54 if [ "$?" == 0 ]; then
57 [ -z
"$soso" ] && return 3
58 sed '/[Ww]arning/d;/[Ee]rror/d' "out/$pattern.res" > "out/$pattern.res2"
59 sed '/[Ww]arning/d;/[Ee]rror/d' "$sav" > "out/$pattern.sav2"
60 grep '[Ee]rror' "out/$pattern.res" >/dev
/null
&& echo "Error" >> "out/$pattern.res2"
61 grep '[Ee]rror' "$sav" >/dev
/null
&& echo "Error" >> "out/$pattern.sav2"
62 diff -u
"out/$pattern.sav2" "out/$pattern.res2" > "out/$pattern.diff.sav.log"
63 if [ "$?" == 0 ]; then
70 # As argument: the pattern used for the file
71 function process_result
()
73 ((tapcount
=tapcount
+1))
89 echo >>$xml "<testcase classname='$pack' name='$description'>"
90 #for sav in "sav/$engine/fixme/$pattern.res" "sav/$engine/$pattern.res" "sav/fixme/$pattern.res" "sav/$pattern.res" "sav/$pattern.sav"; do
91 for savdir
in $savdirs; do
92 sav
=$savdir/$pattern.res
93 compare_to_result
"$pattern" "$sav"
111 if [ -z
"$FIRST" ]; then
117 if [ -z
"$FIRST" ]; then
125 OLD
=`echo "$OLD" | sed -e 's/ */ /g' -e 's/^ //' -e 's/ $//'`
126 grep 'NOT YET IMPLEMENTED' "out/$pattern.res" >/dev
/null
128 if [ -n
"$SAV" ]; then
129 if [ -n
"$tap" ]; then
130 echo "ok - $description"
131 elif [ -n
"$OLD" ]; then
132 echo "[*ok*] out/$pattern.res $SAV - but $OLD remains!"
133 echo >>$xml "<error message='ok out/$pattern.res - but $OLD remains'/>"
134 remains
="$remains $OLD"
136 echo "[ok] out/$pattern.res $SAV"
139 elif [ -n
"$FIXME" ]; then
140 if [ -n
"$tap" ]; then
141 echo "not ok - $description # TODO expected failure"
142 elif [ -n
"$OLD" ]; then
143 echo "[*fixme*] out/$pattern.res $FIXME - but $OLD remains!"
144 echo >>$xml "<error message='ok out/$pattern.res - but $OLD remains'/>"
145 remains
="$remains $OLD"
147 echo "[fixme] out/$pattern.res $FIXME"
149 todos
="$todos $pattern"
150 elif [ -n
"$SOSO" ]; then
151 if [ -n
"$tap" ]; then
152 echo "ok - $description # SOSO"
154 echo "[soso] out/$pattern.res $SOSO"
157 elif [ "x$NYI" = "x0" ]; then
158 if [ -n
"$tap" ]; then
159 echo "not ok - $description # TODO not yet implemented"
161 echo "[todo] out/$pattern.res -> not yet implemented"
163 todos
="$todos $pattern"
164 elif [ -n
"$SOSOF" ]; then
165 if [ -n
"$tap" ]; then
166 echo "not ok - $description # TODO SOSO expected failure"
168 echo "[fixme soso] out/$pattern.res $SOSOF"
170 todos
="$todos $pattern"
171 elif [ -n
"$NSAV" ]; then
172 if [ -n
"$tap" ]; then
173 echo "not ok - $description"
175 echo "[======= fail out/$pattern.res $NSAV =======]"
177 echo >>$xml "<error message='fail out/$pattern.res $NSAV'/>"
178 echo >>$xml "<system-out><![CDATA["
179 head >>$xml -n
50 out
/$pattern.
diff.sav.log
180 echo >>$xml "]]></system-out>"
182 echo "$ii" >> "$ERRLIST"
183 elif [ -n
"$NFIXME" ]; then
184 if [ -n
"$tap" ]; then
185 echo "not ok - $description"
187 echo "[======= changed out/$pattern.res $NFIXME ======]"
189 echo >>$xml "<error message='changed out/$pattern.res $NFIXME'/>"
190 echo >>$xml "<system-out><![CDATA["
191 head >>$xml -n
50 out
/$pattern.
diff.sav.log
192 echo >>$xml "]]></system-out>"
194 echo "$ii" >> "$ERRLIST"
196 if [ -n
"$tap" ]; then
197 echo "ok - $description # skip no sav"
199 echo "[=== no sav ===] out/$pattern.res"
201 echo >>$xml "<skipped/>"
202 echo >>$xml "<system-out><![CDATA["
203 cat >>$xml out
/$pattern.res
204 echo >>$xml "]]></system-out>"
207 if test -s out
/$pattern.
cmp.err
; then
208 echo >>$xml "<system-err><![CDATA["
209 cat >>$xml out
/$pattern.
cmp.err
210 echo >>$xml "]]></system-err>"
212 echo >>$xml "</testcase>"
217 test "$noskip" = true
&& return 1
218 if echo "$1" |
grep -f
"$engine.skip" >/dev
/null
2>&1; then
219 ((tapcount
=tapcount
+1))
220 if [ -n
"$tap" ]; then
221 echo "ok - $2 # skip"
225 echo >>$xml "<testcase classname='$3' name='$2'><skipped/></testcase>"
233 ((tapcount
=tapcount
+1))
234 name
="$enginebinname"
235 recent
=`ls -t ../src/$name ../src/$name_[0-9] ../bin/$name ../c_src/$name 2>/dev/null | head -1`
236 if [[ "x$recent" == "x" ]]; then
237 if [ -n
"$tap" ]; then
238 echo "not ok - find binary for $engine"
239 echo "Bail out! Could not find binary for engine $engine, aborting"
241 echo "Could not find binary for engine $engine, aborting"
245 if [ -n
"$tap" ]; then
246 echo "ok - find binary for $engine: $recent $OPT"
248 echo "Find binary for engine $engine: $recent $OPT"
258 while [ $stop = false
]; do
260 -o
) OPT
="$OPT $2"; shift; shift;;
261 -v
) verbose
=true
; shift;;
263 --tap
) tap
=true
; shift;;
264 --engine
) engine
="$2"; shift; shift;;
265 --noskip
) noskip
=true
; shift;;
266 --soso
) soso
=true
; shift;;
267 --nososo
) nososo
=true
; shift;;
271 enginebinname
=$engine
274 savdirs
="sav/$engine/fixme/ sav/$engine/ sav/sav/ sav/"
279 savdirs
="sav/$engine/fixme/ sav/$engine/ sav/fixme/ sav/"
280 OPT
="--separate $OPT"
284 savdirs
="sav/$engine/fixme/ sav/$engine/ sav/fixme/ sav/"
285 OPT
="--separate $OPT"
289 savdirs
="sav/$engine/fixme/ sav/$engine/ sav/fixme/ sav/"
294 savdirs
="sav/$engine/fixme/ sav/$engine/ sav/fixme/ sav/"
299 savdirs
="sav/$engine/fixme/ sav/$engine/ sav/fixme/ sav/"
303 savdirs
="sav/$engine/fixme/ sav/$engine/ sav/fixme/ sav/"
307 # The default nitc compiler
308 [ -z
"$NITC" ] && find_nitc
310 # Set NIT_DIR if needed
311 [ -z
"$NIT_DIR" ] && export NIT_DIR
=..
313 if sh
-c
"timelimit echo" 1>/dev
/null
2>&1; then
314 TIMEOUT
="timelimit -t 600"
315 elif sh
-c
"timeout 1 echo" 1>/dev
/null
2>&1; then
316 TIMEOUT
="timeout 600s"
318 echo "No timelimit or timeout command detected. Tests may hang :("
321 # Mark to distinguish files among tests
324 # File where error tests are outputed
325 # Old ERRLIST is backuped
326 ERRLIST
=${ERRLIST:-errlist}
327 ERRLIST_TARGET
=$ERRLIST
334 # Initiate new ERRLIST
335 if [ "x$ERRLIST" = "x" ]; then
345 xml
="tests-$engine.xml"
346 echo >$xml "<testsuites><testsuite>"
348 # CLEAN the out directory
349 rm -rf out
/ 2>/dev
/null
350 mkdir out
2>/dev
/null
353 if [ ! -f
$ii ]; then
354 echo "File '$ii' does not exist."
357 f
=`basename "$ii" .nit`
359 pack
=`echo $ii | perl -p -e 's|^../([^/]*)/([a-zA-Z_]*).*|\1.\2| || s|^([a-zA-Z]*)[^_]*_([a-zA-Z]*).*|\1.\2| || s|\W*([a-zA-Z_]*).*|\1|'`
361 # Sould we skip the file for this engine?
362 need_skip
$f $f $pack && continue
365 if [ "x$tmp" = "x$ii" ]; then
366 includes
="-I . -I ../lib/standard -I ../lib/standard/collection -I alt"
371 for i
in "$ii" `./alterner.pl --start '#' --altsep '_' $ii`; do
372 bf
=`basename $i .nit`
375 # Sould we skip the alternative for this engine?
376 need_skip
$bf $bf $pack && continue
378 test -z
"$tap" && echo -n
"=> $bf: "
380 if [ -f
"$f.inputs" ]; then
386 if [ "$engine" = "niti" ]; then
387 cat > "./$ff.bin" <<END
388 exec $NITC --no
-color
$OPT "$i" $includes -- "\$@"
396 if [ "x$verbose" = "xtrue" ]; then
398 echo $NITC --no
-color
$OPT -o
"$ff.bin" "$i" "$includes"
400 NIT_NO_STACK
=1 $TIMEOUT $NITC --no
-color
$OPT -o
"$ff.bin" "$i" $includes 2> "$ff.cmp.err" > "$ff.compile.log"
402 if [ "x$verbose" = "xtrue" ]; then
403 cat "$ff.compile.log"
404 cat >&2 "$ff.cmp.err"
407 if [ "$ERR" != 0 ]; then
408 test -z
"$tap" && echo -n
"! "
409 cat "$ff.compile.log" "$ff.cmp.err" > "$ff.res"
410 process_result
$bf $bf $pack
411 elif [ -x
"./$ff.bin" ]; then
412 test -z
"$tap" && echo -n
". "
415 if [ "x$verbose" = "xtrue" ]; then
417 echo "NIT_NO_STACK=1 ./$ff.bin" $args
419 NIT_NO_STACK
=1 $TIMEOUT "./$ff.bin" $args < "$inputs" > "$ff.res" 2>"$ff.err"
420 if [ "x$verbose" = "xtrue" ]; then
424 if [ -f
"$ff.write" ]; then
425 cat "$ff.write" >> "$ff.res"
426 elif [ -d
"$ff.write" ]; then
427 LANG
=C
/bin
/ls -F
$ff.
write >> "$ff.res"
429 cp "$ff.res" "$ff.res2"
430 cat "$ff.cmp.err" "$ff.err" "$ff.res2" > "$ff.res"
431 process_result
$bf $bf $pack
433 if [ -f
"$f.args" ]; then
441 name
="$bf args $cptr"
443 # Sould we skip the input for this engine?
444 need_skip
$bff " $name" $pack && continue
446 rm -rf
"$fff.res" "$fff.err" "$fff.write" 2> /dev
/null
447 if [ "x$verbose" = "xtrue" ]; then
449 echo "NIT_NO_STACK=1 ./$ff.bin" $args
451 test -z
"$tap" && echo -n
"==> $name "
452 echo "./$ff.bin $args" > "./$fff.bin"
453 chmod +x
"./$fff.bin"
454 sh
-c
"NIT_NO_STACK=1 $TIMEOUT ./$fff.bin < $inputs > $fff.res 2>$fff.err"
455 if [ "x$verbose" = "xtrue" ]; then
459 if [ -f
"$fff.write" ]; then
460 cat "$fff.write" >> "$fff.res"
461 elif [ -d
"$fff.write" ]; then
462 LANG
=C
/bin
/ls -F
$fff.
write >> "$fff.res"
464 if [ -s
"$fff.err" ]; then
465 cp "$fff.res" "$fff.res2"
466 cat "$fff.err" "$fff.res2" > "$fff.res"
468 process_result
$bff " $name" $pack
472 test -z
"$tap" && echo -n
"! "
473 cat "$ff.cmp.err" > "$ff.res"
474 echo "Compilation error" > "$ff.res"
475 process_result
$bf "$bf" $pack
480 if [ -n
"$tap" ]; then
482 echo "# ok:" `echo $ok | wc -w`
483 echo "# not ok:" `echo $nok | wc -w`
484 echo "# no sav:" `echo $nos | wc -w`
485 echo "# todo/fixme:" `echo $todos | wc -w`
486 echo "# of sav that remains:" `echo $remains | wc -w`
490 echo "engine: $engine ($enginebinname $OPT)"
491 echo "ok: " `echo $ok | wc -w` "/" `echo $ok $nok $nos $todos | wc -w`
493 if [ -n
"$nok" ]; then
495 echo "There were $(echo $nok | wc -w) errors ! (see file $ERRLIST)"
497 if [ -n
"$nos" ]; then
500 if [ -n
"$todos" ]; then
501 echo "todo/fixme: $todos"
503 if [ -n
"$remains" ]; then
504 echo "sav that remains: $remains"
508 if [ "x$ERRLIST" != "x" ]; then
509 if [ -x
"$ERRLIST_TARGET" ]; then
510 mv "$ERRLIST_TARGET" "${ERRLIST_TARGET}.bak"
512 mv $ERRLIST $ERRLIST_TARGET
515 echo >>$xml "</testsuite></testsuites>"
517 if [ -n
"$nok" ]; then