Added missing operators.
[ragel.git] / test / runtests
blob9f91a750e6231019d543bc4779fdb436d8b386f1
1 #!/bin/bash
4 # Copyright 2006 Adrian Thurston <thurston@cs.queensu.ca>
7 # This file is part of Ragel.
9 # Ragel is free software; you can redistribute it and/or modify
10 # it under the terms of the GNU General Public License as published by
11 # the Free Software Foundation; either version 2 of the License, or
12 # (at your option) any later version.
14 # Ragel is distributed in the hope that it will be useful,
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 # GNU General Public License for more details.
19 # You should have received a copy of the GNU General Public License
20 # along with Ragel; if not, write to the Free Software
21 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 while getopts "gcnmleT:F:G:P:CDJR" opt; do
24 case $opt in
25 T|F|G|P)
26 genflags="$genflags -$opt$OPTARG"
27 options="$options -$opt$OPTARG"
29 n|m|l|e)
30 minflags="$minflags -$opt"
31 options="$options -$opt"
33 c)
34 compile_only="true"
35 options="$options -$opt"
37 g)
38 allow_generated="true"
40 C|D|J|R)
41 langflags="$langflags -$opt"
43 esac
44 done
46 [ -z "$minflags" ] && minflags="-n -m -l -e"
47 [ -z "$genflags" ] && genflags="-T0 -T1 -F0 -F1 -G0 -G1 -G2"
48 [ -z "$langflags" ] && langflags="-C -D -J -R"
50 shift $((OPTIND - 1));
52 [ -z "$*" ] && set -- *.rl
54 config=../common/config.h
55 ragel=../ragel/ragel
57 cxx_compiler=`sed '/^#define CXX/s/#define CXX *//p;d' $config`
58 c_compiler=`sed '/^#define CC/s/#define CC *//p;d' $config`
59 objc_compiler=`sed '/^#define GOBJC/s/#define GOBJC *//p;d' $config`
60 d_compiler=`sed '/^#define GDC/s/#define GDC *//p;d' $config`
61 java_compiler=`sed '/#define JAVAC/s/#define JAVAC *//p;d' $config`
62 txl_engine=`sed '/^#define TXL/s/#define TXL *//p;d' $config`
63 ruby_engine=`sed '/^#define RUBY/s/#define RUBY *//p;d' $config`
65 function test_error
67 exit 1;
70 # split_objs=""
71 # if test $split_iters != "$gen_opt"; then
72 # n=0;
73 # while test $n -lt $split_iters; do
74 # part_root=${root}_`awk 'BEGIN {
75 # width = 0;
76 # high = '$split_iters' - 1;
77 # while ( high > 0 ) {
78 # width = width + 1;
79 # high = int(high / 10);
80 # }
81 # suffFormat = "%" width "." width "d\n";
82 # printf( suffFormat, '$n' );
83 # exit 0;
84 # }'`
85 # part_src=${part_root}.c
86 # part_bin=${part_root}.o
87 # echo "$compiler -c $cflags -o $part_bin $part_src"
88 # if ! $compiler -c $cflags -o $part_bin $part_src; then
89 # test_error;
90 # fi
91 # split_objs="$split_objs $part_bin"
92 # n=$((n+1))
93 # done
94 # fi
96 function run_test()
98 echo "$ragel $lang_opt $min_opt $gen_opt -o $code_src $test_case"
99 if ! $ragel $lang_opt $min_opt $gen_opt -o $code_src $test_case; then
100 test_error;
103 out_args=""
104 [ $lang != java ] && out_args="-o ${binary}";
106 # Ruby doesn't need to be compiled.
107 if [ $lang != ruby ]; then
108 echo "$compiler ${cflags} ${out_args} ${code_src}"
109 if ! $compiler ${cflags} ${out_args} ${code_src}; then
110 test_error;
114 if [ "$compile_only" != "true" ]; then
115 echo -n "running $root ... ";
117 exec_cmd=./$binary
118 [ $lang = java ] && exec_cmd="java $root"
119 [ $lang = ruby ] && exec_cmd="ruby ${code_src}"
121 $exec_cmd 2>&1 > $output;
122 if diff $expected_out $output > /dev/null; then
123 echo "passed";
124 else
125 echo "FAILED";
126 test_error;
131 for test_case; do
132 root=${test_case%.rl};
134 if ! [ -f "$test_case" ]; then
135 echo "runtests: not a file: $test_case"; >&2
136 exit 1;
139 # Check if we should ignore the test case
140 ignore=`sed '/@IGNORE:/s/^.*: *//p;d' $test_case`
141 if [ "$ignore" = yes ]; then
142 continue;
145 # If the generated flag is given make sure that the test case is generated.
146 is_generated=`sed '/@GENERATED:/s/^.*: *//p;d' $test_case`
147 if [ "$is_generated" = yes ] && [ "$allow_generated" != true ]; then
148 continue;
151 expected_out=$root.exp;
152 sed '1,/_____OUTPUT_____/d;$d' $test_case > $expected_out
154 lang=`sed '/@LANG:/s/^.*: *//p;d' $test_case`
155 if [ -z "$lang" ]; then
156 echo "$test_case: language unset"; >&2
157 exit 1;
160 case $lang in
161 c++)
162 lang_opt=-C;
163 codegen=../rlgen-cd/rlgen-cd;
164 code_suffix=cpp;
165 compiler=$cxx_compiler;
166 cflags="-pedantic -ansi -Wall -O3"
169 lang_opt=-D;
170 codegen=../rlgen-cd/rlgen-cd;
171 code_suffix=d;
172 compiler=$d_compiler;
173 cflags="-Wall -O3"
176 lang_opt=-C;
177 codegen=../rlgen-cd/rlgen-cd;
178 code_suffix=c;
179 compiler=$c_compiler;
180 cflags="-pedantic -ansi -Wall -O3"
182 obj-c)
183 lang_opt=-C;
184 codegen=../rlgen-cd/rlgen-cd;
185 code_suffix=m;
186 compiler=$objc_compiler
187 cflags="-Wall -O3 -fno-strict-aliasing -lobjc"
189 java)
190 lang_opt=-J;
191 codegen=../rlgen-java/rlgen-java;
192 code_suffix=java;
193 compiler=$java_compiler
194 cflags=""
196 ruby)
197 lang_opt=-R;
198 codegen=../rlgen-ruby/rlgen-ruby;
199 code_suffix=rb;
200 compiler=$ruby_engine
201 cflags=""
203 indep)
204 lang_opt="";
206 # If we have no txl engine then skip this test.
207 [ -z "$txl_engine" ] && continue
208 for lang in c d java ruby; do
209 case $lang in
210 c) lf="-C";;
211 d) lf="-D";;
212 java) lf="-J";;
213 ruby) lf="-R";;
214 esac
216 echo "$langflags" | grep -e $lf >/dev/null || continue
218 targ=${root}_$lang.rl
219 echo "./langtrans_$lang.sh $test_case > $targ"
220 if ! ./langtrans_$lang.sh $test_case > $targ; then
221 test_error
223 echo "./runtests -g $options $targ"
224 if ! ./runtests -g $options $targ; then
225 test_error
227 done
228 continue;
231 echo "$test_case: unknown language type $lang" >&2
232 exit 1;
234 esac
236 # Make sure that we are interested in the host language.
237 echo "$langflags" | grep -e $lang_opt >/dev/null || continue
239 code_src=$root.$code_suffix;
240 binary=$root.bin;
241 output=$root.out;
243 # If we have no compiler for the source program then skip it.
244 [ -z "$compiler" ] && continue
246 additional_cflags=`sed '/@CFLAGS:/s/^.*: *//p;d' $test_case`
247 [ -n "$additional_cflags" ] && cflags="$cflags $additional_cflags"
249 allow_minflags=`sed '/@ALLOW_MINFLAGS:/s/^.*: *//p;d' $test_case`
250 [ -z "$allow_minflags" ] && allow_minflags="-n -m -l -e"
252 case $lang in
253 c|c++|d)
254 # Using genflags, get the allowed gen flags from the test case. If the
255 # test case doesn't specify assume that all gen flags are allowed.
256 allow_genflags=`sed '/@ALLOW_GENFLAGS:/s/^.*: *//p;d' $test_case`
257 [ -z "$allow_genflags" ] && allow_genflags="-T0 -T1 -F0 -F1 -G0 -G1 -G2"
259 for min_opt in $minflags; do
260 echo "$allow_minflags" | grep -e $min_opt >/dev/null || continue
261 for gen_opt in $genflags; do
262 echo "$allow_genflags" | grep -e $gen_opt >/dev/null || continue
263 run_test
264 done
265 done
268 java)
269 # Not interested in gen opt.
270 gen_opt=""
271 for min_opt in $minflags; do
272 echo "$allow_minflags" | grep -e $min_opt >/dev/null || continue
273 run_test
274 done
277 ruby)
278 # Using genflags, get the allowed gen flags from the test case. If the
279 # test case doesn't specify assume that all gen flags are allowed.
280 allow_genflags=`sed '/@ALLOW_GENFLAGS:/s/^.*: *//p;d' $test_case`
281 [ -z "$allow_genflags" ] && allow_genflags="-T0 -T1 -F0 -F1"
283 for min_opt in $minflags; do
284 echo "$allow_minflags" | grep -e $min_opt >/dev/null || continue
286 for gen_opt in $genflags; do
287 echo "$allow_genflags" | grep -e $gen_opt >/dev/null || continue
288 run_test
289 done
290 done
293 esac
295 done