5b4de3817b8d6e2dd16425c39b2d81e10a7c5b48
[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 if [ $# = 0 ]; then
31 echo "usage: $0 file.nit ..."
32 fi
33
34 ok=""
35 nok=""
36
37 for ii in "$@"; do
38 for alt in "" `sed -n 's/.*#!*\(alt[0-9]*\)#.*/\1/p' "$ii" | sort -u`; do
39 f=`basename "$ii" .nit`
40 d=`dirname "$ii"`
41 ff="$f"
42 i="$ii"
43 if [ "x$alt" != "x" ]; then
44 test -d alt || mkdir -p alt
45 i="alt/${f}_$alt.nit"
46 ff="${ff}_$alt"
47 sed "s/#$alt#//g;/#!$alt#/d" "$ii" > "$i"
48 fi
49 ff="$ff$MARK"
50
51 echo -n "=> $i: "
52
53 rm "$ff.res" "$ff.err" "$ff.write" 2> /dev/null
54
55 # Compile
56 $NITC $OPT -o "$f.bin" "$i" -I . -I alt -I ../lib/standard 2> "$ff.cmp.err" > "$ff.compile.log"
57 ERR=$?
58 mv "$f.bin" "$ff.bin" 2> /dev/null
59 egrep '^[A-Z0-9_]*$' "$ff.compile.log" > "$ff.res"
60 if [ "$ERR" != 0 ]; then
61 echo -n "! "
62 cp "$ff.cmp.err" "$ff.res"
63 else
64 echo -n ". "
65 # Execute
66 if [ -f "$f.args" ]; then
67 args=`cat "$f.args"`
68 else
69 args=""
70 fi
71 if [ -f "$f.inputs" ]; then
72 "./$ff.bin" $args < "$f.inputs" > "$ff.res" 2>"$ff.err"
73 else
74 "./$ff.bin" $args > "$ff.res" 2>"$ff.err"
75 fi
76 if [ -f "$ff.write" ]; then
77 cat "$ff.write" >> "$ff.res"
78 fi
79 if [ -s "$ff.err" ]; then
80 cat "$ff.err" >> "$ff.res"
81 fi
82 fi
83
84 # Result
85 if [ -r "sav/$ff.sav" ]; then
86 diff -u "$ff.res" "sav/$ff.sav" > "$ff.diff.log"
87 if [ "$?" == 0 ]; then
88 echo "[ok] $ff.res"
89 ok="$ok $ff"
90 else
91 echo "[======= fail $ff.res sav/$ff.sav =======]"
92 nok="$nok $ff"
93 fi
94 else
95 echo "[=== no sav ===] $ff.res"
96 nos="$nos $ff"
97 fi
98 done
99 done
100
101 echo "ok: " `echo $ok | wc -w` "/" `echo $ok $nok $nos | wc -w`
102
103 if [ -n "$nok" ]; then
104 echo "fail: $nok"
105 echo "There were errors !"
106 fi
107 if [ -n "$nos" ]; then
108 echo "no sav: $nos"
109 fi