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 # As argument: the pattern used for the file
39 function process_result
()
41 ((tapcount
=tapcount
+1))
53 for sav
in "sav/$engine/$pattern.res" "sav/$pattern.res" "sav/$pattern.sav"; do
54 if [ -r
"$sav" ]; then
55 diff -u
"out/$pattern.res" "$sav" > "out/$pattern.diff.sav.log"
56 if [ "$?" == 0 ]; then
61 [ -z
"$soso" ] && continue
62 sed '/[Ww]arning/d;/[Ee]rror/d' "out/$pattern.res" > "out/$pattern.res2"
63 sed '/[Ww]arning/d;/[Ee]rror/d' "$sav" > "out/$pattern.sav2"
64 grep '[Ee]rror' "out/$pattern.res" >/dev
/null
&& echo "Error" >> "out/$pattern.res2"
65 grep '[Ee]rror' "$sav" >/dev
/null
&& echo "Error" >> "out/$pattern.sav2"
66 diff -u
"out/$pattern.res2" "out/$pattern.sav2" > "out/$pattern.diff.sav2.log"
67 if [ "$?" == 0 ]; then
74 for sav
in "sav/$engine/fixme/$pattern.res" "sav/fixme/$pattern.res" "sav/$pattern.fail"; do
75 if [ -r
"$sav" ]; then
76 diff -u
"out/$pattern.res" "$sav" > "out/$pattern.diff.fail.log"
77 if [ "$?" == 0 ]; then
82 [ -z
"$soso" ] && continue
83 sed '/[Ww]arning/d;/[Ee]rror/d' "out/$pattern.res" > "out/$pattern.res2"
84 sed '/[Ww]arning/d;/[Ee]rror/d' "$sav" > "out/$pattern.fail2"
85 grep '[Ee]rror' "out/$pattern.res" >/dev
/null
&& echo "Error" >> "out/$pattern.res2"
86 grep '[Ee]rror' "$sav" >/dev
/null
&& echo "Error" >> "out/$pattern.fail2"
87 diff -u
"out/$pattern.res2" "out/$pattern.fail2" > "out/$pattern.diff.fail2.log"
88 if [ "$?" == 0 ]; then
95 grep 'NOT YET IMPLEMENTED' "out/$pattern.res" >/dev
/null
97 if [ -n
"$SAV" ]; then
98 if [ -n
"$tap" ]; then
99 echo "ok - $description"
100 elif [ -z
"$FAIL" ]; then
101 echo "[ok] out/$pattern.res $SAV"
103 echo "[ok] out/$pattern.res $SAV - but $FAIL remains!"
106 elif [ -n
"$FAIL" ]; then
107 if [ -n
"$tap" ]; then
108 echo "not ok - $description # TODO expected failure"
110 echo "[fail] out/$pattern.res $FAIL"
113 elif [ -n
"$SOSO" ]; then
114 if [ -n
"$tap" ]; then
115 echo "ok - $description # SOSO"
117 echo "[soso] out/$pattern.res $SOSO"
120 elif [ "x$NYI" = "x0" ]; then
121 if [ -n
"$tap" ]; then
122 echo "not ok - $description # TODO not yet implemented"
124 echo "[todo] out/$pattern.res -> not yet implemented"
126 todos
="$todos $pattern"
127 elif [ -n
"$SOSOF" ]; then
128 if [ -n
"$tap" ]; then
129 echo "not ok - $description # TODO SOSO expected failure"
131 echo "[fail soso] out/$pattern.res $SOSOF"
134 elif [ -n
"$NSAV" ]; then
135 if [ -n
"$tap" ]; then
136 echo "not ok - $description"
138 echo "[======= fail out/$pattern.res $NSAV =======]"
141 echo "$ii" >> "$ERRLIST"
142 elif [ -n
"$NFAIL" ]; then
143 if [ -n
"$tap" ]; then
144 echo "not ok - $description"
146 echo "[======= changed out/$pattern.res $NFAIL ======]"
149 echo "$ii" >> "$ERRLIST"
151 if [ -n
"$tap" ]; then
152 echo "ok - $description # skip no sav"
154 echo "[=== no sav ===] out/$pattern.res"
162 test "$noskip" = true
&& return 1
163 if grep "$engine" "sav/$1.skip" >/dev
/null
2>&1 ||
echo "$1" |
grep -f
"$engine.skip" >/dev
/null
2>&1; then
164 ((tapcount
=tapcount
+1))
165 if [ -n
"$tap" ]; then
166 echo "ok - $2 # skip"
177 ((tapcount
=tapcount
+1))
178 name
="$enginebinname"
179 recent
=`ls -t ../src/$name ../src/$name_[0-9] ../bin/$name ../c_src/$name 2>/dev/null | head -1`
180 if [[ "x$recent" == "x" ]]; then
181 if [ -n
"$tap" ]; then
182 echo "not ok - find engine $name"
183 echo "Bail out! Could not find engine $name, aborting"
185 echo "Could not find engine $name, aborting"
189 if [ -n
"$tap" ]; then
190 echo "ok - find engine $name: $recent"
192 echo "Using engine $name from: $recent"
202 while [ $stop = false
]; do
204 -o
) OPT
="$OPT $2"; shift; shift;;
205 -v
) verbose
=true
; shift;;
207 --tap
) tap
=true
; shift;;
208 --engine
) engine
="$2"; shift; shift;;
209 --noskip
) noskip
=true
; shift;;
210 --soso
) soso
=true
; shift;;
211 --nososo
) nososo
=true
; shift;;
215 enginebinname
=$engine
220 niti
) enginebinname
=nit
;;
223 # The default nitc compiler
224 [ -z
"$NITC" ] && find_nitc
226 # Set NIT_DIR if needed
227 [ -z
"$NIT_DIR" ] && export NIT_DIR
=..
230 # Mark to distinguish files among tests
233 # File where error tests are outputed
234 # Old ERRLIST is backuped
235 ERRLIST
=${ERRLIST:-errlist}
236 ERRLIST_TARGET
=$ERRLIST
243 # Initiate new ERRLIST
244 if [ "x$ERRLIST" = "x" ]; then
255 # CLEAN the out directory
256 rm -rf out
/ 2>/dev
/null
257 mkdir out
2>/dev
/null
260 if [ ! -f
$ii ]; then
261 echo "File '$ii' does not exist."
264 f
=`basename "$ii" .nit`
266 # Sould we skip the file for this engine?
267 need_skip
$f $f && continue
270 if [ "x$tmp" = "x$ii" ]; then
271 includes
="-I . -I ../lib/standard -I ../lib/standard/collection -I alt"
276 for i
in "$ii" `./alterner.pl --start '#' --altsep '_' $ii`; do
277 bf
=`basename $i .nit`
280 # Sould we skip the alternative for this engine?
281 need_skip
$bf $bf && continue
283 test -z
"$tap" && echo -n
"=> $bf: "
285 if [ -f
"$f.inputs" ]; then
291 if [ "$engine" = "niti" ]; then
292 cat > "./$ff.bin" <<END
293 exec $NITC --no
-color
$OPT "$i" $includes -- "\$@"
301 if [ "x$verbose" = "xtrue" ]; then
303 echo $NITC --no
-color
$OPT -o
"$ff.bin" "$i" "$includes"
305 NIT_NO_STACK
=1 $NITC --no
-color
$OPT -o
"$ff.bin" "$i" $includes 2> "$ff.cmp.err" > "$ff.compile.log"
307 if [ "x$verbose" = "xtrue" ]; then
308 cat "$ff.compile.log"
309 cat >&2 "$ff.cmp.err"
312 if [ "$ERR" != 0 ]; then
313 test -z
"$tap" && echo -n
"! "
314 cat "$ff.compile.log" "$ff.cmp.err" > "$ff.res"
315 process_result
$bf $bf
316 elif [ -x
"./$ff.bin" ]; then
317 cp "$ff.cmp.err" "$ff.res"
318 test -z
"$tap" && echo -n
". "
321 if [ "x$verbose" = "xtrue" ]; then
323 echo "NIT_NO_STACK=1 ./$ff.bin" $args
325 NIT_NO_STACK
=1 "./$ff.bin" $args < "$inputs" >> "$ff.res" 2>"$ff.err"
326 if [ "x$verbose" = "xtrue" ]; then
330 if [ -f
"$ff.write" ]; then
331 cat "$ff.write" >> "$ff.res"
332 elif [ -d
"$ff.write" ]; then
333 LANG
=C
/bin
/ls -F
$ff.
write >> "$ff.res"
335 if [ -s
"$ff.err" ]; then
336 cat "$ff.err" >> "$ff.res"
338 process_result
$bf $bf
340 if [ -f
"$f.args" ]; then
349 # Sould we skip the input for this engine?
350 need_skip
$bff " args #$cptr" && continue
352 rm -rf
"$fff.res" "$fff.err" "$fff.write" 2> /dev
/null
353 if [ "x$verbose" = "xtrue" ]; then
355 echo "NIT_NO_STACK=1 ./$ff.bin" $args
357 test -z
"$tap" && echo -n
"==> args #"$cptr " "
358 sh
-c
"NIT_NO_STACK=1 ./$ff.bin ''$args < $inputs > $fff.res 2>$fff.err"
359 if [ "x$verbose" = "xtrue" ]; then
363 if [ -f
"$fff.write" ]; then
364 cat "$fff.write" >> "$fff.res"
365 elif [ -d
"$fff.write" ]; then
366 LANG
=C
/bin
/ls -F
$fff.
write >> "$fff.res"
368 if [ -s
"$fff.err" ]; then
369 cat "$fff.err" >> "$fff.res"
371 process_result
$bff " args #$cptr"
375 test -z
"$tap" && echo -n
"! "
376 cat "$ff.cmp.err" > "$ff.res"
377 echo "Compilation error" > "$ff.res"
378 process_result
$bf "$bf"
383 if [ -n
"$tap" ]; then
385 echo "# ok:" `echo $ok | wc -w`
386 echo "# not ok:" `echo $nok | wc -w`
387 echo "# no sav:" `echo $nos | wc -w`
388 echo "# todos:" `echo $todos | wc -w`
392 echo "ok: " `echo $ok | wc -w` "/" `echo $ok $nok $nos $todos | wc -w`
394 if [ -n
"$nok" ]; then
396 echo "There were $(echo $nok | wc -w) errors ! (see file $ERRLIST)"
398 if [ -n
"$nos" ]; then
401 if [ -n
"$todos" ]; then
406 if [ "x$ERRLIST" != "x" ]; then
407 if [ -x
"$ERRLIST_TARGET" ]; then
408 mv "$ERRLIST_TARGET" "${ERRLIST_TARGET}.bak"
410 mv $ERRLIST $ERRLIST_TARGET
413 if [ -n
"$nok" ]; then