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"
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
218 nitg
) [ -z
"$nososo" ] && soso
=true
;;
219 nit
) [ -z
"$nososo" ] && soso
=true
221 niti
) [ -z
"$nososo" ] && soso
=true
225 # The default nitc compiler
226 [ -z
"$NITC" ] && find_nitc
228 # Set NIT_DIR if needed
229 [ -z
"$NIT_DIR" ] && export NIT_DIR
=..
232 # Mark to distinguish files among tests
235 # File where error tests are outputed
236 # Old ERRLIST is backuped
237 ERRLIST
=${ERRLIST:-errlist}
238 ERRLIST_TARGET
=$ERRLIST
245 # Initiate new ERRLIST
246 if [ "x$ERRLIST" = "x" ]; then
256 # CLEAN the out directory
257 rm -rf out
/ 2>/dev
/null
258 mkdir out
2>/dev
/null
261 if [ ! -f
$ii ]; then
262 echo "File '$ii' does not exist."
265 f
=`basename "$ii" .nit`
267 # Sould we skip the file for this engine?
268 need_skip
$f $f && continue
271 if [ "x$tmp" = "x$ii" ]; then
272 includes
="-I . -I ../lib/standard -I ../lib/standard/collection -I alt"
277 for i
in "$ii" `./alterner.pl --start '#' --altsep '_' $ii`; do
278 bf
=`basename $i .nit`
281 # Sould we skip the alternative for this engine?
282 need_skip
$bf $bf && continue
284 test -z
"$tap" && echo -n
"=> $bf: "
286 if [ -f
"$f.inputs" ]; then
292 if [ "$engine" = "niti" ]; then
293 cat > "./$ff.bin" <<END
294 exec $NITC --no
-color
$OPT "$i" $includes -- "\$@"
302 if [ "x$verbose" = "xtrue" ]; then
304 echo $NITC --no
-color
$OPT -o
"$ff.bin" "$i" "$includes"
306 $NITC --no
-color
$OPT -o
"$ff.bin" "$i" $includes 2> "$ff.cmp.err" > "$ff.compile.log"
308 if [ "x$verbose" = "xtrue" ]; then
309 cat "$ff.compile.log"
310 cat >&2 "$ff.cmp.err"
313 if [ "$ERR" != 0 ]; then
314 test -z
"$tap" && echo -n
"! "
315 cat "$ff.cmp.err" "$ff.compile.log" > "$ff.res"
316 process_result
$bf $bf
317 elif [ -x
"./$ff.bin" ]; then
318 cp "$ff.cmp.err" "$ff.res"
319 test -z
"$tap" && echo -n
". "
322 if [ "x$verbose" = "xtrue" ]; then
324 echo "NIT_NO_STACK=1 ./$ff.bin" $args
326 NIT_NO_STACK
=1 "./$ff.bin" $args < "$inputs" >> "$ff.res" 2>"$ff.err"
327 if [ "x$verbose" = "xtrue" ]; then
331 if [ -f
"$ff.write" ]; then
332 cat "$ff.write" >> "$ff.res"
333 elif [ -d
"$ff.write" ]; then
334 LANG
=C
/bin
/ls -F
$ff.
write >> "$ff.res"
336 if [ -s
"$ff.err" ]; then
337 cat "$ff.err" >> "$ff.res"
339 process_result
$bf $bf
341 if [ -f
"$f.args" ]; then
350 # Sould we skip the input for this engine?
351 need_skip
$bff " args #$cptr" && continue
353 rm -rf
"$fff.res" "$fff.err" "$fff.write" 2> /dev
/null
354 if [ "x$verbose" = "xtrue" ]; then
356 echo "NIT_NO_STACK=1 ./$ff.bin" $args
358 test -z
"$tap" && echo -n
"==> args #"$cptr " "
359 sh
-c
"NIT_NO_STACK=1 ./$ff.bin ''$args < $inputs > $fff.res 2>$fff.err"
360 if [ "x$verbose" = "xtrue" ]; then
364 if [ -f
"$fff.write" ]; then
365 cat "$fff.write" >> "$fff.res"
366 elif [ -d
"$fff.write" ]; then
367 LANG
=C
/bin
/ls -F
$fff.
write >> "$fff.res"
369 if [ -s
"$fff.err" ]; then
370 cat "$fff.err" >> "$fff.res"
372 process_result
$bff " args #$cptr"
376 test -z
"$tap" && echo -n
"! "
377 cat "$ff.cmp.err" > "$ff.res"
378 echo "Compilation error" > "$ff.res"
379 process_result
$bf "$bf"
384 if [ -n
"$tap" ]; then
386 echo "# ok:" `echo $ok | wc -w`
387 echo "# not ok:" `echo $nok | wc -w`
388 echo "# no sav:" `echo $nos | wc -w`
392 echo "ok: " `echo $ok | wc -w` "/" `echo $ok $nok $nos | wc -w`
394 if [ -n
"$nok" ]; then
396 echo "There were $(echo $nok | wc -w) errors ! (see file $ERRLIST)"
398 if [ -n
"$nos" ]; then
403 if [ "x$ERRLIST" != "x" ]; then
404 if [ -x
"$ERRLIST_TARGET" ]; then
405 mv "$ERRLIST_TARGET" "${ERRLIST_TARGET}.bak"
407 mv $ERRLIST $ERRLIST_TARGET
410 if [ -n
"$nok" ]; then