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
92 # The default nitc compiler
93 [ -z
"$NITC" ] && find_nitc
97 while [ $stop = false
]; do
99 -o
) OPT
="$OPT $2"; shift; shift;;
100 -v
) verbose
=true
; shift;;
106 # Mark to distinguish files among tests
109 # File where error tests are outputed
110 # Old ERRLIST is backuped
111 ERRLIST
=${ERRLIST:-errlist}
112 ERRLIST_TARGET
=$ERRLIST
119 # Initiate new ERRLIST
120 if [ "x$ERRLIST" = "x" ]; then
131 if [ ! -f
$ii ]; then
132 echo "File '$ii' does not exist."
137 if [ "x$tmp" = "x$ii" ]; then
138 oincludes
="-I . -I ../lib/standard -I ../lib/standard/collection"
143 for alt
in "" `sed -n 's/.*#!*\(alt[0-9]*\)#.*/\1/p' "$ii" | sort -u`; do
144 f
=`basename "$ii" .nit`
148 includes
="$oincludes"
150 if [ "x$alt" != "x" ]; then
151 test -d alt || mkdir
-p alt
152 i
="alt/${f}_$alt.nit"
154 sed "s/#$alt#//g;/#!$alt#/d" "$ii" > "$i"
155 includes
="$includes -I alt"
161 rm -rf
"$ff.res" "$ff.err" "$ff.write" "$ff.bin" 2> /dev
/null
164 if [ "x$verbose" = "xtrue" ]; then
166 echo $NITC $OPT -o
"$ff.bin" "$i" "$includes"
168 $NITC $OPT -o
"$ff.bin" "$i" $includes 2> "$ff.cmp.err" > "$ff.compile.log"
170 if [ "x$verbose" = "xtrue" ]; then
171 cat "$ff.compile.log"
172 cat >&2 "$ff.cmp.err"
174 egrep '^[A-Z0-9_]*$' "$ff.compile.log" > "$ff.res"
175 if [ "$ERR" != 0 ]; then
177 cp "$ff.cmp.err" "$ff.res"
179 elif [ -x
"./$ff.bin" ]; then
183 if [ "x$verbose" = "xtrue" ]; then
185 echo "./$ff.bin" $args
187 if [ -f
"$f.inputs" ]; then
188 "./$ff.bin" $args < "$f.inputs" > "$ff.res" 2>"$ff.err"
190 "./$ff.bin" $args > "$ff.res" 2>"$ff.err"
192 if [ "x$verbose" = "xtrue" ]; then
196 if [ -f
"$ff.write" ]; then
197 cat "$ff.write" >> "$ff.res"
198 elif [ -d
"$ff.write" ]; then
199 ls -F
$ff.
write >> "$ff.res"
201 if [ -s
"$ff.err" ]; then
202 cat "$ff.err" >> "$ff.res"
206 if [ -f
"$f.args" ]; then
213 if [ "x$verbose" = "xtrue" ]; then
215 echo "./$ff.bin" $args
217 echo -n
"==> args #"$cptr " "
218 if [ -f
"$f.inputs" ]; then
219 "./$ff.bin" $args < "$f.inputs" > "$fff.res" 2>"$fff.err"
221 sh
-c
"./$ff.bin ''$args > $fff.res 2>$fff.err"
223 if [ "x$verbose" = "xtrue" ]; then
227 if [ -f
"$fff.write" ]; then
228 cat "$fff.write" >> "$fff.res"
229 elif [ -d
"$fff.write" ]; then
230 ls -F
$fff.
write >> "$fff.res"
232 if [ -s
"$fff.err" ]; then
233 cat "$fff.err" >> "$fff.res"
240 echo "Compilation error" > "$ff.res"
246 echo "ok: " `echo $ok | wc -w` "/" `echo $ok $nok $nos | wc -w`
248 if [ -n
"$nok" ]; then
250 echo "There were $(echo $nok | wc -w) errors ! (see file $ERRLIST)"
252 if [ -n
"$nos" ]; then
257 if [ "x$ERRLIST" != "x" ]; then
258 if [ -x
"$ERRLIST_TARGET" ]; then
259 mv "$ERRLIST_TARGET" "${ERRLIST_TARGET}.bak"
261 mv $ERRLIST $ERRLIST_TARGET
264 if [ -n
"$nok" ]; then