From ea3edb34c48829d66a225f23077d6d0e29eb2746 Mon Sep 17 00:00:00 2001 From: John Millaway Date: Thu, 21 Feb 2002 05:12:10 +0000 Subject: [PATCH] Added test-c-cpp-nr and test-c-cpp-r. --- tests/README | 7 +++- tests/TEMPLATE/Makefile.in | 3 +- tests/configure.in | 6 ++-- tests/test-c-cpp-nr/.cvsignore | 4 +++ tests/test-c-cpp-nr/Makefile.in | 60 ++++++++++++++++++++++++++++++++ tests/test-c-cpp-nr/scanner.l | 31 +++++++++++++++++ tests/test-c-cpp-nr/test.input | 2 ++ tests/test-c-cpp-r/.cvsignore | 4 +++ tests/test-c-cpp-r/Makefile.in | 61 +++++++++++++++++++++++++++++++++ tests/test-c-cpp-r/scanner.l | 36 +++++++++++++++++++ tests/test-c-cpp-r/test.input | 2 ++ 11 files changed, 212 insertions(+), 4 deletions(-) create mode 100644 tests/test-c-cpp-nr/.cvsignore create mode 100644 tests/test-c-cpp-nr/Makefile.in create mode 100644 tests/test-c-cpp-nr/scanner.l create mode 100644 tests/test-c-cpp-nr/test.input create mode 100644 tests/test-c-cpp-r/.cvsignore create mode 100644 tests/test-c-cpp-r/Makefile.in create mode 100644 tests/test-c-cpp-r/scanner.l create mode 100644 tests/test-c-cpp-r/test.input diff --git a/tests/README b/tests/README index 031cc99..24d0534 100644 --- a/tests/README +++ b/tests/README @@ -30,6 +30,9 @@ To build and execute a single test: HOW TO ADD A NEW TEST + - Run the perl script `create-test.pl` found in this directory. + If it works, skip the next step. + - Copy the tests/TEMPLATE directory, then modify the skeleton scanner (and parser if necessary). If you are submitting a patch for inclusion in the flex distribution, then move the file "cvsignore" @@ -49,6 +52,7 @@ HOW TO ADD A NEW TEST - You must modify the last few lines of tests/configure.in by adding your new test directory, and the Makefile target. + (This step is done automatically by `create-test.pl`.) - Each test assumes that the newly-built binary "flex" is in the directory above the tests directory. @@ -73,4 +77,5 @@ DESCRIPTION OF TESTS pthread - pthreads test. A NO-OP if libpthread not found. string-nr - Scan strings, non-reentrant. string-r - Scan strings, reentrant. - yyextra - User-specific data in reentrant scanner. + c-cpp-nr - Compile a C scanner with C++ compiler, nonreentrant. + c-cpp-r - Compile a C scanner with C++ compiler, reentrant. diff --git a/tests/TEMPLATE/Makefile.in b/tests/TEMPLATE/Makefile.in index 1a8260c..61ddc95 100644 --- a/tests/TEMPLATE/Makefile.in +++ b/tests/TEMPLATE/Makefile.in @@ -22,6 +22,7 @@ VPATH = @srcdir@ LN_S = @LN_S@ YACC = @YACC@ CC = @CC@ +CXX = @CXX@ AR = ar RANLIB = @RANLIB@ YACC = @YACC@ @@ -30,7 +31,7 @@ YACC = @YACC@ TESTNAME = TEMPLATE FLEX = ../../flex YFLAGS = --defines --output-file="parser.c" --name-prefix="test" -OBJS = scanner.o # parser.o +OBJS = scanner.o # Force YACC to be bison (autoconf generates 'bison -y') YACC = @BISON@ diff --git a/tests/configure.in b/tests/configure.in index faaf161..950ec7e 100644 --- a/tests/configure.in +++ b/tests/configure.in @@ -10,6 +10,7 @@ AC_CHECK_LIB(pthread, pthread_create) AC_LN_S AC_PROG_YACC AC_PROG_CC +AC_PROG_CXX AC_PROG_RANLIB AC_PROG_INSTALL AC_PROG_MAKE_SET @@ -44,7 +45,7 @@ TESTDIRS="test-string-r test-pthread \ test-bison-yylloc test-yyextra test-prefix-nr \ test-prefix-r test-header-nr test-header-r \ test-multiple-scanners-nr test-multiple-scanners-r \ - test-array-nr test-array-r" + test-array-nr test-array-r test-c-cpp-nr test-c-cpp-r" AC_OUTPUT( Makefile test-string-r/Makefile test-pthread/Makefile test-bison-yylval/Makefile test-include-by-reentrant/Makefile @@ -54,4 +55,5 @@ AC_OUTPUT( Makefile test-string-r/Makefile test-pthread/Makefile test-prefix-nr/Makefile test-prefix-r/Makefile test-header-nr/Makefile test-header-r/Makefile test-multiple-scanners-nr/Makefile test-multiple-scanners-r/Makefile - test-array-nr/Makefile test-array-r/Makefile) + test-array-nr/Makefile test-array-r/Makefile test-c-cpp-nr/Makefile + test-c-cpp-r/Makefile) diff --git a/tests/test-c-cpp-nr/.cvsignore b/tests/test-c-cpp-nr/.cvsignore new file mode 100644 index 0000000..3c7e442 --- /dev/null +++ b/tests/test-c-cpp-nr/.cvsignore @@ -0,0 +1,4 @@ +Makefile +scanner.c +test-c-cpp-nr +OUTPUT diff --git a/tests/test-c-cpp-nr/Makefile.in b/tests/test-c-cpp-nr/Makefile.in new file mode 100644 index 0000000..4275e5f --- /dev/null +++ b/tests/test-c-cpp-nr/Makefile.in @@ -0,0 +1,60 @@ +# Makefile.in for a single TEST. +# +# By default this Makefile will build the target "$(TESTNAME)" +# from the sources "scanner.l" and "parser.y". +# +# $(TESTNAME) is supplied by the calling Makefile. +# "parser.y" is not necessary. You may delete this file +# if you do not require a parser. +# "scanner.l" is necessary. It should build "scanner.c". +# + +@SET_MAKE@ + +CFLAGS = @CFLAGS@ +CPPFLAGS = @CPPFLAGS@ -I. -I"@srcdir@" -I.. +DEFS = @DEFS@ +LDFLAGS = @LDFLAGS@ +LIBS = @LIBS@ +SHELL = /bin/sh +srcdir = @srcdir@ +VPATH = @srcdir@ +LN_S = @LN_S@ +YACC = @YACC@ +CC = @CC@ +CXX = @CXX@ +AR = ar +RANLIB = @RANLIB@ +YACC = @YACC@ + +# Edit these if necessary for your specific test. +TESTNAME = test-c-cpp-nr +FLEX = ../../flex +YFLAGS = --defines --output-file="parser.c" --name-prefix="test" +OBJS = scanner.o # parser.o + +# Force YACC to be bison (autoconf generates 'bison -y') +YACC = @BISON@ + +all: $(TESTNAME) + +$(TESTNAME): $(OBJS) + $(CXX) $(CFLAGS) -o $(TESTNAME) $(OBJS) $(LDFLAGS) $(LIBS) + +scanner.c: $(srcdir)/scanner.l + $(FLEX) $(srcdir)/scanner.l + +scanner.o: scanner.c + $(CXX) $(CPPFLAGS) $(CFLAGS) -c scanner.c + +test: check + +check: $(TESTNAME) + ./$(TESTNAME) < $(srcdir)/test.input + +distclean: clean + rm -f Makefile + +clean: + rm -f scanner.o scanner.c parser.o parser.c parser.h parser.h $(TESTNAME) OUTPUT + diff --git a/tests/test-c-cpp-nr/scanner.l b/tests/test-c-cpp-nr/scanner.l new file mode 100644 index 0000000..be66ffb --- /dev/null +++ b/tests/test-c-cpp-nr/scanner.l @@ -0,0 +1,31 @@ +%{ +/* A template scanner file to build "scanner.c". + The scanner is not really important -- we only care if + it compiles under a c++ compiler, and runs. */ +#include +#include +#include "config.h" +/*#include "parser.h" */ + +%} + +%option 8bit outfile="scanner.c" prefix="test" +%option nounput nomain noyywrap +%option warn + + +%% + +. { } + +%% + +int +main ( int argc, char** argv ) +{ + yyin = stdin; + yyout = stdout; + yylex(); + printf("TEST RETURNING OK.\n"); + return 0; +} diff --git a/tests/test-c-cpp-nr/test.input b/tests/test-c-cpp-nr/test.input new file mode 100644 index 0000000..7288a40 --- /dev/null +++ b/tests/test-c-cpp-nr/test.input @@ -0,0 +1,2 @@ +0000 foo 1111 foo 0000 bar +0000 foo 1111 foo 0000 bar diff --git a/tests/test-c-cpp-r/.cvsignore b/tests/test-c-cpp-r/.cvsignore new file mode 100644 index 0000000..d13057e --- /dev/null +++ b/tests/test-c-cpp-r/.cvsignore @@ -0,0 +1,4 @@ +Makefile +scanner.c +test-c-cpp-r +OUTPUT diff --git a/tests/test-c-cpp-r/Makefile.in b/tests/test-c-cpp-r/Makefile.in new file mode 100644 index 0000000..50281f9 --- /dev/null +++ b/tests/test-c-cpp-r/Makefile.in @@ -0,0 +1,61 @@ +# Makefile.in for a single TEST. +# +# By default this Makefile will build the target "$(TESTNAME)" +# from the sources "scanner.l" and "parser.y". +# +# $(TESTNAME) is supplied by the calling Makefile. +# "parser.y" is not necessary. You may delete this file +# if you do not require a parser. +# "scanner.l" is necessary. It should build "scanner.c". +# + +@SET_MAKE@ + +CFLAGS = @CFLAGS@ +CPPFLAGS = @CPPFLAGS@ -I. -I"@srcdir@" -I.. +DEFS = @DEFS@ +LDFLAGS = @LDFLAGS@ +LIBS = @LIBS@ +SHELL = /bin/sh +srcdir = @srcdir@ +VPATH = @srcdir@ +LN_S = @LN_S@ +YACC = @YACC@ +CC = @CC@ +CXX = @CXX@ +CXXFLAGS = @CXXFLAGS@ -I. -I"@srcdir@" -I.. +AR = ar +RANLIB = @RANLIB@ +YACC = @YACC@ + +# Edit these if necessary for your specific test. +TESTNAME = test-c-cpp-r +FLEX = ../../flex +YFLAGS = --defines --output-file="parser.c" --name-prefix="test" +OBJS = scanner.o # parser.o + +# Force YACC to be bison (autoconf generates 'bison -y') +YACC = @BISON@ + +all: $(TESTNAME) + +$(TESTNAME): $(OBJS) + $(CXX) $(CXXFLAGS) -o $(TESTNAME) $(OBJS) $(LDFLAGS) $(LIBS) + +scanner.c: $(srcdir)/scanner.l + $(FLEX) $(srcdir)/scanner.l + +scanner.o: scanner.c + $(CXX) $(CXXFLAGS) -c scanner.c + +test: check + +check: $(TESTNAME) + ./$(TESTNAME) < $(srcdir)/test.input + +distclean: clean + rm -f Makefile + +clean: + rm -f scanner.o scanner.c parser.o parser.c parser.h parser.h $(TESTNAME) OUTPUT + diff --git a/tests/test-c-cpp-r/scanner.l b/tests/test-c-cpp-r/scanner.l new file mode 100644 index 0000000..e4e0749 --- /dev/null +++ b/tests/test-c-cpp-r/scanner.l @@ -0,0 +1,36 @@ +%{ +/* A template scanner file to build "scanner.c". + The scanner is not really important -- we only care if + it compiles under a c++ compiler, and runs. */ +#include +#include +#include "config.h" +/*#include "parser.h" */ + +%} + +%option 8bit outfile="scanner.c" prefix="test" +%option nounput nomain noyywrap +%option warn reentrant + + +%% + +. { } + +%% + +int +main ( int argc, char** argv ) +{ + yyscan_t lexer; + yylex_init( &lexer ); + yyset_out ( stdout,lexer); + yyset_in ( stdin, lexer); + while( yylex(lexer) ) + { + } + yylex_destroy( lexer ); + printf("TEST RETURNING OK.\n"); + return 0; +} diff --git a/tests/test-c-cpp-r/test.input b/tests/test-c-cpp-r/test.input new file mode 100644 index 0000000..7288a40 --- /dev/null +++ b/tests/test-c-cpp-r/test.input @@ -0,0 +1,2 @@ +0000 foo 1111 foo 0000 bar +0000 foo 1111 foo 0000 bar -- 2.40.0