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
28 Usage
: $e [options
] modulenames
29 -o option Pass option to the engine
30 -v Verbose
(show tests steps
)
32 --tap Produce TAP output
33 --engine Use a specific engine
(default
=nitc
)
34 --noskip Do not skip a
test even
if the .skip
file matches
35 --[no
]soso Force
enable (or disable
) SOSO
39 # $1 is the pattern of the test
40 # $2 is the file to compare to
42 # 0: if the file to compare to do not exists
43 # 1: if the file match
44 # 2: if the file match with soso
45 # 3: if the file do not match
46 function compare_to_result
()
50 if [ ! -r
"$sav" ]; then return 0; fi
51 diff -u
"$sav" "out/$pattern.res" > "out/$pattern.diff.sav.log"
52 if [ "$?" == 0 ]; then
55 [ -z
"$soso" ] && return 3
56 sed '/[Ww]arning/d;/[Ee]rror/d' "out/$pattern.res" > "out/$pattern.res2"
57 sed '/[Ww]arning/d;/[Ee]rror/d' "$sav" > "out/$pattern.sav2"
58 grep '[Ee]rror' "out/$pattern.res" >/dev
/null
&& echo "Error" >> "out/$pattern.res2"
59 grep '[Ee]rror' "$sav" >/dev
/null
&& echo "Error" >> "out/$pattern.sav2"
60 diff -u
"out/$pattern.sav2" "out/$pattern.res2" > "out/$pattern.diff.sav.log"
61 if [ "$?" == 0 ]; then
68 # As argument: the pattern used for the file
69 function process_result
()
71 ((tapcount
=tapcount
+1))
84 echo >>$xml "<testcase classname='$pack' name='$description'>"
85 for sav
in "sav/$engine/$pattern.res" "sav/$pattern.res" "sav/$pattern.sav"; do
86 compare_to_result
"$pattern" "$sav"
98 for sav
in "sav/$engine/fixme/$pattern.res" "sav/fixme/$pattern.res" "sav/$pattern.fail"; do
99 compare_to_result
"$pattern" "$sav"
111 grep 'NOT YET IMPLEMENTED' "out/$pattern.res" >/dev
/null
113 if [ -n
"$SAV" ]; then
114 if [ -n
"$tap" ]; then
115 echo "ok - $description"
116 elif [ -z
"$FIXME" ]; then
117 echo "[ok] out/$pattern.res $SAV"
119 echo "[ok] out/$pattern.res $SAV - but $FIXME remains!"
122 elif [ -n
"$FIXME" ]; then
123 if [ -n
"$tap" ]; then
124 echo "not ok - $description # TODO expected failure"
126 echo "[fixme] out/$pattern.res $FIXME"
128 todos
="$todos $pattern"
129 elif [ -n
"$SOSO" ]; then
130 if [ -n
"$tap" ]; then
131 echo "ok - $description # SOSO"
133 echo "[soso] out/$pattern.res $SOSO"
136 elif [ "x$NYI" = "x0" ]; then
137 if [ -n
"$tap" ]; then
138 echo "not ok - $description # TODO not yet implemented"
140 echo "[todo] out/$pattern.res -> not yet implemented"
142 todos
="$todos $pattern"
143 elif [ -n
"$SOSOF" ]; then
144 if [ -n
"$tap" ]; then
145 echo "not ok - $description # TODO SOSO expected failure"
147 echo "[fixme soso] out/$pattern.res $SOSOF"
149 todos
="$todos $pattern"
150 elif [ -n
"$NSAV" ]; then
151 if [ -n
"$tap" ]; then
152 echo "not ok - $description"
154 echo "[======= fail out/$pattern.res $NSAV =======]"
156 echo >>$xml "<error message='fail out/$pattern.res $NSAV'/>"
157 echo >>$xml "<system-out><![CDATA["
158 head >>$xml -n
50 out
/$pattern.
diff.sav.log
159 echo >>$xml "]]></system-out>"
161 echo "$ii" >> "$ERRLIST"
162 elif [ -n
"$NFIXME" ]; then
163 if [ -n
"$tap" ]; then
164 echo "not ok - $description"
166 echo "[======= changed out/$pattern.res $NFIXME ======]"
168 echo >>$xml "<error message='changed out/$pattern.res $NFIXME'/>"
169 echo >>$xml "<system-out><![CDATA["
170 head >>$xml -n
50 out
/$pattern.
diff.sav.log
171 echo >>$xml "]]></system-out>"
173 echo "$ii" >> "$ERRLIST"
175 if [ -n
"$tap" ]; then
176 echo "ok - $description # skip no sav"
178 echo "[=== no sav ===] out/$pattern.res"
180 echo >>$xml "<skipped/>"
181 echo >>$xml "<system-out><![CDATA["
182 cat >>$xml out
/$pattern.res
183 echo >>$xml "]]></system-out>"
186 if test -s out
/$pattern.
cmp.err
; then
187 echo >>$xml "<system-err><![CDATA["
188 cat >>$xml out
/$pattern.
cmp.err
189 echo >>$xml "]]></system-err>"
191 echo >>$xml "</testcase>"
196 test "$noskip" = true
&& return 1
197 if echo "$1" |
grep -f
"$engine.skip" >/dev
/null
2>&1; then
198 ((tapcount
=tapcount
+1))
199 if [ -n
"$tap" ]; then
200 echo "ok - $2 # skip"
204 echo >>$xml "<testcase classname='$3' name='$2'><skipped/></testcase>"
212 ((tapcount
=tapcount
+1))
213 name
="$enginebinname"
214 recent
=`ls -t ../src/$name ../src/$name_[0-9] ../bin/$name ../c_src/$name 2>/dev/null | head -1`
215 if [[ "x$recent" == "x" ]]; then
216 if [ -n
"$tap" ]; then
217 echo "not ok - find engine $name"
218 echo "Bail out! Could not find engine $name, aborting"
220 echo "Could not find engine $name, aborting"
224 if [ -n
"$tap" ]; then
225 echo "ok - find engine $name: $recent"
227 echo "Using engine $name from: $recent"
237 while [ $stop = false
]; do
239 -o
) OPT
="$OPT $2"; shift; shift;;
240 -v
) verbose
=true
; shift;;
242 --tap
) tap
=true
; shift;;
243 --engine
) engine
="$2"; shift; shift;;
244 --noskip
) noskip
=true
; shift;;
245 --soso
) soso
=true
; shift;;
246 --nososo
) nososo
=true
; shift;;
250 enginebinname
=$engine
253 nitg
) OPT
="--global $OPT";;
254 nitg
-s
) enginebinname
=nitg
; OPT
="--separate $OPT";;
255 nitg
-e
) enginebinname
=nitg
; OPT
="--erasure $OPT";;
257 niti
) enginebinname
=nit
;;
260 # The default nitc compiler
261 [ -z
"$NITC" ] && find_nitc
263 # Set NIT_DIR if needed
264 [ -z
"$NIT_DIR" ] && export NIT_DIR
=..
266 if sh
-c
"timelimit echo" 1>/dev
/null
2>&1; then
267 TIMEOUT
="timelimit -t 600"
268 elif sh
-c
"timeout 1 echo" 1>/dev
/null
2>&1; then
269 TIMEOUT
="timeout 600s"
271 echo "No timelimit or timeout command detected. Tests may hang :("
274 # Mark to distinguish files among tests
277 # File where error tests are outputed
278 # Old ERRLIST is backuped
279 ERRLIST
=${ERRLIST:-errlist}
280 ERRLIST_TARGET
=$ERRLIST
287 # Initiate new ERRLIST
288 if [ "x$ERRLIST" = "x" ]; then
298 xml
="tests-$engine.xml"
299 echo >$xml "<testsuites><testsuite>"
301 # CLEAN the out directory
302 rm -rf out
/ 2>/dev
/null
303 mkdir out
2>/dev
/null
306 if [ ! -f
$ii ]; then
307 echo "File '$ii' does not exist."
310 f
=`basename "$ii" .nit`
312 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|'`
314 # Sould we skip the file for this engine?
315 need_skip
$f $f $pack && continue
318 if [ "x$tmp" = "x$ii" ]; then
319 includes
="-I . -I ../lib/standard -I ../lib/standard/collection -I alt"
324 for i
in "$ii" `./alterner.pl --start '#' --altsep '_' $ii`; do
325 bf
=`basename $i .nit`
328 # Sould we skip the alternative for this engine?
329 need_skip
$bf $bf $pack && continue
331 test -z
"$tap" && echo -n
"=> $bf: "
333 if [ -f
"$f.inputs" ]; then
339 if [ "$engine" = "niti" ]; then
340 cat > "./$ff.bin" <<END
341 exec $NITC --no
-color
$OPT "$i" $includes -- "\$@"
349 if [ "x$verbose" = "xtrue" ]; then
351 echo $NITC --no
-color
$OPT -o
"$ff.bin" "$i" "$includes"
353 NIT_NO_STACK
=1 $TIMEOUT $NITC --no
-color
$OPT -o
"$ff.bin" "$i" $includes 2> "$ff.cmp.err" > "$ff.compile.log"
355 if [ "x$verbose" = "xtrue" ]; then
356 cat "$ff.compile.log"
357 cat >&2 "$ff.cmp.err"
360 if [ "$ERR" != 0 ]; then
361 test -z
"$tap" && echo -n
"! "
362 cat "$ff.compile.log" "$ff.cmp.err" > "$ff.res"
363 process_result
$bf $bf $pack
364 elif [ -x
"./$ff.bin" ]; then
365 test -z
"$tap" && echo -n
". "
368 if [ "x$verbose" = "xtrue" ]; then
370 echo "NIT_NO_STACK=1 ./$ff.bin" $args
372 NIT_NO_STACK
=1 $TIMEOUT "./$ff.bin" $args < "$inputs" > "$ff.res" 2>"$ff.err"
373 if [ "x$verbose" = "xtrue" ]; then
377 if [ -f
"$ff.write" ]; then
378 cat "$ff.write" >> "$ff.res"
379 elif [ -d
"$ff.write" ]; then
380 LANG
=C
/bin
/ls -F
$ff.
write >> "$ff.res"
382 cp "$ff.res" "$ff.res2"
383 cat "$ff.cmp.err" "$ff.err" "$ff.res2" > "$ff.res"
384 process_result
$bf $bf $pack
386 if [ -f
"$f.args" ]; then
394 name
="$bf args $cptr"
396 # Sould we skip the input for this engine?
397 need_skip
$bff " $name" $pack && continue
399 rm -rf
"$fff.res" "$fff.err" "$fff.write" 2> /dev
/null
400 if [ "x$verbose" = "xtrue" ]; then
402 echo "NIT_NO_STACK=1 ./$ff.bin" $args
404 test -z
"$tap" && echo -n
"==> $name "
405 echo "./$ff.bin $args" > "./$fff.bin"
406 chmod +x
"./$fff.bin"
407 sh
-c
"NIT_NO_STACK=1 $TIMEOUT ./$fff.bin < $inputs > $fff.res 2>$fff.err"
408 if [ "x$verbose" = "xtrue" ]; then
412 if [ -f
"$fff.write" ]; then
413 cat "$fff.write" >> "$fff.res"
414 elif [ -d
"$fff.write" ]; then
415 LANG
=C
/bin
/ls -F
$fff.
write >> "$fff.res"
417 if [ -s
"$fff.err" ]; then
418 cp "$fff.res" "$fff.res2"
419 cat "$fff.err" "$fff.res2" > "$fff.res"
421 process_result
$bff " $name" $pack
425 test -z
"$tap" && echo -n
"! "
426 cat "$ff.cmp.err" > "$ff.res"
427 echo "Compilation error" > "$ff.res"
428 process_result
$bf "$bf" $pack
433 if [ -n
"$tap" ]; then
435 echo "# ok:" `echo $ok | wc -w`
436 echo "# not ok:" `echo $nok | wc -w`
437 echo "# no sav:" `echo $nos | wc -w`
438 echo "# todo/fixme:" `echo $todos | wc -w`
442 echo "ok: " `echo $ok | wc -w` "/" `echo $ok $nok $nos $todos | wc -w`
444 if [ -n
"$nok" ]; then
446 echo "There were $(echo $nok | wc -w) errors ! (see file $ERRLIST)"
448 if [ -n
"$nos" ]; then
451 if [ -n
"$todos" ]; then
452 echo "todo/fixme: $todos"
456 if [ "x$ERRLIST" != "x" ]; then
457 if [ -x
"$ERRLIST_TARGET" ]; then
458 mv "$ERRLIST_TARGET" "${ERRLIST_TARGET}.bak"
460 mv $ERRLIST $ERRLIST_TARGET
463 echo >>$xml "</testsuite></testsuites>"
465 if [ -n
"$nok" ]; then