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
"out/$pattern.res" "$sav" > "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.res2" "out/$pattern.sav2" > "out/$pattern.diff.sav2.log"
61 if [ "$?" == 0 ]; then
68 # As argument: the pattern used for the file
69 function process_result
()
71 ((tapcount
=tapcount
+1))
83 for sav
in "sav/$engine/$pattern.res" "sav/$pattern.res" "sav/$pattern.sav"; do
84 compare_to_result
"$pattern" "$sav"
96 for sav
in "sav/$engine/fixme/$pattern.res" "sav/fixme/$pattern.res" "sav/$pattern.fail"; do
97 compare_to_result
"$pattern" "$sav"
109 grep 'NOT YET IMPLEMENTED' "out/$pattern.res" >/dev
/null
111 if [ -n
"$SAV" ]; then
112 if [ -n
"$tap" ]; then
113 echo "ok - $description"
114 elif [ -z
"$FIXME" ]; then
115 echo "[ok] out/$pattern.res $SAV"
117 echo "[ok] out/$pattern.res $SAV - but $FIXME remains!"
120 elif [ -n
"$FIXME" ]; then
121 if [ -n
"$tap" ]; then
122 echo "not ok - $description # TODO expected failure"
124 echo "[fixme] out/$pattern.res $FIXME"
126 todos
="$todos $pattern"
127 elif [ -n
"$SOSO" ]; then
128 if [ -n
"$tap" ]; then
129 echo "ok - $description # SOSO"
131 echo "[soso] out/$pattern.res $SOSO"
134 elif [ "x$NYI" = "x0" ]; then
135 if [ -n
"$tap" ]; then
136 echo "not ok - $description # TODO not yet implemented"
138 echo "[todo] out/$pattern.res -> not yet implemented"
140 todos
="$todos $pattern"
141 elif [ -n
"$SOSOF" ]; then
142 if [ -n
"$tap" ]; then
143 echo "not ok - $description # TODO SOSO expected failure"
145 echo "[fixme soso] out/$pattern.res $SOSOF"
147 todos
="$todos $pattern"
148 elif [ -n
"$NSAV" ]; then
149 if [ -n
"$tap" ]; then
150 echo "not ok - $description"
152 echo "[======= fail out/$pattern.res $NSAV =======]"
155 echo "$ii" >> "$ERRLIST"
156 elif [ -n
"$NFIXME" ]; then
157 if [ -n
"$tap" ]; then
158 echo "not ok - $description"
160 echo "[======= changed out/$pattern.res $NFIXME ======]"
163 echo "$ii" >> "$ERRLIST"
165 if [ -n
"$tap" ]; then
166 echo "ok - $description # skip no sav"
168 echo "[=== no sav ===] out/$pattern.res"
176 test "$noskip" = true
&& return 1
177 if echo "$1" |
grep -f
"$engine.skip" >/dev
/null
2>&1; then
178 ((tapcount
=tapcount
+1))
179 if [ -n
"$tap" ]; then
180 echo "ok - $2 # skip"
191 ((tapcount
=tapcount
+1))
192 name
="$enginebinname"
193 recent
=`ls -t ../src/$name ../src/$name_[0-9] ../bin/$name ../c_src/$name 2>/dev/null | head -1`
194 if [[ "x$recent" == "x" ]]; then
195 if [ -n
"$tap" ]; then
196 echo "not ok - find engine $name"
197 echo "Bail out! Could not find engine $name, aborting"
199 echo "Could not find engine $name, aborting"
203 if [ -n
"$tap" ]; then
204 echo "ok - find engine $name: $recent"
206 echo "Using engine $name from: $recent"
216 while [ $stop = false
]; do
218 -o
) OPT
="$OPT $2"; shift; shift;;
219 -v
) verbose
=true
; shift;;
221 --tap
) tap
=true
; shift;;
222 --engine
) engine
="$2"; shift; shift;;
223 --noskip
) noskip
=true
; shift;;
224 --soso
) soso
=true
; shift;;
225 --nososo
) nososo
=true
; shift;;
229 enginebinname
=$engine
232 nitg
) OPT
="--global $OPT";;
233 nitg
-s
) enginebinname
=nitg
; OPT
="--separate $OPT";;
234 nitg
-e
) enginebinname
=nitg
; OPT
="--erasure $OPT";;
236 niti
) enginebinname
=nit
;;
239 # The default nitc compiler
240 [ -z
"$NITC" ] && find_nitc
242 # Set NIT_DIR if needed
243 [ -z
"$NIT_DIR" ] && export NIT_DIR
=..
245 if sh
-c
"timelimit echo" 1>/dev
/null
2>&1; then
246 TIMEOUT
="timelimit -t 600"
247 elif sh
-c
"timeout 1 echo" 1>/dev
/null
2>&1; then
248 TIMEOUT
="timeout 600s"
250 echo "No timelimit or timeout command detected. Tests may hang :("
253 # Mark to distinguish files among tests
256 # File where error tests are outputed
257 # Old ERRLIST is backuped
258 ERRLIST
=${ERRLIST:-errlist}
259 ERRLIST_TARGET
=$ERRLIST
266 # Initiate new ERRLIST
267 if [ "x$ERRLIST" = "x" ]; then
278 # CLEAN the out directory
279 rm -rf out
/ 2>/dev
/null
280 mkdir out
2>/dev
/null
283 if [ ! -f
$ii ]; then
284 echo "File '$ii' does not exist."
287 f
=`basename "$ii" .nit`
289 # Sould we skip the file for this engine?
290 need_skip
$f $f && continue
293 if [ "x$tmp" = "x$ii" ]; then
294 includes
="-I . -I ../lib/standard -I ../lib/standard/collection -I alt"
299 for i
in "$ii" `./alterner.pl --start '#' --altsep '_' $ii`; do
300 bf
=`basename $i .nit`
303 # Sould we skip the alternative for this engine?
304 need_skip
$bf $bf && continue
306 test -z
"$tap" && echo -n
"=> $bf: "
308 if [ -f
"$f.inputs" ]; then
314 if [ "$engine" = "niti" ]; then
315 cat > "./$ff.bin" <<END
316 exec $NITC --no
-color
$OPT "$i" $includes -- "\$@"
324 if [ "x$verbose" = "xtrue" ]; then
326 echo $NITC --no
-color
$OPT -o
"$ff.bin" "$i" "$includes"
328 NIT_NO_STACK
=1 $TIMEOUT $NITC --no
-color
$OPT -o
"$ff.bin" "$i" $includes 2> "$ff.cmp.err" > "$ff.compile.log"
330 if [ "x$verbose" = "xtrue" ]; then
331 cat "$ff.compile.log"
332 cat >&2 "$ff.cmp.err"
335 if [ "$ERR" != 0 ]; then
336 test -z
"$tap" && echo -n
"! "
337 cat "$ff.compile.log" "$ff.cmp.err" > "$ff.res"
338 process_result
$bf $bf
339 elif [ -x
"./$ff.bin" ]; then
340 test -z
"$tap" && echo -n
". "
343 if [ "x$verbose" = "xtrue" ]; then
345 echo "NIT_NO_STACK=1 ./$ff.bin" $args
347 NIT_NO_STACK
=1 $TIMEOUT "./$ff.bin" $args < "$inputs" > "$ff.res" 2>"$ff.err"
348 if [ "x$verbose" = "xtrue" ]; then
352 if [ -f
"$ff.write" ]; then
353 cat "$ff.write" >> "$ff.res"
354 elif [ -d
"$ff.write" ]; then
355 LANG
=C
/bin
/ls -F
$ff.
write >> "$ff.res"
357 cp "$ff.res" "$ff.res2"
358 cat "$ff.cmp.err" "$ff.err" "$ff.res2" > "$ff.res"
359 process_result
$bf $bf
361 if [ -f
"$f.args" ]; then
369 name
="$bf args $cptr"
371 # Sould we skip the input for this engine?
372 need_skip
$bff " $name" && continue
374 rm -rf
"$fff.res" "$fff.err" "$fff.write" 2> /dev
/null
375 if [ "x$verbose" = "xtrue" ]; then
377 echo "NIT_NO_STACK=1 ./$ff.bin" $args
379 test -z
"$tap" && echo -n
"==> $name "
380 echo "./$ff.bin $args" > "./$fff.bin"
381 chmod +x
"./$fff.bin"
382 sh
-c
"NIT_NO_STACK=1 $TIMEOUT ./$fff.bin < $inputs > $fff.res 2>$fff.err"
383 if [ "x$verbose" = "xtrue" ]; then
387 if [ -f
"$fff.write" ]; then
388 cat "$fff.write" >> "$fff.res"
389 elif [ -d
"$fff.write" ]; then
390 LANG
=C
/bin
/ls -F
$fff.
write >> "$fff.res"
392 if [ -s
"$fff.err" ]; then
393 cp "$fff.res" "$fff.res2"
394 cat "$fff.err" "$fff.res2" > "$fff.res"
396 process_result
$bff " $name"
400 test -z
"$tap" && echo -n
"! "
401 cat "$ff.cmp.err" > "$ff.res"
402 echo "Compilation error" > "$ff.res"
403 process_result
$bf "$bf"
408 if [ -n
"$tap" ]; then
410 echo "# ok:" `echo $ok | wc -w`
411 echo "# not ok:" `echo $nok | wc -w`
412 echo "# no sav:" `echo $nos | wc -w`
413 echo "# todo/fixme:" `echo $todos | wc -w`
417 echo "ok: " `echo $ok | wc -w` "/" `echo $ok $nok $nos $todos | wc -w`
419 if [ -n
"$nok" ]; then
421 echo "There were $(echo $nok | wc -w) errors ! (see file $ERRLIST)"
423 if [ -n
"$nos" ]; then
426 if [ -n
"$todos" ]; then
427 echo "todo/fixme: $todos"
431 if [ "x$ERRLIST" != "x" ]; then
432 if [ -x
"$ERRLIST_TARGET" ]; then
433 mv "$ERRLIST_TARGET" "${ERRLIST_TARGET}.bak"
435 mv $ERRLIST $ERRLIST_TARGET
438 if [ -n
"$nok" ]; then