From d516a905384fc1edbfedc3e08f6b77c5f51e10ab Mon Sep 17 00:00:00 2001 From: thurston Date: Tue, 6 Feb 2007 17:51:50 +0000 Subject: [PATCH] Added a ruby test: atoi3.rl and adapted the test harness to build and run ruby tests. git-svn-id: http://svn.complang.org/ragel/trunk@85 052ea7fc-9027-0410-9066-f65837a77df0 --- common/config.h.in | 3 +- configure | 45 +++++++++++++++++++++++++++++- configure.in | 6 ++++ test/atoi3.rl | 82 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ test/runtests | 25 +++++++++++++---- 5 files changed, 153 insertions(+), 8 deletions(-) create mode 100644 test/atoi3.rl diff --git a/common/config.h.in b/common/config.h.in index 0285bb0..86aab1e 100644 --- a/common/config.h.in +++ b/common/config.h.in @@ -22,12 +22,13 @@ #ifndef _CONFIG_H #define _CONFIG_H -/* Compilers. */ +/* Programs. */ #undef GDC #undef GOBJC #undef CXX #undef CC #undef JAVAC #undef TXL +#undef RUBY #endif /* _CONFIG_H */ diff --git a/configure b/configure index 43f4418..1c2ddb8 100755 --- a/configure +++ b/configure @@ -272,7 +272,7 @@ PACKAGE_STRING= PACKAGE_BUGREPORT= ac_unique_file="ragel/main.cpp" -ac_subst_vars='SHELL PATH_SEPARATOR PACKAGE_NAME PACKAGE_TARNAME PACKAGE_VERSION PACKAGE_STRING PACKAGE_BUGREPORT exec_prefix prefix program_transform_name bindir sbindir libexecdir datadir sysconfdir sharedstatedir localstatedir libdir includedir oldincludedir infodir mandir build_alias host_alias target_alias DEFS ECHO_C ECHO_N ECHO_T LIBS BUILD_PARSERS CC CFLAGS LDFLAGS CPPFLAGS ac_ct_CC EXEEXT OBJEXT CXX CXXFLAGS ac_ct_CXX SET_MAKE RAGEL GPERF KELBT GDC GOBJC JAVAC TXL LIBOBJS LTLIBOBJS' +ac_subst_vars='SHELL PATH_SEPARATOR PACKAGE_NAME PACKAGE_TARNAME PACKAGE_VERSION PACKAGE_STRING PACKAGE_BUGREPORT exec_prefix prefix program_transform_name bindir sbindir libexecdir datadir sysconfdir sharedstatedir localstatedir libdir includedir oldincludedir infodir mandir build_alias host_alias target_alias DEFS ECHO_C ECHO_N ECHO_T LIBS BUILD_PARSERS CC CFLAGS LDFLAGS CPPFLAGS ac_ct_CC EXEEXT OBJEXT CXX CXXFLAGS ac_ct_CXX SET_MAKE RAGEL GPERF KELBT GDC GOBJC JAVAC TXL RUBY LIBOBJS LTLIBOBJS' ac_subst_files='' # Initialize some variables set by options. @@ -2856,6 +2856,48 @@ _ACEOF fi +# Extract the first word of "ruby", so it can be a program name with args. +set dummy ruby; ac_word=$2 +echo "$as_me:$LINENO: checking for $ac_word" >&5 +echo $ECHO_N "checking for $ac_word... $ECHO_C" >&6 +if test "${ac_cv_prog_RUBY+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + if test -n "$RUBY"; then + ac_cv_prog_RUBY="$RUBY" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if $as_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + ac_cv_prog_RUBY="ruby" + echo "$as_me:$LINENO: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done +done + +fi +fi +RUBY=$ac_cv_prog_RUBY +if test -n "$RUBY"; then + echo "$as_me:$LINENO: result: $RUBY" >&5 +echo "${ECHO_T}$RUBY" >&6 +else + echo "$as_me:$LINENO: result: no" >&5 +echo "${ECHO_T}no" >&6 +fi + +if test -n "$RUBY"; then + cat >>confdefs.h <<_ACEOF +#define RUBY $RUBY +_ACEOF + +fi + ac_config_files="$ac_config_files Makefile common/Makefile ragel/Makefile redfsm/Makefile rlcodegen/Makefile rlgen-java/Makefile rlgen-ruby/Makefile doc/Makefile test/Makefile" cat >confcache <<\_ACEOF # This file is a shell script that caches the results of configure @@ -3494,6 +3536,7 @@ s,@GDC@,$GDC,;t t s,@GOBJC@,$GOBJC,;t t s,@JAVAC@,$JAVAC,;t t s,@TXL@,$TXL,;t t +s,@RUBY@,$RUBY,;t t s,@LIBOBJS@,$LIBOBJS,;t t s,@LTLIBOBJS@,$LTLIBOBJS,;t t CEOF diff --git a/configure.in b/configure.in index 7c74d33..4bdb18b 100644 --- a/configure.in +++ b/configure.in @@ -104,6 +104,12 @@ if test -n "$TXL"; then AC_DEFINE_UNQUOTED(TXL,$TXL) fi +dnl Check for Ruby. +AC_CHECK_PROG(RUBY, ruby, ruby) +if test -n "$RUBY"; then + AC_DEFINE_UNQUOTED(RUBY,$RUBY) +fi + dnl write output files AC_OUTPUT(Makefile common/Makefile ragel/Makefile redfsm/Makefile rlcodegen/Makefile rlgen-java/Makefile rlgen-ruby/Makefile doc/Makefile test/Makefile) diff --git a/test/atoi3.rl b/test/atoi3.rl new file mode 100644 index 0000000..4df39af --- /dev/null +++ b/test/atoi3.rl @@ -0,0 +1,82 @@ +# +# @LANG: ruby +# @ALLOW_GENFLAGS: -T0 +# + +neg = false +val = 0 + +%%{ + machine atoi1_java; + alphtype byte; + action begin { + neg = false; + val = 0; + } + action see_neg { + neg = true; + } + action add_digit { + val = val * 10 + (fc - "0"[0]); + } + action finish { + val = -1 * val if neg + } + action print { + puts val; + } + atoi = (('-' @ see_neg | '+') ? (digit @ add_digit) +) > begin % finish; + main := atoi '\n' @ print; +}%% + +%% write data; + +def run_machine( data ) + p = 0; + pe = data.length + cs = 0 + cs = 0 + val = 0; + neg = false; + + %% write init; + %% write exec; + %% write eof; + if cs >= atoi1_java_first_final + puts "ACCEPT" + else + puts "FAIL" + end +end + +inp = [ + "1\n", + "12\n", + "222222\n", + "+2123\n", + "213 3213\n", + "-12321\n", + "--123\n", + "-99\n", + " -3000\n", +] + +inp.each { |str| run_machine(str) } + +=begin _____OUTPUT_____ +1 +ACCEPT +12 +ACCEPT +222222 +ACCEPT +2123 +ACCEPT +FAIL +-12321 +ACCEPT +FAIL +-99 +ACCEPT +FAIL +=end _____OUTPUT_____ diff --git a/test/runtests b/test/runtests index 2b0daf0..48bbf2e 100755 --- a/test/runtests +++ b/test/runtests @@ -37,7 +37,7 @@ while getopts "gcnmleT:F:G:P:CDJ" opt; do g) allow_generated="true" ;; - C|D|J) + C|D|J|R) langflags="$langflags -$opt" ;; esac @@ -45,7 +45,7 @@ done [ -z "$minflags" ] && minflags="-n -m -l -e" [ -z "$genflags" ] && genflags="-T0 -T1 -F0 -F1 -G0 -G1 -G2" -[ -z "$langflags" ] && langflags="-C -D -J" +[ -z "$langflags" ] && langflags="-C -D -J -R" shift $((OPTIND - 1)); @@ -60,6 +60,7 @@ objc_compiler=`sed '/^#define GOBJC/s/#define GOBJC *//p;d' $config` d_compiler=`sed '/^#define GDC/s/#define GDC *//p;d' $config` java_compiler=`sed '/#define JAVAC/s/#define JAVAC *//p;d' $config` txl_engine=`sed '/^#define TXL/s/#define TXL *//p;d' $config` +ruby_engine=`sed '/^#define RUBY/s/#define RUBY *//p;d' $config` function test_error { @@ -131,6 +132,13 @@ for test_case; do lang_opt=-J; cflags="" ;; + ruby) + codegen=../rlgen-ruby/rlgen-ruby; + code_suffix=rb; + compiler=$ruby_engine + lang_opt=-R; + cflags="" + ;; indep) # If we have no compiler for the source program then skip it. [ -z "$txl_engine" ] && continue @@ -180,6 +188,7 @@ for test_case; do allow_genflags=`sed '/@ALLOW_GENFLAGS:/s/^.*: *//p;d' $test_case` [ -z "$allow_genflags" ] && allow_genflags="-T0 -T1 -F0 -F1 -G0 -G1 -G2" + for min_opt in $minflags; do for gen_opt in $genflags; do echo "$allow_minflags" | grep -e $min_opt >/dev/null || continue @@ -225,9 +234,12 @@ for test_case; do out_args="" [ $lang != java ] && out_args="-o ${binary}"; - echo "$compiler ${cflags} ${out_args} ${code_src}" - if ! $compiler ${cflags} ${out_args} ${code_src}; then - test_error; + # Ruby doesn't need to be compiled. + if [ $lang != ruby ]; then + echo "$compiler ${cflags} ${out_args} ${code_src}" + if ! $compiler ${cflags} ${out_args} ${code_src}; then + test_error; + fi fi if [ "$compile_only" != "true" ]; then @@ -235,7 +247,8 @@ for test_case; do exec_cmd=./$binary [ $lang = java ] && exec_cmd="java $root" - + [ $lang = ruby ] && exec_cmd="ruby ${code_src}" + $exec_cmd 2>&1 > $output; if diff $expected_out $output > /dev/null; then echo "passed"; -- 2.7.4