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
()
41 if [ -r
"sav/$pattern.sav" ]; then
42 diff -u
"out/$pattern.res" "sav/$pattern.sav" > "out/$pattern.diff.sav.log"
43 if [ "$?" == 0 ]; then
49 if [ -r
"sav/$pattern.fail" ]; then
50 diff -u
"out/$pattern.res" "sav/$pattern.fail" > "out/$pattern.diff.fail.log"
51 if [ "$?" == 0 ]; then
57 if [ "x$SAV" = "xOK" ]; then
58 if [ "x$FAIL" = "x" ]; then
59 echo "[ok] out/$pattern.res"
61 echo "[ok] out/$pattern.res - but sav/$pattern.fail remains!"
64 elif [ "x$FAIL" = "xOK" ]; then
65 echo "[fail] out/$pattern.res"
67 elif [ "x$SAV" = "xNOK" ]; then
68 echo "[======= fail out/$pattern.res sav/$pattern.sav =======]"
70 echo "$ii" >> "$ERRLIST"
71 elif [ "x$FAIL" = "xNOK" ]; then
72 echo "[======= changed out/$pattern.res sav/$pattern.fail ======]"
74 echo "$ii" >> "$ERRLIST"
76 echo "[=== no sav ===] out/$pattern.res"
83 recent
=`ls -t ../src/nitc ../src/nitc_[0-9] ../bin/nitc ../c_src/nitc 2>/dev/null | head -1`
84 if [[ "x$recent" == "x" ]]; then
85 echo 'Could not find nitc, aborting'
88 echo 'Using nitc from: '$recent
97 for alt
in `sed -n "s/.*#!*\($xalt[0-9]*\)#.*/\1/p" "$ii" | sort -u`; do
98 f
=`basename "$ii" .nit`
103 if [ "x$alt" != "x" ]; then
104 test -d alt || mkdir
-p alt
105 i
="alt/${f}_$alt.nit"
107 sed "s/#$alt#//g;/#!$alt#/d" "$ii" > "$i"
118 for xalt
in `sed -n 's/.*#!*\([0-9]*alt\)[0-9]*#.*/\1/p' "$ii" | sort -u`; do
121 fs2
="$fs2 `make_alts0 $f $xalt`"
128 # The default nitc compiler
129 [ -z
"$NITC" ] && find_nitc
131 # Set NIT_DIR if needed
132 [ -z
"$NIT_DIR" ] && export NIT_DIR
=..
136 while [ $stop = false
]; do
138 -o
) OPT
="$OPT $2"; shift; shift;;
139 -v
) verbose
=true
; shift;;
145 # Mark to distinguish files among tests
148 # File where error tests are outputed
149 # Old ERRLIST is backuped
150 ERRLIST
=${ERRLIST:-errlist}
151 ERRLIST_TARGET
=$ERRLIST
158 # Initiate new ERRLIST
159 if [ "x$ERRLIST" = "x" ]; then
169 # CLEAN the out directory
170 rm -rf out
/ 2>/dev
/null
171 mkdir out
2>/dev
/null
174 if [ ! -f
$ii ]; then
175 echo "File '$ii' does not exist."
180 if [ "x$tmp" = "x$ii" ]; then
181 includes
="-I . -I ../lib/standard -I ../lib/standard/collection -I alt"
186 f
=`basename "$ii" .nit`
187 for i
in `make_alts $ii`; do
188 bf
=`basename $i .nit`
193 if [ "x$verbose" = "xtrue" ]; then
195 echo $NITC --no
-color
$OPT -o
"$ff.bin" "$i" "$includes"
197 $NITC --no
-color
$OPT -o
"$ff.bin" "$i" $includes 2> "$ff.cmp.err" > "$ff.compile.log"
199 if [ "x$verbose" = "xtrue" ]; then
200 cat "$ff.compile.log"
201 cat >&2 "$ff.cmp.err"
203 egrep '^[A-Z0-9_]*$' "$ff.compile.log" > "$ff.res"
204 if [ "$ERR" != 0 ]; then
206 cp "$ff.cmp.err" "$ff.res"
208 elif [ -x
"./$ff.bin" ]; then
209 cp "$ff.cmp.err" "$ff.res"
213 if [ "x$verbose" = "xtrue" ]; then
215 echo "NIT_NO_STACK=1 ./$ff.bin" $args
217 if [ -f
"$f.inputs" ]; then
218 NIT_NO_STACK
=1 "./$ff.bin" $args < "$f.inputs" >> "$ff.res" 2>"$ff.err"
220 NIT_NO_STACK
=1 "./$ff.bin" $args >> "$ff.res" 2>"$ff.err"
222 if [ "x$verbose" = "xtrue" ]; then
226 if [ -f
"$ff.write" ]; then
227 cat "$ff.write" >> "$ff.res"
228 elif [ -d
"$ff.write" ]; then
229 LANG
=C
/bin
/ls -F
$ff.
write >> "$ff.res"
231 if [ -s
"$ff.err" ]; then
232 cat "$ff.err" >> "$ff.res"
236 if [ -f
"$f.args" ]; then
244 rm -rf
"$fff.res" "$fff.err" "$fff.write" 2> /dev
/null
245 if [ "x$verbose" = "xtrue" ]; then
247 echo "NIT_NO_STACK=1 ./$ff.bin" $args
249 echo -n
"==> args #"$cptr " "
250 if [ -f
"$f.inputs" ]; then
251 NIT_NO_STACK
=1 "./$ff.bin" $args < "$f.inputs" > "$fff.res" 2>"$fff.err"
253 sh
-c
"NIT_NO_STACK=1 ./$ff.bin ''$args > $fff.res 2>$fff.err"
255 if [ "x$verbose" = "xtrue" ]; then
259 if [ -f
"$fff.write" ]; then
260 cat "$fff.write" >> "$fff.res"
261 elif [ -d
"$fff.write" ]; then
262 LANG
=C
/bin
/ls -F
$fff.
write >> "$fff.res"
264 if [ -s
"$fff.err" ]; then
265 cat "$fff.err" >> "$fff.res"
272 echo "Compilation error" > "$ff.res"
278 echo "ok: " `echo $ok | wc -w` "/" `echo $ok $nok $nos | wc -w`
280 if [ -n
"$nok" ]; then
282 echo "There were $(echo $nok | wc -w) errors ! (see file $ERRLIST)"
284 if [ -n
"$nos" ]; then
289 if [ "x$ERRLIST" != "x" ]; then
290 if [ -x
"$ERRLIST_TARGET" ]; then
291 mv "$ERRLIST_TARGET" "${ERRLIST_TARGET}.bak"
293 mv $ERRLIST $ERRLIST_TARGET
296 if [ -n
"$nok" ]; then