From 3ad7f6b2592ce4404c7f72ac92e90b7bfe090d35 Mon Sep 17 00:00:00 2001 From: Will Estes Date: Fri, 20 Oct 2006 17:10:50 +0000 Subject: add unit test for c++ with yywrap --- NEWS | 3 ++ configure.in | 1 + tests/Makefile.am | 2 ++ tests/descriptions | 1 + tests/test-c++-yywrap/.cvsignore | 6 ++++ tests/test-c++-yywrap/Makefile.am | 45 +++++++++++++++++++++++++ tests/test-c++-yywrap/scanner.l | 70 +++++++++++++++++++++++++++++++++++++++ tests/test-c++-yywrap/test.input | 2 ++ 8 files changed, 130 insertions(+) create mode 100644 tests/test-c++-yywrap/.cvsignore create mode 100644 tests/test-c++-yywrap/Makefile.am create mode 100644 tests/test-c++-yywrap/scanner.l create mode 100644 tests/test-c++-yywrap/test.input diff --git a/NEWS b/NEWS index 7862262..4a72d2a 100644 --- a/NEWS +++ b/NEWS @@ -4,6 +4,9 @@ changes between releases of flex. See the file COPYING for copying conditions. * after version 2.5.33 + +* added new unit test for c++ and yywrap + ** portability fixes to some unit tests ** new ca, vi, ga, nl translations from the translation project diff --git a/configure.in b/configure.in index 03fc350..16c995c 100644 --- a/configure.in +++ b/configure.in @@ -149,6 +149,7 @@ tests/test-rescan-r/Makefile tests/test-quotes/Makefile tests/test-ccl/Makefile tests/test-extended/Makefile +tests/test-c++-yywrap/Makefile dnl --new-test-here-- This line is processed by tests/create-test. ) diff --git a/tests/Makefile.am b/tests/Makefile.am index c9d970d..744761a 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -26,6 +26,7 @@ dist_noinst_SCRIPTS = \ create-test DIST_SUBDIRS = \ + test-c++-yywrap \ test-extended \ test-ccl \ test-quotes \ @@ -72,6 +73,7 @@ DIST_SUBDIRS = \ test-table-opts SUBDIRS = \ + test-c++-yywrap \ test-extended \ test-ccl \ test-quotes \ diff --git a/tests/descriptions b/tests/descriptions index 9bf891a..b263bbb 100644 --- a/tests/descriptions +++ b/tests/descriptions @@ -44,3 +44,4 @@ string-r - Scan strings, reentrant. table-opts - Try every table compression option. top - Test %top directive. yyextra - Test yyextra. +c++-yywrap - test yywrap in c++ scanner diff --git a/tests/test-c++-yywrap/.cvsignore b/tests/test-c++-yywrap/.cvsignore new file mode 100644 index 0000000..31ef089 --- /dev/null +++ b/tests/test-c++-yywrap/.cvsignore @@ -0,0 +1,6 @@ +Makefile +Makefile.in +scanner.cpp +OUTPUT +.deps +test-c++-yywrap diff --git a/tests/test-c++-yywrap/Makefile.am b/tests/test-c++-yywrap/Makefile.am new file mode 100644 index 0000000..2929f28 --- /dev/null +++ b/tests/test-c++-yywrap/Makefile.am @@ -0,0 +1,45 @@ +# This file is part of flex. + +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: + +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. + +# Neither the name of the University nor the names of its contributors +# may be used to endorse or promote products derived from this software +# without specific prior written permission. + +# THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR +# IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED +# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +# PURPOSE. + + +FLEX = $(top_builddir)/flex + +EXTRA_DIST = scanner.l test.input +CLEANFILES = scanner.cpp scanner.h test-c++-yywrap OUTPUT $(OBJS) +OBJS = scanner.o + +AM_CPPFLAGS = -I$(srcdir) -I$(top_srcdir) -I$(top_builddir) +LFLAGS = -+ +#LDFLAGS = + +testname = test-c++-yywrap + +scanner.cpp: $(srcdir)/scanner.l + $(FLEX) $(LFLAGS) $< + +$(testname)$(EXEEXT): $(OBJS) + $(CXX) -o $@ $(LDFLAGS) $(OBJS) + +test: $(testname)$(EXEEXT) + ./$(testname)$(EXEEXT) $(srcdir)/test.input $(srcdir)/test.input $(srcdir)/test.input + +.cpp.o: + $(CXX) -c -o $@ $(AM_CPPFLAGS) $(CPPFLAGS) $(CFLAGS) $< diff --git a/tests/test-c++-yywrap/scanner.l b/tests/test-c++-yywrap/scanner.l new file mode 100644 index 0000000..433ad08 --- /dev/null +++ b/tests/test-c++-yywrap/scanner.l @@ -0,0 +1,70 @@ +/* + * This file is part of flex. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE. + */ + +%{ + +#include "config.h" +#include + +%} + +%option 8bit outfile="scanner.cpp" prefix="test" +%option nounput nomain +%option warn c++ + + +%% + +. { } + +%% + +#define MAX_FILES 10 + +char *files[MAX_FILES] = { 0 }; +int filecounter = 0; + +int testFlexLexer::yywrap() +{ + if (filecounter-- > 0) { + std::cout << "NOW WRAPPING TO READ " << files[filecounter] << std::endl; + std::ifstream *ifs = new std::ifstream(files[filecounter]); + switch_streams(ifs); + return 0; + } + return 1; +} + +int +main (int argc, char *argv[]) +{ + for (int i = 1; i < argc && i <= MAX_FILES; i++) { + files[i-1] = argv[i]; + filecounter++; + } + testFlexLexer* f = new testFlexLexer; + f->yywrap(); + f->yylex(); + std::cout << "TEST RETURNING OK." << std::endl; + return 0; +} diff --git a/tests/test-c++-yywrap/test.input b/tests/test-c++-yywrap/test.input new file mode 100644 index 0000000..7288a40 --- /dev/null +++ b/tests/test-c++-yywrap/test.input @@ -0,0 +1,2 @@ +0000 foo 1111 foo 0000 bar +0000 foo 1111 foo 0000 bar -- cgit v1.2.3