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 nitc
29 -v Verbose
(show tests steps
)
34 # As argument: the pattern used for the file
35 function process_result
()
42 if [ -r
"sav/$pattern.sav" ]; then
43 diff -u
"out/$pattern.res" "sav/$pattern.sav" > "out/$pattern.diff.sav.log"
44 if [ "$?" == 0 ]; then
49 sed '/[Ww]arning/d;/[Ee]rror/d' "out/$pattern.res" > "out/$pattern.res2"
50 sed '/[Ww]arning/d;/[Ee]rror/d' "sav/$pattern.sav" > "out/$pattern.sav2"
51 grep '[Ee]rror' "out/$pattern.res" >/dev
/null
&& echo "Error" >> "out/$pattern.res2"
52 grep '[Ee]rror' "sav/$pattern.sav" >/dev
/null
&& echo "Error" >> "out/$pattern.sav2"
53 diff -u
"out/$pattern.res2" "out/$pattern.sav2" > "out/$pattern.diff.sav2.log"
54 if [ "$?" == 0 ]; then
60 if [ -r
"sav/$pattern.fail" ]; then
61 diff -u
"out/$pattern.res" "sav/$pattern.fail" > "out/$pattern.diff.fail.log"
62 if [ "$?" == 0 ]; then
68 if [ "x$SAV" = "xOK" ]; then
69 if [ "x$FAIL" = "x" ]; then
70 echo "[ok] out/$pattern.res"
72 echo "[ok] out/$pattern.res - but sav/$pattern.fail remains!"
75 elif [ "x$FAIL" = "xOK" ]; then
76 echo "[fail] out/$pattern.res"
78 elif [ "x$SOSO" = "xOK" ]; then
79 echo "[soso] out/$pattern.res sav/$pattern.sav"
81 elif [ "x$SAV" = "xNOK" ]; then
82 echo "[======= fail out/$pattern.res sav/$pattern.sav =======]"
84 echo "$ii" >> "$ERRLIST"
85 elif [ "x$FAIL" = "xNOK" ]; then
86 echo "[======= changed out/$pattern.res sav/$pattern.fail ======]"
88 echo "$ii" >> "$ERRLIST"
90 echo "[=== no sav ===] out/$pattern.res"
97 recent
=`ls -t ../src/nitc ../src/nitc_[0-9] ../bin/nitc ../c_src/nitc 2>/dev/null | head -1`
98 if [[ "x$recent" == "x" ]]; then
99 echo 'Could not find nitc, aborting'
102 echo 'Using nitc from: '$recent
111 for alt
in `sed -n "s/.*#!*\($xalt[0-9]*\)#.*/\1/p" "$ii" | sort -u`; do
112 f
=`basename "$ii" .nit`
117 if [ "x$alt" != "x" ]; then
118 test -d alt || mkdir
-p alt
119 i
="alt/${f}_$alt.nit"
121 sed "s/#$alt#//g;/#!$alt#/d" "$ii" > "$i"
132 for xalt
in `sed -n 's/.*#!*\([0-9]*alt\)[0-9]*#.*/\1/p' "$ii" | sort -u`; do
135 fs2
="$fs2 `make_alts0 $f $xalt`"
142 # The default nitc compiler
143 [ -z
"$NITC" ] && find_nitc
145 # Set NIT_DIR if needed
146 [ -z
"$NIT_DIR" ] && export NIT_DIR
=..
150 while [ $stop = false
]; do
152 -o
) OPT
="$OPT $2"; shift; shift;;
153 -v
) verbose
=true
; shift;;
159 # Mark to distinguish files among tests
162 # File where error tests are outputed
163 # Old ERRLIST is backuped
164 ERRLIST
=${ERRLIST:-errlist}
165 ERRLIST_TARGET
=$ERRLIST
172 # Initiate new ERRLIST
173 if [ "x$ERRLIST" = "x" ]; then
183 # CLEAN the out directory
184 rm -rf out
/ 2>/dev
/null
185 mkdir out
2>/dev
/null
188 if [ ! -f
$ii ]; then
189 echo "File '$ii' does not exist."
194 if [ "x$tmp" = "x$ii" ]; then
195 includes
="-I . -I ../lib/standard -I ../lib/standard/collection -I alt"
200 f
=`basename "$ii" .nit`
201 for i
in `make_alts $ii`; do
202 bf
=`basename $i .nit`
207 if [ "x$verbose" = "xtrue" ]; then
209 echo $NITC --no
-color
$OPT -o
"$ff.bin" "$i" "$includes"
211 $NITC --no
-color
$OPT -o
"$ff.bin" "$i" $includes 2> "$ff.cmp.err" > "$ff.compile.log"
213 if [ "x$verbose" = "xtrue" ]; then
214 cat "$ff.compile.log"
215 cat >&2 "$ff.cmp.err"
217 egrep '^[A-Z0-9_]*$' "$ff.compile.log" > "$ff.res"
218 if [ "$ERR" != 0 ]; then
220 cp "$ff.cmp.err" "$ff.res"
222 elif [ -x
"./$ff.bin" ]; then
223 cp "$ff.cmp.err" "$ff.res"
227 if [ "x$verbose" = "xtrue" ]; then
229 echo "NIT_NO_STACK=1 ./$ff.bin" $args
231 if [ -f
"$f.inputs" ]; then
232 NIT_NO_STACK
=1 "./$ff.bin" $args < "$f.inputs" >> "$ff.res" 2>"$ff.err"
234 NIT_NO_STACK
=1 "./$ff.bin" $args >> "$ff.res" 2>"$ff.err"
236 if [ "x$verbose" = "xtrue" ]; then
240 if [ -f
"$ff.write" ]; then
241 cat "$ff.write" >> "$ff.res"
242 elif [ -d
"$ff.write" ]; then
243 LANG
=C
/bin
/ls -F
$ff.
write >> "$ff.res"
245 if [ -s
"$ff.err" ]; then
246 cat "$ff.err" >> "$ff.res"
250 if [ -f
"$f.args" ]; then
258 rm -rf
"$fff.res" "$fff.err" "$fff.write" 2> /dev
/null
259 if [ "x$verbose" = "xtrue" ]; then
261 echo "NIT_NO_STACK=1 ./$ff.bin" $args
263 echo -n
"==> args #"$cptr " "
264 if [ -f
"$f.inputs" ]; then
265 NIT_NO_STACK
=1 "./$ff.bin" $args < "$f.inputs" > "$fff.res" 2>"$fff.err"
267 sh
-c
"NIT_NO_STACK=1 ./$ff.bin ''$args > $fff.res 2>$fff.err"
269 if [ "x$verbose" = "xtrue" ]; then
273 if [ -f
"$fff.write" ]; then
274 cat "$fff.write" >> "$fff.res"
275 elif [ -d
"$fff.write" ]; then
276 LANG
=C
/bin
/ls -F
$fff.
write >> "$fff.res"
278 if [ -s
"$fff.err" ]; then
279 cat "$fff.err" >> "$fff.res"
286 echo "Compilation error" > "$ff.res"
292 echo "ok: " `echo $ok | wc -w` "/" `echo $ok $nok $nos | wc -w`
294 if [ -n
"$nok" ]; then
296 echo "There were $(echo $nok | wc -w) errors ! (see file $ERRLIST)"
298 if [ -n
"$nos" ]; then
303 if [ "x$ERRLIST" != "x" ]; then
304 if [ -x
"$ERRLIST_TARGET" ]; then
305 mv "$ERRLIST_TARGET" "${ERRLIST_TARGET}.bak"
307 mv $ERRLIST $ERRLIST_TARGET
310 if [ -n
"$nok" ]; then