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
()
43 if [ -r
"sav/$pattern.sav" ]; then
44 diff -u
"out/$pattern.res" "sav/$pattern.sav" > "out/$pattern.diff.sav.log"
45 if [ "$?" == 0 ]; then
50 sed '/[Ww]arning/d;/[Ee]rror/d' "out/$pattern.res" > "out/$pattern.res2"
51 sed '/[Ww]arning/d;/[Ee]rror/d' "sav/$pattern.sav" > "out/$pattern.sav2"
52 grep '[Ee]rror' "out/$pattern.res" >/dev
/null
&& echo "Error" >> "out/$pattern.res2"
53 grep '[Ee]rror' "sav/$pattern.sav" >/dev
/null
&& echo "Error" >> "out/$pattern.sav2"
54 diff -u
"out/$pattern.res2" "out/$pattern.sav2" > "out/$pattern.diff.sav2.log"
55 if [ "$?" == 0 ]; then
61 if [ -r
"sav/$pattern.fail" ]; then
62 diff -u
"out/$pattern.res" "sav/$pattern.fail" > "out/$pattern.diff.fail.log"
63 if [ "$?" == 0 ]; then
68 sed '/[Ww]arning/d;/[Ee]rror/d' "out/$pattern.res" > "out/$pattern.res2"
69 sed '/[Ww]arning/d;/[Ee]rror/d' "sav/$pattern.fail" > "out/$pattern.fail2"
70 grep '[Ee]rror' "out/$pattern.res" >/dev
/null
&& echo "Error" >> "out/$pattern.res2"
71 grep '[Ee]rror' "sav/$pattern.fail" >/dev
/null
&& echo "Error" >> "out/$pattern.fail2"
72 diff -u
"out/$pattern.res2" "out/$pattern.fail2" > "out/$pattern.diff.fail2.log"
73 if [ "$?" == 0 ]; then
79 if [ "x$SAV" = "xOK" ]; then
80 if [ "x$FAIL" = "x" ]; then
81 echo "[ok] out/$pattern.res"
83 echo "[ok] out/$pattern.res - but sav/$pattern.fail remains!"
86 elif [ "x$FAIL" = "xOK" ]; then
87 echo "[fail] out/$pattern.res"
89 elif [ "x$SOSO" = "xOK" ]; then
90 echo "[soso] out/$pattern.res sav/$pattern.sav"
92 elif [ "x$SOSOF" = "xOK" ]; then
93 echo "[fail soso] out/$pattern.res sav/$pattern.fail"
95 elif [ "x$SAV" = "xNOK" ]; then
96 echo "[======= fail out/$pattern.res sav/$pattern.sav =======]"
98 echo "$ii" >> "$ERRLIST"
99 elif [ "x$FAIL" = "xNOK" ]; then
100 echo "[======= changed out/$pattern.res sav/$pattern.fail ======]"
102 echo "$ii" >> "$ERRLIST"
104 echo "[=== no sav ===] out/$pattern.res"
111 recent
=`ls -t ../src/nitc ../src/nitc_[0-9] ../bin/nitc ../c_src/nitc 2>/dev/null | head -1`
112 if [[ "x$recent" == "x" ]]; then
113 echo 'Could not find nitc, aborting'
116 echo 'Using nitc from: '$recent
120 # The default nitc compiler
121 [ -z
"$NITC" ] && find_nitc
123 # Set NIT_DIR if needed
124 [ -z
"$NIT_DIR" ] && export NIT_DIR
=..
128 while [ $stop = false
]; do
130 -o
) OPT
="$OPT $2"; shift; shift;;
131 -v
) verbose
=true
; shift;;
137 # Mark to distinguish files among tests
140 # File where error tests are outputed
141 # Old ERRLIST is backuped
142 ERRLIST
=${ERRLIST:-errlist}
143 ERRLIST_TARGET
=$ERRLIST
150 # Initiate new ERRLIST
151 if [ "x$ERRLIST" = "x" ]; then
161 # CLEAN the out directory
162 rm -rf out
/ 2>/dev
/null
163 mkdir out
2>/dev
/null
166 if [ ! -f
$ii ]; then
167 echo "File '$ii' does not exist."
172 if [ "x$tmp" = "x$ii" ]; then
173 includes
="-I . -I ../lib/standard -I ../lib/standard/collection -I alt"
178 f
=`basename "$ii" .nit`
179 for i
in "$ii" `./alterner.pl --start '#' --altsep '_' $ii`; do
180 bf
=`basename $i .nit`
184 if [ -f
"$f.inputs" ]; then
191 if [ "x$verbose" = "xtrue" ]; then
193 echo $NITC --no
-color
$OPT -o
"$ff.bin" "$i" "$includes"
195 $NITC --no
-color
$OPT -o
"$ff.bin" "$i" $includes <"$inputs" 2> "$ff.cmp.err" > "$ff.compile.log"
197 if [ "x$verbose" = "xtrue" ]; then
198 cat "$ff.compile.log"
199 cat >&2 "$ff.cmp.err"
201 egrep '^[A-Z0-9_]*$' "$ff.compile.log" > "$ff.res"
202 if [ "$ERR" != 0 ]; then
204 cat "$ff.cmp.err" "$ff.compile.log" > "$ff.res"
206 elif [ -x
"./$ff.bin" ]; then
207 cp "$ff.cmp.err" "$ff.res"
211 if [ "x$verbose" = "xtrue" ]; then
213 echo "NIT_NO_STACK=1 ./$ff.bin" $args
215 NIT_NO_STACK
=1 "./$ff.bin" $args < "$inputs" >> "$ff.res" 2>"$ff.err"
216 if [ "x$verbose" = "xtrue" ]; then
220 if [ -f
"$ff.write" ]; then
221 cat "$ff.write" >> "$ff.res"
222 elif [ -d
"$ff.write" ]; then
223 LANG
=C
/bin
/ls -F
$ff.
write >> "$ff.res"
225 if [ -s
"$ff.err" ]; then
226 cat "$ff.err" >> "$ff.res"
230 if [ -f
"$f.args" ]; then
238 rm -rf
"$fff.res" "$fff.err" "$fff.write" 2> /dev
/null
239 if [ "x$verbose" = "xtrue" ]; then
241 echo "NIT_NO_STACK=1 ./$ff.bin" $args
243 echo -n
"==> args #"$cptr " "
244 sh
-c
"NIT_NO_STACK=1 ./$ff.bin ''$args < $inputs > $fff.res 2>$fff.err"
245 if [ "x$verbose" = "xtrue" ]; then
249 if [ -f
"$fff.write" ]; then
250 cat "$fff.write" >> "$fff.res"
251 elif [ -d
"$fff.write" ]; then
252 LANG
=C
/bin
/ls -F
$fff.
write >> "$fff.res"
254 if [ -s
"$fff.err" ]; then
255 cat "$fff.err" >> "$fff.res"
262 cat "$ff.cmp.err" "$ff.compile.log" > "$ff.res"
263 #echo "Compilation error" > "$ff.res"
269 echo "ok: " `echo $ok | wc -w` "/" `echo $ok $nok $nos | wc -w`
271 if [ -n
"$nok" ]; then
273 echo "There were $(echo $nok | wc -w) errors ! (see file $ERRLIST)"
275 if [ -n
"$nos" ]; then
280 if [ "x$ERRLIST" != "x" ]; then
281 if [ -x
"$ERRLIST_TARGET" ]; then
282 mv "$ERRLIST_TARGET" "${ERRLIST_TARGET}.bak"
284 mv $ERRLIST $ERRLIST_TARGET
287 if [ -n
"$nok" ]; then