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
23 # The default nitc compiler
24 [ -z
"$NITC" ] && NITC
=..
/bin
/nitc
30 Usage
: $e [options
] modulenames
31 -o option Pass option to nitc
32 -v Verbose
(show tests steps
)
37 # As argument: the pattern used for the file
38 function process_result
()
44 if [ -r
"sav/$pattern.sav" ]; then
45 diff -u
"$pattern.res" "sav/$pattern.sav" > "$pattern.diff.sav.log"
46 if [ "$?" == 0 ]; then
52 if [ -r
"sav/$pattern.fail" ]; then
53 diff -u
"$pattern.res" "sav/$pattern.fail" > "$pattern.diff.fail.log"
54 if [ "$?" == 0 ]; then
60 if [ "x$SAV" = "xOK" ]; then
61 if [ "x$FAIL" = "x" ]; then
62 echo "[ok] $pattern.res"
64 echo "[ok] $pattern.res - but sav/$pattern.fail remains!"
67 elif [ "x$FAIL" = "xOK" ]; then
68 echo "[fail] $pattern.res"
70 elif [ "x$SAV" = "xNOK" ]; then
71 echo "[======= fail $pattern.res sav/$pattern.sav =======]"
73 echo "$ii" >> "$ERRLIST"
74 elif [ "x$FAIL" = "xNOK" ]; then
75 echo "[======= changed $pattern.res sav/$pattern.fail ======]"
77 echo "$ii" >> "$ERRLIST"
79 echo "[=== no sav ===] $pattern.res"
87 while [ $stop = false
]; do
89 -o
) OPT
="$OPT $2"; shift; shift;;
90 -v
) verbose
=true
; shift;;
96 # Mark to distinguish files among tests
99 # File where error tests are outputed
100 # Old ERRLIST is backuped
101 ERRLIST
=${ERRLIST:-errlist}
108 # Backup and initiate new ERRLIST
109 if [ "x$ERRLIST" = "x" ]; then
112 if [ -x
"$ERRLIST" ]; then
113 mv "$ERRLIST" "${ERRLIST}.bak"
122 for alt
in "" `sed -n 's/.*#!*\(alt[0-9]*\)#.*/\1/p' "$ii" | sort -u`; do
123 f
=`basename "$ii" .nit`
127 if [ "x$alt" != "x" ]; then
128 test -d alt || mkdir
-p alt
129 i
="alt/${f}_$alt.nit"
131 sed "s/#$alt#//g;/#!$alt#/d" "$ii" > "$i"
137 rm "$ff.res" "$ff.err" "$ff.write" "$ff.bin" 2> /dev
/null
140 if [ "x$verbose" = "xtrue" ]; then
142 echo $NITC $OPT -o
"$ff.bin" "$i" -I .
-I alt
-I ..
/lib
/standard
144 $NITC $OPT -o
"$ff.bin" "$i" -I .
-I alt
-I ..
/lib
/standard
2> "$ff.cmp.err" > "$ff.compile.log"
146 if [ "x$verbose" = "xtrue" ]; then
147 cat "$ff.compile.log"
148 cat >&2 "$ff.cmp.err"
150 egrep '^[A-Z0-9_]*$' "$ff.compile.log" > "$ff.res"
151 if [ "$ERR" != 0 ]; then
153 cp "$ff.cmp.err" "$ff.res"
155 elif [ -x
"./$ff.bin" ]; then
159 if [ "x$verbose" = "xtrue" ]; then
161 echo "./$ff.bin" $args
163 if [ -f
"$f.inputs" ]; then
164 "./$ff.bin" $args < "$f.inputs" > "$ff.res" 2>"$ff.err"
166 "./$ff.bin" $args > "$ff.res" 2>"$ff.err"
168 if [ "x$verbose" = "xtrue" ]; then
172 if [ -f
"$ff.write" ]; then
173 cat "$ff.write" >> "$ff.res"
175 if [ -s
"$ff.err" ]; then
176 cat "$ff.err" >> "$ff.res"
180 if [ -f
"$f.args" ]; then
188 if [ "x$verbose" = "xtrue" ]; then
190 echo "./$ff.bin" $args
192 echo -n
"==> args #"$cptr " "
193 if [ -f
"$f.inputs" ]; then
194 "./$ff.bin" $args < "$f.inputs" > "$fff.res" 2>"$fff.err"
196 sh
-c
"./$ff.bin ''$args > $fff.res 2>$fff.err"
198 if [ "x$verbose" = "xtrue" ]; then
202 if [ -f
"$fff.write" ]; then
203 cat "$fff.write" >> "$fff.res"
205 if [ -s
"$fff.err" ]; then
206 cat "$fff.err" >> "$fff.res"
213 echo "Compilation error" > "$ff.res"
219 echo "ok: " `echo $ok | wc -w` "/" `echo $ok $nok $nos | wc -w`
221 if [ -n
"$nok" ]; then
223 echo "There were $(echo $nok | wc -w) errors ! (see file $ERRLIST)"
225 if [ -n
"$nos" ]; then
229 if [ -n
"$nok" ]; then