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
27 Usage
: $e [options
] modulenames
28 -o option Pass option to the engine
29 -v Verbose
(show tests steps
)
31 --tap Produce TAP output
32 --engine Use a specific engine
(default
=nitc
)
33 --noskip Do not skip a
test even
if the .skip
file matches
34 --[no
]soso Force
enable (or disable
) SOSO
38 # $1 is the pattern of the test
39 # $2 is the file to compare to
41 # 0: if the file to compare to do not exists
42 # 1: if the file match
43 # 2: if the file match with soso
44 # 3: if the file do not match
45 function compare_to_result
()
49 if [ ! -r
"$sav" ]; then return 0; fi
50 diff -u
"out/$pattern.res" "$sav" > "out/$pattern.diff.sav.log"
51 if [ "$?" == 0 ]; then
54 [ -z
"$soso" ] && return 3
55 sed '/[Ww]arning/d;/[Ee]rror/d' "out/$pattern.res" > "out/$pattern.res2"
56 sed '/[Ww]arning/d;/[Ee]rror/d' "$sav" > "out/$pattern.sav2"
57 grep '[Ee]rror' "out/$pattern.res" >/dev
/null
&& echo "Error" >> "out/$pattern.res2"
58 grep '[Ee]rror' "$sav" >/dev
/null
&& echo "Error" >> "out/$pattern.sav2"
59 diff -u
"out/$pattern.res2" "out/$pattern.sav2" > "out/$pattern.diff.sav2.log"
60 if [ "$?" == 0 ]; then
67 # As argument: the pattern used for the file
68 function process_result
()
70 ((tapcount
=tapcount
+1))
82 for sav
in "sav/$engine/$pattern.res" "sav/$pattern.res" "sav/$pattern.sav"; do
83 compare_to_result
"$pattern" "$sav"
95 for sav
in "sav/$engine/fixme/$pattern.res" "sav/fixme/$pattern.res" "sav/$pattern.fail"; do
96 compare_to_result
"$pattern" "$sav"
108 grep 'NOT YET IMPLEMENTED' "out/$pattern.res" >/dev
/null
110 if [ -n
"$SAV" ]; then
111 if [ -n
"$tap" ]; then
112 echo "ok - $description"
113 elif [ -z
"$FIXME" ]; then
114 echo "[ok] out/$pattern.res $SAV"
116 echo "[ok] out/$pattern.res $SAV - but $FIXME remains!"
119 elif [ -n
"$FIXME" ]; then
120 if [ -n
"$tap" ]; then
121 echo "not ok - $description # TODO expected failure"
123 echo "[fixme] out/$pattern.res $FIXME"
125 todos
="$todos $pattern"
126 elif [ -n
"$SOSO" ]; then
127 if [ -n
"$tap" ]; then
128 echo "ok - $description # SOSO"
130 echo "[soso] out/$pattern.res $SOSO"
133 elif [ "x$NYI" = "x0" ]; then
134 if [ -n
"$tap" ]; then
135 echo "not ok - $description # TODO not yet implemented"
137 echo "[todo] out/$pattern.res -> not yet implemented"
139 todos
="$todos $pattern"
140 elif [ -n
"$SOSOF" ]; then
141 if [ -n
"$tap" ]; then
142 echo "not ok - $description # TODO SOSO expected failure"
144 echo "[fixme soso] out/$pattern.res $SOSOF"
146 todos
="$todos $pattern"
147 elif [ -n
"$NSAV" ]; then
148 if [ -n
"$tap" ]; then
149 echo "not ok - $description"
151 echo "[======= fail out/$pattern.res $NSAV =======]"
154 echo "$ii" >> "$ERRLIST"
155 elif [ -n
"$NFIXME" ]; then
156 if [ -n
"$tap" ]; then
157 echo "not ok - $description"
159 echo "[======= changed out/$pattern.res $NFIXME ======]"
162 echo "$ii" >> "$ERRLIST"
164 if [ -n
"$tap" ]; then
165 echo "ok - $description # skip no sav"
167 echo "[=== no sav ===] out/$pattern.res"
175 test "$noskip" = true
&& return 1
176 if echo "$1" |
grep -f
"$engine.skip" >/dev
/null
2>&1; then
177 ((tapcount
=tapcount
+1))
178 if [ -n
"$tap" ]; then
179 echo "ok - $2 # skip"
190 ((tapcount
=tapcount
+1))
191 name
="$enginebinname"
192 recent
=`ls -t ../src/$name ../src/$name_[0-9] ../bin/$name ../c_src/$name 2>/dev/null | head -1`
193 if [[ "x$recent" == "x" ]]; then
194 if [ -n
"$tap" ]; then
195 echo "not ok - find engine $name"
196 echo "Bail out! Could not find engine $name, aborting"
198 echo "Could not find engine $name, aborting"
202 if [ -n
"$tap" ]; then
203 echo "ok - find engine $name: $recent"
205 echo "Using engine $name from: $recent"
215 while [ $stop = false
]; do
217 -o
) OPT
="$OPT $2"; shift; shift;;
218 -v
) verbose
=true
; shift;;
220 --tap
) tap
=true
; shift;;
221 --engine
) engine
="$2"; shift; shift;;
222 --noskip
) noskip
=true
; shift;;
223 --soso
) soso
=true
; shift;;
224 --nososo
) nososo
=true
; shift;;
228 enginebinname
=$engine
233 niti
) enginebinname
=nit
;;
236 # The default nitc compiler
237 [ -z
"$NITC" ] && find_nitc
239 # Set NIT_DIR if needed
240 [ -z
"$NIT_DIR" ] && export NIT_DIR
=..
243 # Mark to distinguish files among tests
246 # File where error tests are outputed
247 # Old ERRLIST is backuped
248 ERRLIST
=${ERRLIST:-errlist}
249 ERRLIST_TARGET
=$ERRLIST
256 # Initiate new ERRLIST
257 if [ "x$ERRLIST" = "x" ]; then
268 # CLEAN the out directory
269 rm -rf out
/ 2>/dev
/null
270 mkdir out
2>/dev
/null
273 if [ ! -f
$ii ]; then
274 echo "File '$ii' does not exist."
277 f
=`basename "$ii" .nit`
279 # Sould we skip the file for this engine?
280 need_skip
$f $f && continue
283 if [ "x$tmp" = "x$ii" ]; then
284 includes
="-I . -I ../lib/standard -I ../lib/standard/collection -I alt"
289 for i
in "$ii" `./alterner.pl --start '#' --altsep '_' $ii`; do
290 bf
=`basename $i .nit`
293 # Sould we skip the alternative for this engine?
294 need_skip
$bf $bf && continue
296 test -z
"$tap" && echo -n
"=> $bf: "
298 if [ -f
"$f.inputs" ]; then
304 if [ "$engine" = "niti" ]; then
305 cat > "./$ff.bin" <<END
306 exec $NITC --no
-color
$OPT "$i" $includes -- "\$@"
314 if [ "x$verbose" = "xtrue" ]; then
316 echo $NITC --no
-color
$OPT -o
"$ff.bin" "$i" "$includes"
318 NIT_NO_STACK
=1 $NITC --no
-color
$OPT -o
"$ff.bin" "$i" $includes 2> "$ff.cmp.err" > "$ff.compile.log"
320 if [ "x$verbose" = "xtrue" ]; then
321 cat "$ff.compile.log"
322 cat >&2 "$ff.cmp.err"
325 if [ "$ERR" != 0 ]; then
326 test -z
"$tap" && echo -n
"! "
327 cat "$ff.compile.log" "$ff.cmp.err" > "$ff.res"
328 process_result
$bf $bf
329 elif [ -x
"./$ff.bin" ]; then
330 cp "$ff.cmp.err" "$ff.res"
331 test -z
"$tap" && echo -n
". "
334 if [ "x$verbose" = "xtrue" ]; then
336 echo "NIT_NO_STACK=1 ./$ff.bin" $args
338 NIT_NO_STACK
=1 "./$ff.bin" $args < "$inputs" >> "$ff.res" 2>"$ff.err"
339 if [ "x$verbose" = "xtrue" ]; then
343 if [ -f
"$ff.write" ]; then
344 cat "$ff.write" >> "$ff.res"
345 elif [ -d
"$ff.write" ]; then
346 LANG
=C
/bin
/ls -F
$ff.
write >> "$ff.res"
348 if [ -s
"$ff.err" ]; then
349 cat "$ff.err" >> "$ff.res"
351 process_result
$bf $bf
353 if [ -f
"$f.args" ]; then
362 # Sould we skip the input for this engine?
363 need_skip
$bff " args #$cptr" && continue
365 rm -rf
"$fff.res" "$fff.err" "$fff.write" 2> /dev
/null
366 if [ "x$verbose" = "xtrue" ]; then
368 echo "NIT_NO_STACK=1 ./$ff.bin" $args
370 test -z
"$tap" && echo -n
"==> args #"$cptr " "
371 sh
-c
"NIT_NO_STACK=1 ./$ff.bin ''$args < $inputs > $fff.res 2>$fff.err"
372 if [ "x$verbose" = "xtrue" ]; then
376 if [ -f
"$fff.write" ]; then
377 cat "$fff.write" >> "$fff.res"
378 elif [ -d
"$fff.write" ]; then
379 LANG
=C
/bin
/ls -F
$fff.
write >> "$fff.res"
381 if [ -s
"$fff.err" ]; then
382 cat "$fff.err" >> "$fff.res"
384 process_result
$bff " args #$cptr"
388 test -z
"$tap" && echo -n
"! "
389 cat "$ff.cmp.err" > "$ff.res"
390 echo "Compilation error" > "$ff.res"
391 process_result
$bf "$bf"
396 if [ -n
"$tap" ]; then
398 echo "# ok:" `echo $ok | wc -w`
399 echo "# not ok:" `echo $nok | wc -w`
400 echo "# no sav:" `echo $nos | wc -w`
401 echo "# todo/fixme:" `echo $todos | wc -w`
405 echo "ok: " `echo $ok | wc -w` "/" `echo $ok $nok $nos $todos | wc -w`
407 if [ -n
"$nok" ]; then
409 echo "There were $(echo $nok | wc -w) errors ! (see file $ERRLIST)"
411 if [ -n
"$nos" ]; then
414 if [ -n
"$todos" ]; then
415 echo "todo/fixme: $todos"
419 if [ "x$ERRLIST" != "x" ]; then
420 if [ -x
"$ERRLIST_TARGET" ]; then
421 mv "$ERRLIST_TARGET" "${ERRLIST_TARGET}.bak"
423 mv $ERRLIST $ERRLIST_TARGET
426 if [ -n
"$nok" ]; then