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:CDJRA" opt
; do
26 genflags
="$genflags -$opt$OPTARG"
27 options
="$options -$opt$OPTARG"
30 minflags
="$minflags -$opt"
31 options
="$options -$opt"
35 options
="$options -$opt"
38 allow_generated
="true"
41 langflags
="$langflags -$opt"
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 -A"
50 shift $
((OPTIND
- 1));
52 [ -z "$*" ] && set -- *.rl
54 config
=..
/common
/config.h
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`
64 csharp_compiler
=`sed '/#define GMCS/s/#define GMCS *//p;d' $config`
72 # if test $split_iters != "$gen_opt"; then
74 # while test $n -lt $split_iters; do
75 # part_root=${root}_`awk 'BEGIN {
77 # high = '$split_iters' - 1;
78 # while ( high > 0 ) {
80 # high = int(high / 10);
82 # suffFormat = "%" width "." width "d\n";
83 # printf( suffFormat, '$n' );
86 # part_src=${part_root}.c
87 # part_bin=${part_root}.o
88 # echo "$compiler -c $cflags -o $part_bin $part_src"
89 # if ! $compiler -c $cflags -o $part_bin $part_src; then
92 # split_objs="$split_objs $part_bin"
99 echo "$ragel $lang_opt $min_opt $gen_opt -o $code_src $test_case"
100 if ! $ragel $lang_opt $min_opt $gen_opt -o $code_src $test_case; then
105 [ $lang != java
] && out_args
="-o ${binary}";
106 [ $lang == csharp
] && out_args
="-out:${binary}";
108 # Ruby doesn't need to be compiled.
109 if [ $lang != ruby
]; then
110 echo "$compiler ${cflags} ${out_args} ${code_src}"
111 if ! $compiler ${cflags} ${out_args} ${code_src}; then
116 if [ "$compile_only" != "true" ]; then
117 echo -n "running $root ... ";
120 [ $lang = java
] && exec_cmd
="java ${root}"
121 [ $lang = ruby
] && exec_cmd
="ruby ${code_src}"
122 [ $lang = csharp
] && exec_cmd
="mono ${exec_cmd}"
124 $exec_cmd 2>&1 > $output;
125 if diff $expected_out $output > /dev
/null
; then
135 root
=${test_case%.rl};
137 if ! [ -f "$test_case" ]; then
138 echo "runtests: not a file: $test_case"; >&2
142 # Check if we should ignore the test case
143 ignore
=`sed '/@IGNORE:/s/^.*: *//p;d' $test_case`
144 if [ "$ignore" = yes ]; then
148 # If the generated flag is given make sure that the test case is generated.
149 is_generated
=`sed '/@GENERATED:/s/^.*: *//p;d' $test_case`
150 if [ "$is_generated" = yes ] && [ "$allow_generated" != true
]; then
154 expected_out
=$root.exp
;
155 sed '1,/_____OUTPUT_____/d;$d' $test_case > $expected_out
157 lang
=`sed '/@LANG:/s/^.*: *//p;d' $test_case`
158 if [ -z "$lang" ]; then
159 echo "$test_case: language unset"; >&2
166 codegen
=..
/rlgen-cd
/rlgen-cd
;
168 compiler
=$cxx_compiler;
169 cflags
="-pedantic -ansi -Wall -O3"
173 codegen
=..
/rlgen-cd
/rlgen-cd
;
175 compiler
=$d_compiler;
180 codegen
=..
/rlgen-cd
/rlgen-cd
;
182 compiler
=$c_compiler;
183 cflags
="-pedantic -ansi -Wall -O3"
187 codegen
=..
/rlgen-cd
/rlgen-cd
;
189 compiler
=$objc_compiler
190 cflags
="-Wall -O3 -fno-strict-aliasing -lobjc"
194 codegen
=..
/rlgen-java
/rlgen-java
;
196 compiler
=$java_compiler
201 codegen
=..
/rlgen-ruby
/rlgen-ruby
;
203 compiler
=$ruby_engine
208 codegen
=..
/rlgen-csharp
/rlgen-csharp
;
210 compiler
=$csharp_compiler
216 # If we have no txl engine then skip this test.
217 [ -z "$txl_engine" ] && continue
218 for lang
in c d java ruby csharp
; do
227 echo "$langflags" |
grep -e $lf >/dev
/null ||
continue
229 targ
=${root}_
$lang.rl
230 echo "./langtrans_$lang.sh $test_case > $targ"
231 if ! .
/langtrans_
$lang.sh
$test_case > $targ; then
234 echo "./runtests -g $options $targ"
235 if ! .
/runtests
-g $options $targ; then
242 echo "$test_case: unknown language type $lang" >&2
247 # Make sure that we are interested in the host language.
248 echo "$langflags" |
grep -e $lang_opt >/dev
/null ||
continue
250 code_src
=$root.
$code_suffix;
254 # If we have no compiler for the source program then skip it.
255 [ -z "$compiler" ] && continue
257 additional_cflags
=`sed '/@CFLAGS:/s/^.*: *//p;d' $test_case`
258 [ -n "$additional_cflags" ] && cflags
="$cflags $additional_cflags"
260 allow_minflags
=`sed '/@ALLOW_MINFLAGS:/s/^.*: *//p;d' $test_case`
261 [ -z "$allow_minflags" ] && allow_minflags
="-n -m -l -e"
265 # Using genflags, get the allowed gen flags from the test case. If the
266 # test case doesn't specify assume that all gen flags are allowed.
267 allow_genflags
=`sed '/@ALLOW_GENFLAGS:/s/^.*: *//p;d' $test_case`
268 [ -z "$allow_genflags" ] && allow_genflags
="-T0 -T1 -F0 -F1 -G0 -G1 -G2"
270 for min_opt
in $minflags; do
271 echo "$allow_minflags" |
grep -e $min_opt >/dev
/null ||
continue
272 for gen_opt
in $genflags; do
273 echo "$allow_genflags" |
grep -e $gen_opt >/dev
/null ||
continue
280 # Not interested in gen opt.
282 for min_opt
in $minflags; do
283 echo "$allow_minflags" |
grep -e $min_opt >/dev
/null ||
continue
289 # Using genflags, get the allowed gen flags from the test case. If the
290 # test case doesn't specify assume that all gen flags are allowed.
291 allow_genflags
=`sed '/@ALLOW_GENFLAGS:/s/^.*: *//p;d' $test_case`
292 [ -z "$allow_genflags" ] && allow_genflags
="-T0 -T1 -F0 -F1"
294 for min_opt
in $minflags; do
295 echo "$allow_minflags" |
grep -e $min_opt >/dev
/null ||
continue
297 for gen_opt
in $genflags; do
298 echo "$allow_genflags" |
grep -e $gen_opt >/dev
/null ||
continue
305 # Using genflags, get the allowed gen flags from the test case. If the
306 # test case doesn't specify assume that all gen flags are allowed.
307 allow_genflags
=`sed '/@ALLOW_GENFLAGS:/s/^.*: *//p;d' $test_case`
308 [ -z "$allow_genflags" ] && allow_genflags
="-T0 -T1 -F0 -F1 -G0 -G1"
310 for min_opt
in $minflags; do
311 echo "$allow_minflags" |
grep -e $min_opt >/dev
/null ||
continue
312 for gen_opt
in $genflags; do
313 echo "$allow_genflags" |
grep -e $gen_opt >/dev
/null ||
continue