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
()
43 if [ -r
"sav/$pattern.sav" ]; then
44 diff -u
"out/$pattern.res" "sav/$pattern.sav" > "out/$pattern.diff.sav.log"
45 if [ "$?" == 0 ]; then
50 sed '/[Ww]arning/d;/[Ee]rror/d' "out/$pattern.res" > "out/$pattern.res2"
51 sed '/[Ww]arning/d;/[Ee]rror/d' "sav/$pattern.sav" > "out/$pattern.sav2"
52 grep '[Ee]rror' "out/$pattern.res" >/dev
/null
&& echo "Error" >> "out/$pattern.res2"
53 grep '[Ee]rror' "sav/$pattern.sav" >/dev
/null
&& echo "Error" >> "out/$pattern.sav2"
54 diff -u
"out/$pattern.res2" "out/$pattern.sav2" > "out/$pattern.diff.sav2.log"
55 if [ "$?" == 0 ]; then
61 if [ -r
"sav/$pattern.fail" ]; then
62 diff -u
"out/$pattern.res" "sav/$pattern.fail" > "out/$pattern.diff.fail.log"
63 if [ "$?" == 0 ]; then
68 sed '/[Ww]arning/d;/[Ee]rror/d' "out/$pattern.res" > "out/$pattern.res2"
69 sed '/[Ww]arning/d;/[Ee]rror/d' "sav/$pattern.fail" > "out/$pattern.fail2"
70 grep '[Ee]rror' "out/$pattern.res" >/dev
/null
&& echo "Error" >> "out/$pattern.res2"
71 grep '[Ee]rror' "sav/$pattern.fail" >/dev
/null
&& echo "Error" >> "out/$pattern.fail2"
72 diff -u
"out/$pattern.res2" "out/$pattern.fail2" > "out/$pattern.diff.fail2.log"
73 if [ "$?" == 0 ]; then
79 grep 'NOT YET IMPLEMENTED' "out/$pattern.res" >/dev
/null
81 if [ "x$SAV" = "xOK" ]; then
82 if [ "x$FAIL" = "x" ]; then
83 echo "[ok] out/$pattern.res"
85 echo "[ok] out/$pattern.res - but sav/$pattern.fail remains!"
88 elif [ "x$FAIL" = "xOK" ]; then
89 echo "[fail] out/$pattern.res"
91 elif [ "x$SOSO" = "xOK" ]; then
92 echo "[soso] out/$pattern.res sav/$pattern.sav"
94 elif [ "x$NYI" = "x0" ]; then
95 echo "[todo] out/$pattern.res -> not yet implemented"
97 elif [ "x$SOSOF" = "xOK" ]; then
98 echo "[fail soso] out/$pattern.res sav/$pattern.fail"
100 elif [ "x$SAV" = "xNOK" ]; then
101 echo "[======= fail out/$pattern.res sav/$pattern.sav =======]"
103 echo "$ii" >> "$ERRLIST"
104 elif [ "x$FAIL" = "xNOK" ]; then
105 echo "[======= changed out/$pattern.res sav/$pattern.fail ======]"
107 echo "$ii" >> "$ERRLIST"
109 echo "[=== no sav ===] out/$pattern.res"
116 recent
=`ls -t ../src/nitc ../src/nitc_[0-9] ../bin/nitc ../c_src/nitc 2>/dev/null | head -1`
117 if [[ "x$recent" == "x" ]]; then
118 echo 'Could not find nitc, aborting'
121 echo 'Using nitc from: '$recent
125 # The default nitc compiler
126 [ -z
"$NITC" ] && find_nitc
128 # Set NIT_DIR if needed
129 [ -z
"$NIT_DIR" ] && export NIT_DIR
=..
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
166 # CLEAN the out directory
167 rm -rf out
/ 2>/dev
/null
168 mkdir out
2>/dev
/null
171 if [ ! -f
$ii ]; then
172 echo "File '$ii' does not exist."
177 if [ "x$tmp" = "x$ii" ]; then
178 includes
="-I . -I ../lib/standard -I ../lib/standard/collection -I alt"
183 f
=`basename "$ii" .nit`
184 for i
in "$ii" `./alterner.pl --start '#' --altsep '_' $ii`; do
185 bf
=`basename $i .nit`
189 if [ -f
"$f.inputs" ]; then
196 if [ "x$verbose" = "xtrue" ]; then
198 echo $NITC --no
-color
$OPT -o
"$ff.bin" "$i" "$includes"
200 $NITC --no
-color
$OPT -o
"$ff.bin" "$i" $includes <"$inputs" 2> "$ff.cmp.err" > "$ff.compile.log"
202 if [ "x$verbose" = "xtrue" ]; then
203 cat "$ff.compile.log"
204 cat >&2 "$ff.cmp.err"
206 egrep '^[A-Z0-9_]*$' "$ff.compile.log" > "$ff.res"
207 if [ "$ERR" != 0 ]; then
209 cat "$ff.cmp.err" "$ff.compile.log" > "$ff.res"
211 elif [ -x
"./$ff.bin" ]; then
212 cp "$ff.cmp.err" "$ff.res"
216 if [ "x$verbose" = "xtrue" ]; then
218 echo "NIT_NO_STACK=1 ./$ff.bin" $args
220 NIT_NO_STACK
=1 "./$ff.bin" $args < "$inputs" >> "$ff.res" 2>"$ff.err"
221 if [ "x$verbose" = "xtrue" ]; then
225 if [ -f
"$ff.write" ]; then
226 cat "$ff.write" >> "$ff.res"
227 elif [ -d
"$ff.write" ]; then
228 LANG
=C
/bin
/ls -F
$ff.
write >> "$ff.res"
230 if [ -s
"$ff.err" ]; then
231 cat "$ff.err" >> "$ff.res"
235 if [ -f
"$f.args" ]; then
243 rm -rf
"$fff.res" "$fff.err" "$fff.write" 2> /dev
/null
244 if [ "x$verbose" = "xtrue" ]; then
246 echo "NIT_NO_STACK=1 ./$ff.bin" $args
248 echo -n
"==> args #"$cptr " "
249 sh
-c
"NIT_NO_STACK=1 ./$ff.bin ''$args < $inputs > $fff.res 2>$fff.err"
250 if [ "x$verbose" = "xtrue" ]; then
254 if [ -f
"$fff.write" ]; then
255 cat "$fff.write" >> "$fff.res"
256 elif [ -d
"$fff.write" ]; then
257 LANG
=C
/bin
/ls -F
$fff.
write >> "$fff.res"
259 if [ -s
"$fff.err" ]; then
260 cat "$fff.err" >> "$fff.res"
267 cat "$ff.cmp.err" "$ff.compile.log" > "$ff.res"
268 #echo "Compilation error" > "$ff.res"
274 echo "ok: " `echo $ok | wc -w` "/" `echo $ok $nok $nos | wc -w`
276 if [ -n
"$nok" ]; then
278 echo "There were $(echo $nok | wc -w) errors ! (see file $ERRLIST)"
280 if [ -n
"$nos" ]; then
285 if [ "x$ERRLIST" != "x" ]; then
286 if [ -x
"$ERRLIST_TARGET" ]; then
287 mv "$ERRLIST_TARGET" "${ERRLIST_TARGET}.bak"
289 mv $ERRLIST $ERRLIST_TARGET
292 if [ -n
"$nok" ]; then