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 for alt
in "" `sed -n 's/.*#!*\(alt[0-9]*\)#.*/\1/p' "$ii" | sort -u`; do
132 f
=`basename "$ii" .nit`
136 if [ "x$alt" != "x" ]; then
137 test -d alt || mkdir
-p alt
138 i
="alt/${f}_$alt.nit"
140 sed "s/#$alt#//g;/#!$alt#/d" "$ii" > "$i"
146 rm "$ff.res" "$ff.err" "$ff.write" "$ff.bin" 2> /dev
/null
149 if [ "x$verbose" = "xtrue" ]; then
151 echo $NITC $OPT -o
"$ff.bin" "$i" -I .
-I alt
-I ..
/lib
/standard
153 $NITC $OPT -o
"$ff.bin" "$i" -I .
-I alt
-I ..
/lib
/standard
2> "$ff.cmp.err" > "$ff.compile.log"
155 if [ "x$verbose" = "xtrue" ]; then
156 cat "$ff.compile.log"
157 cat >&2 "$ff.cmp.err"
159 egrep '^[A-Z0-9_]*$' "$ff.compile.log" > "$ff.res"
160 if [ "$ERR" != 0 ]; then
162 cp "$ff.cmp.err" "$ff.res"
164 elif [ -x
"./$ff.bin" ]; then
168 if [ "x$verbose" = "xtrue" ]; then
170 echo "./$ff.bin" $args
172 if [ -f
"$f.inputs" ]; then
173 "./$ff.bin" $args < "$f.inputs" > "$ff.res" 2>"$ff.err"
175 "./$ff.bin" $args > "$ff.res" 2>"$ff.err"
177 if [ "x$verbose" = "xtrue" ]; then
181 if [ -f
"$ff.write" ]; then
182 cat "$ff.write" >> "$ff.res"
184 if [ -s
"$ff.err" ]; then
185 cat "$ff.err" >> "$ff.res"
189 if [ -f
"$f.args" ]; then
197 if [ "x$verbose" = "xtrue" ]; then
199 echo "./$ff.bin" $args
201 echo -n
"==> args #"$cptr " "
202 if [ -f
"$f.inputs" ]; then
203 "./$ff.bin" $args < "$f.inputs" > "$fff.res" 2>"$fff.err"
205 sh
-c
"./$ff.bin ''$args > $fff.res 2>$fff.err"
207 if [ "x$verbose" = "xtrue" ]; then
211 if [ -f
"$fff.write" ]; then
212 cat "$fff.write" >> "$fff.res"
214 if [ -s
"$fff.err" ]; then
215 cat "$fff.err" >> "$fff.res"
222 echo "Compilation error" > "$ff.res"
228 echo "ok: " `echo $ok | wc -w` "/" `echo $ok $nok $nos | wc -w`
230 if [ -n
"$nok" ]; then
232 echo "There were $(echo $nok | wc -w) errors ! (see file $ERRLIST)"
234 if [ -n
"$nos" ]; then
239 if [ "x$ERRLIST" != "x" ]; then
240 if [ -x
"$ERRLIST_TARGET" ]; then
241 mv "$ERRLIST_TARGET" "${ERRLIST_TARGET}.bak"
243 mv $ERRLIST $ERRLIST_TARGET
246 if [ -n
"$nok" ]; then