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))
86 echo >>$xml "<testcase classname='$pack' name='$description'>"
87 for sav
in "sav/$engine/$pattern.res" "sav/$pattern.res" "sav/$pattern.sav"; do
88 compare_to_result
"$pattern" "$sav"
100 for sav
in "sav/$engine/fixme/$pattern.res" "sav/fixme/$pattern.res" "sav/$pattern.fail"; do
101 compare_to_result
"$pattern" "$sav"
113 grep 'NOT YET IMPLEMENTED' "out/$pattern.res" >/dev
/null
115 if [ -n
"$SAV" ]; then
116 if [ -n
"$tap" ]; then
117 echo "ok - $description"
118 elif [ -z
"$FIXME" ]; then
119 echo "[ok] out/$pattern.res $SAV"
121 echo "[ok] out/$pattern.res $SAV - but $FIXME remains!"
124 elif [ -n
"$FIXME" ]; then
125 if [ -n
"$tap" ]; then
126 echo "not ok - $description # TODO expected failure"
128 echo "[fixme] out/$pattern.res $FIXME"
130 todos
="$todos $pattern"
131 elif [ -n
"$SOSO" ]; then
132 if [ -n
"$tap" ]; then
133 echo "ok - $description # SOSO"
135 echo "[soso] out/$pattern.res $SOSO"
138 elif [ "x$NYI" = "x0" ]; then
139 if [ -n
"$tap" ]; then
140 echo "not ok - $description # TODO not yet implemented"
142 echo "[todo] out/$pattern.res -> not yet implemented"
144 todos
="$todos $pattern"
145 elif [ -n
"$SOSOF" ]; then
146 if [ -n
"$tap" ]; then
147 echo "not ok - $description # TODO SOSO expected failure"
149 echo "[fixme soso] out/$pattern.res $SOSOF"
151 todos
="$todos $pattern"
152 elif [ -n
"$NSAV" ]; then
153 if [ -n
"$tap" ]; then
154 echo "not ok - $description"
156 echo "[======= fail out/$pattern.res $NSAV =======]"
158 echo >>$xml "<error message='fail out/$pattern.res $NSAV'/>"
159 echo >>$xml "<system-out><![CDATA["
160 head >>$xml -n
50 out
/$pattern.
diff.sav.log
161 echo >>$xml "]]></system-out>"
163 echo "$ii" >> "$ERRLIST"
164 elif [ -n
"$NFIXME" ]; then
165 if [ -n
"$tap" ]; then
166 echo "not ok - $description"
168 echo "[======= changed out/$pattern.res $NFIXME ======]"
170 echo >>$xml "<error message='changed out/$pattern.res $NFIXME'/>"
171 echo >>$xml "<system-out><![CDATA["
172 head >>$xml -n
50 out
/$pattern.
diff.sav.log
173 echo >>$xml "]]></system-out>"
175 echo "$ii" >> "$ERRLIST"
177 if [ -n
"$tap" ]; then
178 echo "ok - $description # skip no sav"
180 echo "[=== no sav ===] out/$pattern.res"
182 echo >>$xml "<skipped/>"
183 echo >>$xml "<system-out><![CDATA["
184 cat >>$xml out
/$pattern.res
185 echo >>$xml "]]></system-out>"
188 if test -s out
/$pattern.
cmp.err
; then
189 echo >>$xml "<system-err><![CDATA["
190 cat >>$xml out
/$pattern.
cmp.err
191 echo >>$xml "]]></system-err>"
193 echo >>$xml "</testcase>"
198 test "$noskip" = true
&& return 1
199 if echo "$1" |
grep -f
"$engine.skip" >/dev
/null
2>&1; then
200 ((tapcount
=tapcount
+1))
201 if [ -n
"$tap" ]; then
202 echo "ok - $2 # skip"
206 echo >>$xml "<testcase classname='$3' name='$2'><skipped/></testcase>"
214 ((tapcount
=tapcount
+1))
215 name
="$enginebinname"
216 recent
=`ls -t ../src/$name ../src/$name_[0-9] ../bin/$name ../c_src/$name 2>/dev/null | head -1`
217 if [[ "x$recent" == "x" ]]; then
218 if [ -n
"$tap" ]; then
219 echo "not ok - find engine $name"
220 echo "Bail out! Could not find engine $name, aborting"
222 echo "Could not find engine $name, aborting"
226 if [ -n
"$tap" ]; then
227 echo "ok - find engine $name: $recent"
229 echo "Using engine $name from: $recent"
239 while [ $stop = false
]; do
241 -o
) OPT
="$OPT $2"; shift; shift;;
242 -v
) verbose
=true
; shift;;
244 --tap
) tap
=true
; shift;;
245 --engine
) engine
="$2"; shift; shift;;
246 --noskip
) noskip
=true
; shift;;
247 --soso
) soso
=true
; shift;;
248 --nososo
) nososo
=true
; shift;;
252 enginebinname
=$engine
255 nitg
) OPT
="--global $OPT";;
256 nitg
-s
) enginebinname
=nitg
; OPT
="--separate $OPT";;
257 nitg
-e
) enginebinname
=nitg
; OPT
="--erasure $OPT";;
259 niti
) enginebinname
=nit
;;
262 # The default nitc compiler
263 [ -z
"$NITC" ] && find_nitc
265 # Set NIT_DIR if needed
266 [ -z
"$NIT_DIR" ] && export NIT_DIR
=..
268 if sh
-c
"timelimit echo" 1>/dev
/null
2>&1; then
269 TIMEOUT
="timelimit -t 600"
270 elif sh
-c
"timeout 1 echo" 1>/dev
/null
2>&1; then
271 TIMEOUT
="timeout 600s"
273 echo "No timelimit or timeout command detected. Tests may hang :("
276 # Mark to distinguish files among tests
279 # File where error tests are outputed
280 # Old ERRLIST is backuped
281 ERRLIST
=${ERRLIST:-errlist}
282 ERRLIST_TARGET
=$ERRLIST
289 # Initiate new ERRLIST
290 if [ "x$ERRLIST" = "x" ]; then
300 xml
="tests-$engine.xml"
301 echo >$xml "<testsuites><testsuite>"
303 # CLEAN the out directory
304 rm -rf out
/ 2>/dev
/null
305 mkdir out
2>/dev
/null
308 if [ ! -f
$ii ]; then
309 echo "File '$ii' does not exist."
312 f
=`basename "$ii" .nit`
314 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|'`
316 # Sould we skip the file for this engine?
317 need_skip
$f $f $pack && continue
320 if [ "x$tmp" = "x$ii" ]; then
321 includes
="-I . -I ../lib/standard -I ../lib/standard/collection -I alt"
326 for i
in "$ii" `./alterner.pl --start '#' --altsep '_' $ii`; do
327 bf
=`basename $i .nit`
330 # Sould we skip the alternative for this engine?
331 need_skip
$bf $bf $pack && continue
333 test -z
"$tap" && echo -n
"=> $bf: "
335 if [ -f
"$f.inputs" ]; then
341 if [ "$engine" = "niti" ]; then
342 cat > "./$ff.bin" <<END
343 exec $NITC --no
-color
$OPT "$i" $includes -- "\$@"
351 if [ "x$verbose" = "xtrue" ]; then
353 echo $NITC --no
-color
$OPT -o
"$ff.bin" "$i" "$includes"
355 NIT_NO_STACK
=1 $TIMEOUT $NITC --no
-color
$OPT -o
"$ff.bin" "$i" $includes 2> "$ff.cmp.err" > "$ff.compile.log"
357 if [ "x$verbose" = "xtrue" ]; then
358 cat "$ff.compile.log"
359 cat >&2 "$ff.cmp.err"
362 if [ "$ERR" != 0 ]; then
363 test -z
"$tap" && echo -n
"! "
364 cat "$ff.compile.log" "$ff.cmp.err" > "$ff.res"
365 process_result
$bf $bf $pack
366 elif [ -x
"./$ff.bin" ]; then
367 test -z
"$tap" && echo -n
". "
370 if [ "x$verbose" = "xtrue" ]; then
372 echo "NIT_NO_STACK=1 ./$ff.bin" $args
374 NIT_NO_STACK
=1 $TIMEOUT "./$ff.bin" $args < "$inputs" > "$ff.res" 2>"$ff.err"
375 if [ "x$verbose" = "xtrue" ]; then
379 if [ -f
"$ff.write" ]; then
380 cat "$ff.write" >> "$ff.res"
381 elif [ -d
"$ff.write" ]; then
382 LANG
=C
/bin
/ls -F
$ff.
write >> "$ff.res"
384 cp "$ff.res" "$ff.res2"
385 cat "$ff.cmp.err" "$ff.err" "$ff.res2" > "$ff.res"
386 process_result
$bf $bf $pack
388 if [ -f
"$f.args" ]; then
396 name
="$bf args $cptr"
398 # Sould we skip the input for this engine?
399 need_skip
$bff " $name" $pack && continue
401 rm -rf
"$fff.res" "$fff.err" "$fff.write" 2> /dev
/null
402 if [ "x$verbose" = "xtrue" ]; then
404 echo "NIT_NO_STACK=1 ./$ff.bin" $args
406 test -z
"$tap" && echo -n
"==> $name "
407 echo "./$ff.bin $args" > "./$fff.bin"
408 chmod +x
"./$fff.bin"
409 sh
-c
"NIT_NO_STACK=1 $TIMEOUT ./$fff.bin < $inputs > $fff.res 2>$fff.err"
410 if [ "x$verbose" = "xtrue" ]; then
414 if [ -f
"$fff.write" ]; then
415 cat "$fff.write" >> "$fff.res"
416 elif [ -d
"$fff.write" ]; then
417 LANG
=C
/bin
/ls -F
$fff.
write >> "$fff.res"
419 if [ -s
"$fff.err" ]; then
420 cp "$fff.res" "$fff.res2"
421 cat "$fff.err" "$fff.res2" > "$fff.res"
423 process_result
$bff " $name" $pack
427 test -z
"$tap" && echo -n
"! "
428 cat "$ff.cmp.err" > "$ff.res"
429 echo "Compilation error" > "$ff.res"
430 process_result
$bf "$bf" $pack
435 if [ -n
"$tap" ]; then
437 echo "# ok:" `echo $ok | wc -w`
438 echo "# not ok:" `echo $nok | wc -w`
439 echo "# no sav:" `echo $nos | wc -w`
440 echo "# todo/fixme:" `echo $todos | wc -w`
444 echo "engine: $engine"
445 echo "ok: " `echo $ok | wc -w` "/" `echo $ok $nok $nos $todos | wc -w`
447 if [ -n
"$nok" ]; then
449 echo "There were $(echo $nok | wc -w) errors ! (see file $ERRLIST)"
451 if [ -n
"$nos" ]; then
454 if [ -n
"$todos" ]; then
455 echo "todo/fixme: $todos"
459 if [ "x$ERRLIST" != "x" ]; then
460 if [ -x
"$ERRLIST_TARGET" ]; then
461 mv "$ERRLIST_TARGET" "${ERRLIST_TARGET}.bak"
463 mv $ERRLIST $ERRLIST_TARGET
466 echo >>$xml "</testsuite></testsuites>"
468 if [ -n
"$nok" ]; then