syntax: 'meth' -> 'fun', 'attr' -> 'var'
[nit.git] / tests / tests.sh
1 #!/bin/bash
2 # This file is part of NIT ( http://www.nitlanguage.org ).
3 #
4 # Copyright 2004-2008 Jean Privat <jean@pryen.org>
5 #
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
9 #
10 # http://www.apache.org/licenses/LICENSE-2.0
11 #
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.
17
18 # This shell script compile, run and verify NIT program files
19
20 # Ruby binary (none if you want to let the program to decide)
21 #RUBY=
22 [ -z "$NITC" ] && NITC=../bin/nitc
23
24 # Options to use with the ruby compiler
25 # OPT=
26
27 # Mark to distinguish files among tests
28 # MARK=
29
30 # File where error tests are outputed
31 # Old ERRLIST is backuped
32 ERRLIST=${ERRLIST:-errlist}
33
34 if [ $# = 0 ]; then
35 echo "usage: $0 file.nit ..."
36 fi
37
38 # Backup and initiate new ERRLIST
39 if [ "x$ERRLIST" = "x" ]; then
40 ERRLIST=/dev=null
41 else
42 if [ -x "$ERRLIST" ]; then
43 mv "$ERRLIST" "${ERRLIST}.bak"
44 fi
45 > "$ERRLIST"
46 fi
47
48 ok=""
49 nok=""
50
51 for ii in "$@"; do
52 for alt in "" `sed -n 's/.*#!*\(alt[0-9]*\)#.*/\1/p' "$ii" | sort -u`; do
53 f=`basename "$ii" .nit`
54 d=`dirname "$ii"`
55 ff="$f"
56 i="$ii"
57 if [ "x$alt" != "x" ]; then
58 test -d alt || mkdir -p alt
59 i="alt/${f}_$alt.nit"
60 ff="${ff}_$alt"
61 sed "s/#$alt#//g;/#!$alt#/d" "$ii" > "$i"
62 fi
63 ff="$ff$MARK"
64
65 echo -n "=> $i: "
66
67 rm "$ff.res" "$ff.err" "$ff.write" 2> /dev/null
68
69 # Compile
70 $NITC $OPT -o "$f.bin" "$i" -I . -I alt -I ../lib/standard 2> "$ff.cmp.err" > "$ff.compile.log"
71 ERR=$?
72 mv "$f.bin" "$ff.bin" 2> /dev/null
73 egrep '^[A-Z0-9_]*$' "$ff.compile.log" > "$ff.res"
74 if [ "$ERR" != 0 ]; then
75 echo -n "! "
76 cp "$ff.cmp.err" "$ff.res"
77 else
78 echo -n ". "
79 # Execute
80 if [ -f "$f.args" ]; then
81 args=`cat "$f.args"`
82 else
83 args=""
84 fi
85 if [ -f "$f.inputs" ]; then
86 "./$ff.bin" $args < "$f.inputs" > "$ff.res" 2>"$ff.err"
87 else
88 "./$ff.bin" $args > "$ff.res" 2>"$ff.err"
89 fi
90 if [ -f "$ff.write" ]; then
91 cat "$ff.write" >> "$ff.res"
92 fi
93 if [ -s "$ff.err" ]; then
94 cat "$ff.err" >> "$ff.res"
95 fi
96 fi
97
98 # Result
99 if [ -r "sav/$ff.sav" ]; then
100 diff -u "$ff.res" "sav/$ff.sav" > "$ff.diff.log"
101 if [ "$?" == 0 ]; then
102 echo "[ok] $ff.res"
103 ok="$ok $ff"
104 else
105 echo "[======= fail $ff.res sav/$ff.sav =======]"
106 nok="$nok $ff"
107 echo "$ii" >> "$ERRLIST"
108 fi
109 else
110 echo "[=== no sav ===] $ff.res"
111 nos="$nos $ff"
112 fi
113 done
114 done
115
116 echo "ok: " `echo $ok | wc -w` "/" `echo $ok $nok $nos | wc -w`
117
118 if [ -n "$nok" ]; then
119 echo "fail: $nok"
120 echo "There were errors ! (see file $ERRLIST)"
121 fi
122 if [ -n "$nos" ]; then
123 echo "no sav: $nos"
124 fi
125
126 if [ -n "$nok" ]; then
127 exit 1
128 else
129 exit 0
130 fi