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
26 # Get the first Java lib available
28 paths
=`echo /usr/lib/jvm/*/`
32 paths
=`echo $JAVA_HOME/jre/lib/*/{client,server}/`
34 JNI_LIB_PATH
=${paths[0]}
41 Usage
: $e [options
] modulenames
42 -o option Pass option to the engine
43 -v Verbose
(show tests steps
)
45 --tap Produce TAP output
46 --engine Use a specific engine
(default
=nitg
)
47 --noskip Do not skip a
test even
if the .skip
file matches
48 --[no
]soso Force
enable (or disable
) SOSO
52 # $1 is the pattern of the test
53 # $2 is the file to compare to
55 # 0: if the file to compare to do not exists
56 # 1: if the file match
57 # 2: if the file match with soso
58 # 3: if the file do not match
59 function compare_to_result
()
63 if [ ! -r
"$sav" ]; then return 0; fi
64 diff -u
"$sav" "out/$pattern.res" > "out/$pattern.diff.sav.log"
65 if [ "$?" == 0 ]; then
68 [ -z
"$soso" ] && return 3
69 sed '/[Ww]arning/d;/[Ee]rror/d' "out/$pattern.res" > "out/$pattern.res2"
70 sed '/[Ww]arning/d;/[Ee]rror/d' "$sav" > "out/$pattern.sav2"
71 grep '[Ee]rror' "out/$pattern.res" >/dev
/null
&& echo "Error" >> "out/$pattern.res2"
72 grep '[Ee]rror' "$sav" >/dev
/null
&& echo "Error" >> "out/$pattern.sav2"
73 diff -u
"out/$pattern.sav2" "out/$pattern.res2" > "out/$pattern.diff.sav.log"
74 if [ "$?" == 0 ]; then
81 # As argument: the pattern used for the file
82 function process_result
()
84 ((tapcount
=tapcount
+1))
100 echo >>$xml "<testcase classname='$pack' name='$description'>"
101 #for sav in "sav/$engine/fixme/$pattern.res" "sav/$engine/$pattern.res" "sav/fixme/$pattern.res" "sav/$pattern.res" "sav/$pattern.sav"; do
102 for savdir
in $savdirs; do
103 sav
=$savdir/$pattern.res
104 compare_to_result
"$pattern" "$sav"
122 if [ -z
"$FIRST" ]; then
128 if [ -z
"$FIRST" ]; then
136 OLD
=`echo "$OLD" | sed -e 's/ */ /g' -e 's/^ //' -e 's/ $//'`
137 grep 'NOT YET IMPLEMENTED' "out/$pattern.res" >/dev
/null
139 if [ -n
"$SAV" ]; then
140 if [ -n
"$tap" ]; then
141 echo "ok - $description"
142 elif [ -n
"$OLD" ]; then
143 echo "[*ok*] out/$pattern.res $SAV - but $OLD remains!"
144 echo >>$xml "<error message='ok out/$pattern.res - but $OLD remains'/>"
145 remains
="$remains $OLD"
147 echo "[ok] out/$pattern.res $SAV"
150 elif [ -n
"$FIXME" ]; then
151 if [ -n
"$tap" ]; then
152 echo "not ok - $description # TODO expected failure"
153 elif [ -n
"$OLD" ]; then
154 echo "[*fixme*] out/$pattern.res $FIXME - but $OLD remains!"
155 echo >>$xml "<error message='ok out/$pattern.res - but $OLD remains'/>"
156 remains
="$remains $OLD"
158 echo "[fixme] out/$pattern.res $FIXME"
159 echo >>$xml "<skipped/>"
161 todos
="$todos $pattern"
162 elif [ -n
"$SOSO" ]; then
163 if [ -n
"$tap" ]; then
164 echo "ok - $description # SOSO"
166 echo "[soso] out/$pattern.res $SOSO"
169 elif [ "x$NYI" = "x0" ]; then
170 if [ -n
"$tap" ]; then
171 echo "not ok - $description # TODO not yet implemented"
173 echo "[todo] out/$pattern.res -> not yet implemented"
174 echo >>$xml "<skipped/>"
176 todos
="$todos $pattern"
177 elif [ -n
"$SOSOF" ]; then
178 if [ -n
"$tap" ]; then
179 echo "not ok - $description # TODO SOSO expected failure"
181 echo "[fixme soso] out/$pattern.res $SOSOF"
182 echo >>$xml "<skipped/>"
184 todos
="$todos $pattern"
185 elif [ -n
"$NSAV" ]; then
186 if [ -n
"$tap" ]; then
187 echo "not ok - $description"
189 echo "[======= fail out/$pattern.res $NSAV =======]"
191 echo >>$xml "<error message='fail out/$pattern.res $NSAV'/>"
192 echo >>$xml "<system-out><![CDATA["
193 cat -v out
/$pattern.
diff.sav.log |
head >>$xml -n
50
194 echo >>$xml "]]></system-out>"
196 echo "$ii" >> "$ERRLIST"
197 elif [ -n
"$NFIXME" ]; then
198 if [ -n
"$tap" ]; then
199 echo "not ok - $description"
201 echo "[======= changed out/$pattern.res $NFIXME ======]"
203 echo >>$xml "<error message='changed out/$pattern.res $NFIXME'/>"
204 echo >>$xml "<system-out><![CDATA["
205 cat -v out
/$pattern.
diff.sav.log |
head >>$xml -n
50
206 echo >>$xml "]]></system-out>"
208 echo "$ii" >> "$ERRLIST"
209 elif [ -s out
/$pattern.res
]; then
210 if [ -n
"$tap" ]; then
211 echo "no ok - $description"
213 echo "[=== no sav ===] out/$pattern.res is not empty"
215 echo >>$xml "<error message='no sav and not empty'/>"
216 echo >>$xml "<system-out><![CDATA["
217 cat -v
>>$xml out
/$pattern.res
218 echo >>$xml "]]></system-out>"
221 # no sav but empty res
222 if [ -n
"$tap" ]; then
223 echo "ok - $description"
225 echo "[0k] out/$pattern.res is empty"
229 if test -s out
/$pattern.
cmp.err
; then
230 echo >>$xml "<system-err><![CDATA["
231 cat -v
>>$xml out
/$pattern.
cmp.err
232 echo >>$xml "]]></system-err>"
234 echo >>$xml "</testcase>"
239 test "$noskip" = true
&& return 1
240 if echo "$1" |
grep -f
"$engine.skip" >/dev
/null
2>&1; then
241 ((tapcount
=tapcount
+1))
242 if [ -n
"$tap" ]; then
243 echo "ok - $2 # skip"
247 echo >>$xml "<testcase classname='$3' name='$2'><skipped/></testcase>"
250 if test $engine = niti
&& echo "$1" |
grep -f
"exec.skip" >/dev
/null
2>&1; then
251 ((tapcount
=tapcount
+1))
252 if [ -n
"$tap" ]; then
253 echo "ok - $2 # skip"
255 echo "=> $2: [skip exec]"
257 echo >>$xml "<testcase classname='$3' name='$2'><skipped/></testcase>"
265 test "$noskip" = true
&& return 1
266 if echo "$1" |
grep -f
"exec.skip" >/dev
/null
2>&1; then
275 test "$noskip" = true
&& return 1
276 if echo "$1" |
grep -f
"cc.skip" >/dev
/null
2>&1; then
284 ((tapcount
=tapcount
+1))
285 name
="$enginebinname"
286 recent
=`ls -t ../src/$name ../src/$name_[0-9] ../bin/$name ../c_src/$name 2>/dev/null | head -1`
287 if [[ "x$recent" == "x" ]]; then
288 if [ -n
"$tap" ]; then
289 echo "not ok - find binary for $engine"
290 echo "Bail out! Could not find binary for engine $engine, aborting"
292 echo "Could not find binary for engine $engine, aborting"
296 if [ -n
"$tap" ]; then
297 echo "ok - find binary for $engine: $recent $OPT"
299 echo "Find binary for engine $engine: $recent $OPT"
309 while [ $stop = false
]; do
311 -o
) OPT
="$OPT $2"; shift; shift;;
312 -v
) verbose
=true
; shift;;
314 --tap
) tap
=true
; shift;;
315 --engine
) engine
="$2"; shift; shift;;
316 --noskip
) noskip
=true
; shift;;
317 --soso
) soso
=true
; shift;;
318 --nososo
) nososo
=true
; shift;;
322 enginebinname
=$engine
327 savdirs
="sav/$engine/fixme/ sav/$engine/ sav/fixme/ sav/"
328 OPT
="--separate $OPT"
332 savdirs
="sav/$engine/fixme/ sav/$engine/ sav/fixme/ sav/"
333 OPT
="--separate $OPT"
337 savdirs
="sav/$engine/fixme/ sav/$engine/ sav/fixme/ sav/"
342 savdirs
="sav/$engine/fixme/ sav/$engine/ sav/fixme/ sav/"
347 savdirs
="sav/$engine/fixme/ sav/$engine/ sav/fixme/ sav/"
351 savdirs
="sav/$engine/fixme/ sav/$engine/ sav/fixme/ sav/"
354 echo "disabled engine $engine"
358 echo "unknown engine $engine"
363 # The default nitc compiler
364 [ -z
"$NITC" ] && find_nitc
366 # Set NIT_DIR if needed
367 [ -z
"$NIT_DIR" ] && export NIT_DIR
=..
369 if sh
-c
"timelimit echo" 1>/dev
/null
2>&1; then
370 TIMEOUT
="timelimit -t 600"
371 elif sh
-c
"timeout 1 echo" 1>/dev
/null
2>&1; then
372 TIMEOUT
="timeout 600s"
374 echo "No timelimit or timeout command detected. Tests may hang :("
377 # Mark to distinguish files among tests
380 # File where error tests are outputed
381 # Old ERRLIST is backuped
382 ERRLIST
=${ERRLIST:-errlist}
383 ERRLIST_TARGET
=$ERRLIST
390 # Initiate new ERRLIST
391 if [ "x$ERRLIST" = "x" ]; then
401 xml
="tests-$engine.xml"
402 echo >$xml "<testsuites><testsuite>"
404 # CLEAN the out directory
405 rm -rf out
/ 2>/dev
/null
406 mkdir out
2>/dev
/null
409 if [ ! -f
$ii ]; then
410 echo "File '$ii' does not exist."
413 f
=`basename "$ii" .nit`
415 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|'`
417 # Sould we skip the file for this engine?
418 need_skip
$f $f $pack && continue
421 if [ "x$tmp" = "x$ii" ]; then
422 includes
="-I . -I ../lib/standard -I ../lib/standard/collection -I alt"
427 for i
in "$ii" `./alterner.pl --start '#' --altsep '_' $ii`; do
428 bf
=`basename $i .nit`
431 # Sould we skip the alternative for this engine?
432 need_skip
$bf $bf $pack && continue
434 test -z
"$tap" && echo -n
"=> $bf: "
436 if [ -f
"$f.inputs" ]; then
442 if [ "$engine" = "niti" ]; then
443 cat > "./$ff.bin" <<END
444 exec $NITC --no
-color
$OPT "$i" $includes -- "\$@"
451 if skip_cc
"$bf"; then
457 if [ "x$verbose" = "xtrue" ]; then
459 echo $NITC --no
-color
$OPT -o
"$ff.bin" "$i" "$includes" $nocc
461 NIT_NO_STACK
=1 JNI_LIB_PATH
=$JNI_LIB_PATH JAVA_HOME
=$JAVA_HOME \
462 $TIMEOUT $NITC --no
-color
$OPT -o
"$ff.bin" "$i" $includes $nocc 2> "$ff.cmp.err" > "$ff.compile.log"
464 if [ "x$verbose" = "xtrue" ]; then
465 cat "$ff.compile.log"
466 cat >&2 "$ff.cmp.err"
469 if [ "$ERR" != 0 ]; then
470 test -z
"$tap" && echo -n
"! "
471 cat "$ff.compile.log" "$ff.cmp.err" > "$ff.res"
472 process_result
$bf $bf $pack
473 elif skip_exec
"$bf"; then
476 process_result
$bf $bf $pack
477 elif [ -n
"$nocc" ]; then
479 test -z
"$tap" && echo -n
"nocc "
481 process_result
$bf $bf $pack
482 elif [ -x
"./$ff.bin" ]; then
483 test -z
"$tap" && echo -n
". "
486 if [ "x$verbose" = "xtrue" ]; then
488 echo "NIT_NO_STACK=1 ./$ff.bin" $args
490 NIT_NO_STACK
=1 LD_LIBRARY_PATH
=$JNI_LIB_PATH \
491 $TIMEOUT "./$ff.bin" $args < "$inputs" > "$ff.res" 2>"$ff.err"
492 if [ "x$verbose" = "xtrue" ]; then
496 if [ -f
"$ff.write" ]; then
497 cat "$ff.write" >> "$ff.res"
498 elif [ -d
"$ff.write" ]; then
499 LANG
=C
/bin
/ls -F
$ff.
write >> "$ff.res"
501 cp "$ff.res" "$ff.res2"
502 cat "$ff.cmp.err" "$ff.err" "$ff.res2" > "$ff.res"
503 process_result
$bf $bf $pack
505 if [ -f
"$f.args" ]; then
513 name
="$bf args $cptr"
515 # Sould we skip the input for this engine?
516 need_skip
$bff " $name" $pack && continue
518 # use a specific inputs file, if required
519 if [ -f
"$bff.inputs" ]; then
520 ffinputs
="$bff.inputs"
525 rm -rf
"$fff.res" "$fff.err" "$fff.write" 2> /dev
/null
526 if [ "x$verbose" = "xtrue" ]; then
528 echo "NIT_NO_STACK=1 ./$ff.bin" $args
530 test -z
"$tap" && echo -n
"==> $name "
531 echo "./$ff.bin $args" > "./$fff.bin"
532 chmod +x
"./$fff.bin"
533 WRITE
="$fff.write" sh
-c
"NIT_NO_STACK=1 $TIMEOUT ./$fff.bin < $ffinputs > $fff.res 2>$fff.err"
534 if [ "x$verbose" = "xtrue" ]; then
538 if [ -f
"$fff.write" ]; then
539 cat "$fff.write" >> "$fff.res"
540 elif [ -d
"$fff.write" ]; then
541 LANG
=C
/bin
/ls -F
$fff.
write >> "$fff.res"
543 if [ -s
"$fff.err" ]; then
544 cp "$fff.res" "$fff.res2"
545 cat "$fff.err" "$fff.res2" > "$fff.res"
547 process_result
$bff " $name" $pack
550 elif [ -f
"./$ff.bin" ]; then
551 echo "Not executable (platform?)" > "$ff.res"
552 process_result
$bf "$bf" $pack
554 test -z
"$tap" && echo -n
"! "
555 cat "$ff.cmp.err" > "$ff.res"
556 echo "Compilation error" > "$ff.res"
557 process_result
$bf "$bf" $pack
562 if [ -n
"$tap" ]; then
564 echo "# ok:" `echo $ok | wc -w`
565 echo "# not ok:" `echo $nok | wc -w`
566 echo "# no sav:" `echo $nos | wc -w`
567 echo "# todo/fixme:" `echo $todos | wc -w`
568 echo "# of sav that remains:" `echo $remains | wc -w`
572 echo "engine: $engine ($enginebinname $OPT)"
573 echo "ok: " `echo $ok | wc -w` "/" `echo $ok $nok $nos $todos | wc -w`
575 if [ -n
"$nok" ]; then
577 echo "There were $(echo $nok | wc -w) errors ! (see file $ERRLIST)"
579 if [ -n
"$nos" ]; then
582 if [ -n
"$todos" ]; then
583 echo "todo/fixme: $todos"
585 if [ -n
"$remains" ]; then
586 echo "sav that remains: $remains"
590 if [ "x$ERRLIST" != "x" ]; then
591 if [ -x
"$ERRLIST_TARGET" ]; then
592 mv "$ERRLIST_TARGET" "${ERRLIST_TARGET}.bak"
594 mv $ERRLIST $ERRLIST_TARGET
597 echo >>$xml "</testsuite></testsuites>"
599 if [ -n
"$nok" ]; then