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"
160 todos
="$todos $pattern"
161 elif [ -n
"$SOSO" ]; then
162 if [ -n
"$tap" ]; then
163 echo "ok - $description # SOSO"
165 echo "[soso] out/$pattern.res $SOSO"
168 elif [ "x$NYI" = "x0" ]; then
169 if [ -n
"$tap" ]; then
170 echo "not ok - $description # TODO not yet implemented"
172 echo "[todo] out/$pattern.res -> not yet implemented"
174 todos
="$todos $pattern"
175 elif [ -n
"$SOSOF" ]; then
176 if [ -n
"$tap" ]; then
177 echo "not ok - $description # TODO SOSO expected failure"
179 echo "[fixme soso] out/$pattern.res $SOSOF"
181 todos
="$todos $pattern"
182 elif [ -n
"$NSAV" ]; then
183 if [ -n
"$tap" ]; then
184 echo "not ok - $description"
186 echo "[======= fail out/$pattern.res $NSAV =======]"
188 echo >>$xml "<error message='fail out/$pattern.res $NSAV'/>"
189 echo >>$xml "<system-out><![CDATA["
190 cat -v out
/$pattern.
diff.sav.log |
head >>$xml -n
50
191 echo >>$xml "]]></system-out>"
193 echo "$ii" >> "$ERRLIST"
194 elif [ -n
"$NFIXME" ]; then
195 if [ -n
"$tap" ]; then
196 echo "not ok - $description"
198 echo "[======= changed out/$pattern.res $NFIXME ======]"
200 echo >>$xml "<error message='changed out/$pattern.res $NFIXME'/>"
201 echo >>$xml "<system-out><![CDATA["
202 cat -v out
/$pattern.
diff.sav.log |
head >>$xml -n
50
203 echo >>$xml "]]></system-out>"
205 echo "$ii" >> "$ERRLIST"
207 if [ -n
"$tap" ]; then
208 echo "ok - $description # skip no sav"
210 echo "[=== no sav ===] out/$pattern.res"
212 echo >>$xml "<skipped/>"
213 echo >>$xml "<system-out><![CDATA["
214 cat -v
>>$xml out
/$pattern.res
215 echo >>$xml "]]></system-out>"
218 if test -s out
/$pattern.
cmp.err
; then
219 echo >>$xml "<system-err><![CDATA["
220 cat -v
>>$xml out
/$pattern.
cmp.err
221 echo >>$xml "]]></system-err>"
223 echo >>$xml "</testcase>"
228 test "$noskip" = true
&& return 1
229 if echo "$1" |
grep -f
"$engine.skip" >/dev
/null
2>&1; then
230 ((tapcount
=tapcount
+1))
231 if [ -n
"$tap" ]; then
232 echo "ok - $2 # skip"
236 echo >>$xml "<testcase classname='$3' name='$2'><skipped/></testcase>"
244 ((tapcount
=tapcount
+1))
245 name
="$enginebinname"
246 recent
=`ls -t ../src/$name ../src/$name_[0-9] ../bin/$name ../c_src/$name 2>/dev/null | head -1`
247 if [[ "x$recent" == "x" ]]; then
248 if [ -n
"$tap" ]; then
249 echo "not ok - find binary for $engine"
250 echo "Bail out! Could not find binary for engine $engine, aborting"
252 echo "Could not find binary for engine $engine, aborting"
256 if [ -n
"$tap" ]; then
257 echo "ok - find binary for $engine: $recent $OPT"
259 echo "Find binary for engine $engine: $recent $OPT"
269 while [ $stop = false
]; do
271 -o
) OPT
="$OPT $2"; shift; shift;;
272 -v
) verbose
=true
; shift;;
274 --tap
) tap
=true
; shift;;
275 --engine
) engine
="$2"; shift; shift;;
276 --noskip
) noskip
=true
; shift;;
277 --soso
) soso
=true
; shift;;
278 --nososo
) nososo
=true
; shift;;
282 enginebinname
=$engine
287 savdirs
="sav/$engine/fixme/ sav/$engine/ sav/fixme/ sav/"
288 OPT
="--separate $OPT"
292 savdirs
="sav/$engine/fixme/ sav/$engine/ sav/fixme/ sav/"
293 OPT
="--separate $OPT"
297 savdirs
="sav/$engine/fixme/ sav/$engine/ sav/fixme/ sav/"
302 savdirs
="sav/$engine/fixme/ sav/$engine/ sav/fixme/ sav/"
307 savdirs
="sav/$engine/fixme/ sav/$engine/ sav/fixme/ sav/"
311 savdirs
="sav/$engine/fixme/ sav/$engine/ sav/fixme/ sav/"
314 echo "disabled engine $engine"
318 echo "unknown engine $engine"
323 # The default nitc compiler
324 [ -z
"$NITC" ] && find_nitc
326 # Set NIT_DIR if needed
327 [ -z
"$NIT_DIR" ] && export NIT_DIR
=..
329 if sh
-c
"timelimit echo" 1>/dev
/null
2>&1; then
330 TIMEOUT
="timelimit -t 600"
331 elif sh
-c
"timeout 1 echo" 1>/dev
/null
2>&1; then
332 TIMEOUT
="timeout 600s"
334 echo "No timelimit or timeout command detected. Tests may hang :("
337 # Mark to distinguish files among tests
340 # File where error tests are outputed
341 # Old ERRLIST is backuped
342 ERRLIST
=${ERRLIST:-errlist}
343 ERRLIST_TARGET
=$ERRLIST
350 # Initiate new ERRLIST
351 if [ "x$ERRLIST" = "x" ]; then
361 xml
="tests-$engine.xml"
362 echo >$xml "<testsuites><testsuite>"
364 # CLEAN the out directory
365 rm -rf out
/ 2>/dev
/null
366 mkdir out
2>/dev
/null
369 if [ ! -f
$ii ]; then
370 echo "File '$ii' does not exist."
373 f
=`basename "$ii" .nit`
375 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|'`
377 # Sould we skip the file for this engine?
378 need_skip
$f $f $pack && continue
381 if [ "x$tmp" = "x$ii" ]; then
382 includes
="-I . -I ../lib/standard -I ../lib/standard/collection -I alt"
387 for i
in "$ii" `./alterner.pl --start '#' --altsep '_' $ii`; do
388 bf
=`basename $i .nit`
391 # Sould we skip the alternative for this engine?
392 need_skip
$bf $bf $pack && continue
394 test -z
"$tap" && echo -n
"=> $bf: "
396 if [ -f
"$f.inputs" ]; then
402 if [ "$engine" = "niti" ]; then
403 cat > "./$ff.bin" <<END
404 exec $NITC --no
-color
$OPT "$i" $includes -- "\$@"
412 if [ "x$verbose" = "xtrue" ]; then
414 echo $NITC --no
-color
$OPT -o
"$ff.bin" "$i" "$includes"
416 NIT_NO_STACK
=1 JNI_LIB_PATH
=$JNI_LIB_PATH JAVA_HOME
=$JAVA_HOME \
417 $TIMEOUT $NITC --no
-color
$OPT -o
"$ff.bin" "$i" $includes 2> "$ff.cmp.err" > "$ff.compile.log"
419 if [ "x$verbose" = "xtrue" ]; then
420 cat "$ff.compile.log"
421 cat >&2 "$ff.cmp.err"
424 if [ "$ERR" != 0 ]; then
425 test -z
"$tap" && echo -n
"! "
426 cat "$ff.compile.log" "$ff.cmp.err" > "$ff.res"
427 process_result
$bf $bf $pack
428 elif [ -x
"./$ff.bin" ]; then
429 test -z
"$tap" && echo -n
". "
432 if [ "x$verbose" = "xtrue" ]; then
434 echo "NIT_NO_STACK=1 ./$ff.bin" $args
436 NIT_NO_STACK
=1 LD_LIBRARY_PATH
=$JNI_LIB_PATH \
437 $TIMEOUT "./$ff.bin" $args < "$inputs" > "$ff.res" 2>"$ff.err"
438 if [ "x$verbose" = "xtrue" ]; then
442 if [ -f
"$ff.write" ]; then
443 cat "$ff.write" >> "$ff.res"
444 elif [ -d
"$ff.write" ]; then
445 LANG
=C
/bin
/ls -F
$ff.
write >> "$ff.res"
447 cp "$ff.res" "$ff.res2"
448 cat "$ff.cmp.err" "$ff.err" "$ff.res2" > "$ff.res"
449 process_result
$bf $bf $pack
451 if [ -f
"$f.args" ]; then
459 name
="$bf args $cptr"
461 # Sould we skip the input for this engine?
462 need_skip
$bff " $name" $pack && continue
464 rm -rf
"$fff.res" "$fff.err" "$fff.write" 2> /dev
/null
465 if [ "x$verbose" = "xtrue" ]; then
467 echo "NIT_NO_STACK=1 ./$ff.bin" $args
469 test -z
"$tap" && echo -n
"==> $name "
470 echo "./$ff.bin $args" > "./$fff.bin"
471 chmod +x
"./$fff.bin"
472 WRITE
="$fff.write" sh
-c
"NIT_NO_STACK=1 $TIMEOUT ./$fff.bin < $inputs > $fff.res 2>$fff.err"
473 if [ "x$verbose" = "xtrue" ]; then
477 if [ -f
"$fff.write" ]; then
478 cat "$fff.write" >> "$fff.res"
479 elif [ -d
"$fff.write" ]; then
480 LANG
=C
/bin
/ls -F
$fff.
write >> "$fff.res"
482 if [ -s
"$fff.err" ]; then
483 cp "$fff.res" "$fff.res2"
484 cat "$fff.err" "$fff.res2" > "$fff.res"
486 process_result
$bff " $name" $pack
490 test -z
"$tap" && echo -n
"! "
491 cat "$ff.cmp.err" > "$ff.res"
492 echo "Compilation error" > "$ff.res"
493 process_result
$bf "$bf" $pack
498 if [ -n
"$tap" ]; then
500 echo "# ok:" `echo $ok | wc -w`
501 echo "# not ok:" `echo $nok | wc -w`
502 echo "# no sav:" `echo $nos | wc -w`
503 echo "# todo/fixme:" `echo $todos | wc -w`
504 echo "# of sav that remains:" `echo $remains | wc -w`
508 echo "engine: $engine ($enginebinname $OPT)"
509 echo "ok: " `echo $ok | wc -w` "/" `echo $ok $nok $nos $todos | wc -w`
511 if [ -n
"$nok" ]; then
513 echo "There were $(echo $nok | wc -w) errors ! (see file $ERRLIST)"
515 if [ -n
"$nos" ]; then
518 if [ -n
"$todos" ]; then
519 echo "todo/fixme: $todos"
521 if [ -n
"$remains" ]; then
522 echo "sav that remains: $remains"
526 if [ "x$ERRLIST" != "x" ]; then
527 if [ -x
"$ERRLIST_TARGET" ]; then
528 mv "$ERRLIST_TARGET" "${ERRLIST_TARGET}.bak"
530 mv $ERRLIST $ERRLIST_TARGET
533 echo >>$xml "</testsuite></testsuites>"
535 if [ -n
"$nok" ]; then