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
"$pattern.res" "sav/$pattern.sav" > "$pattern.diff.sav.log"
43 if [ "$?" == 0 ]; then
49 if [ -r
"sav/$pattern.fail" ]; then
50 diff -u
"$pattern.res" "sav/$pattern.fail" > "$pattern.diff.fail.log"
51 if [ "$?" == 0 ]; then
57 if [ "x$SAV" = "xOK" ]; then
58 if [ "x$FAIL" = "x" ]; then
59 echo "[ok] $pattern.res"
61 echo "[ok] $pattern.res - but sav/$pattern.fail remains!"
64 elif [ "x$FAIL" = "xOK" ]; then
65 echo "[fail] $pattern.res"
67 elif [ "x$SAV" = "xNOK" ]; then
68 echo "[======= fail $pattern.res sav/$pattern.sav =======]"
70 echo "$ii" >> "$ERRLIST"
71 elif [ "x$FAIL" = "xNOK" ]; then
72 echo "[======= changed $pattern.res sav/$pattern.fail ======]"
74 echo "$ii" >> "$ERRLIST"
76 echo "[=== no sav ===] $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
133 while [ $stop = false
]; do
135 -o
) OPT
="$OPT $2"; shift; shift;;
136 -v
) verbose
=true
; shift;;
142 # Mark to distinguish files among tests
145 # File where error tests are outputed
146 # Old ERRLIST is backuped
147 ERRLIST
=${ERRLIST:-errlist}
148 ERRLIST_TARGET
=$ERRLIST
155 # Initiate new ERRLIST
156 if [ "x$ERRLIST" = "x" ]; then
168 if [ ! -f
$ii ]; then
169 echo "File '$ii' does not exist."
174 if [ "x$tmp" = "x$ii" ]; then
175 includes
="-I . -I ../lib/standard -I ../lib/standard/collection -I alt"
180 f
=`basename "$ii" .nit`
181 for i
in `make_alts $ii`; do
182 ff
=`basename $i .nit`
185 rm -rf
"$ff.res" "$ff.err" "$ff.write" "$ff.bin" 2> /dev
/null
188 if [ "x$verbose" = "xtrue" ]; then
190 echo $NITC --no
-color
$OPT -o
"$ff.bin" "$i" "$includes"
192 $NITC --no
-color
$OPT -o
"$ff.bin" "$i" $includes 2> "$ff.cmp.err" > "$ff.compile.log"
194 if [ "x$verbose" = "xtrue" ]; then
195 cat "$ff.compile.log"
196 cat >&2 "$ff.cmp.err"
198 egrep '^[A-Z0-9_]*$' "$ff.compile.log" > "$ff.res"
199 if [ "$ERR" != 0 ]; then
201 cp "$ff.cmp.err" "$ff.res"
203 elif [ -x
"./$ff.bin" ]; then
207 if [ "x$verbose" = "xtrue" ]; then
209 echo "NIT_NO_STACK=1 ./$ff.bin" $args
211 if [ -f
"$f.inputs" ]; then
212 NIT_NO_STACK
=1 "./$ff.bin" $args < "$f.inputs" > "$ff.res" 2>"$ff.err"
214 NIT_NO_STACK
=1 "./$ff.bin" $args > "$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 ls -F
$ff.
write >> "$ff.res"
225 if [ -s
"$ff.err" ]; then
226 cat "$ff.err" >> "$ff.res"
230 if [ -f
"$f.args" ]; then
237 if [ "x$verbose" = "xtrue" ]; then
239 echo "NIT_NO_STACK=1 ./$ff.bin" $args
241 echo -n
"==> args #"$cptr " "
242 if [ -f
"$f.inputs" ]; then
243 NIT_NO_STACK
=1 "./$ff.bin" $args < "$f.inputs" > "$fff.res" 2>"$fff.err"
245 sh
-c
"NIT_NO_STACK=1 ./$ff.bin ''$args > $fff.res 2>$fff.err"
247 if [ "x$verbose" = "xtrue" ]; then
251 if [ -f
"$fff.write" ]; then
252 cat "$fff.write" >> "$fff.res"
253 elif [ -d
"$fff.write" ]; then
254 ls -F
$fff.
write >> "$fff.res"
256 if [ -s
"$fff.err" ]; then
257 cat "$fff.err" >> "$fff.res"
264 echo "Compilation error" > "$ff.res"
270 echo "ok: " `echo $ok | wc -w` "/" `echo $ok $nok $nos | wc -w`
272 if [ -n
"$nok" ]; then
274 echo "There were $(echo $nok | wc -w) errors ! (see file $ERRLIST)"
276 if [ -n
"$nos" ]; then
281 if [ "x$ERRLIST" != "x" ]; then
282 if [ -x
"$ERRLIST_TARGET" ]; then
283 mv "$ERRLIST_TARGET" "${ERRLIST_TARGET}.bak"
285 mv $ERRLIST $ERRLIST_TARGET
288 if [ -n
"$nok" ]; then