From 70ffad386cb9f9e6cf7274fe27bf0912a28a64c6 Mon Sep 17 00:00:00 2001 From: John Millaway Date: Wed, 26 Mar 2003 16:52:53 +0000 Subject: Added test for yypush_buffer_state and yypop_buffer_state. --- TODO | 2 - configure.in | 1 + tests/Makefile.am | 2 + tests/descriptions | 1 + tests/test-include-by-push/.cvsignore | 7 +++ tests/test-include-by-push/Makefile.am | 49 ++++++++++++++++++ tests/test-include-by-push/scanner.l | 92 +++++++++++++++++++++++++++++++++ tests/test-include-by-push/test-1.input | 3 ++ tests/test-include-by-push/test-2.input | 3 ++ tests/test-include-by-push/test-3.input | 2 + 10 files changed, 160 insertions(+), 2 deletions(-) create mode 100644 tests/test-include-by-push/.cvsignore create mode 100644 tests/test-include-by-push/Makefile.am create mode 100644 tests/test-include-by-push/scanner.l create mode 100644 tests/test-include-by-push/test-1.input create mode 100644 tests/test-include-by-push/test-2.input create mode 100644 tests/test-include-by-push/test-3.input diff --git a/TODO b/TODO index c1102bc..eb4ba31 100644 --- a/TODO +++ b/TODO @@ -54,8 +54,6 @@ ** make test suite more complete -*** add a test for yypush_buffer_state/yypop_buffer_state - * generic coding ** move as much skeleton code as possible out of gen.c and into diff --git a/configure.in b/configure.in index 7742cf1..e18a0ea 100644 --- a/configure.in +++ b/configure.in @@ -98,6 +98,7 @@ tests/test-c-cpp-r/Makefile tests/test-header-nr/Makefile tests/test-header-r/Makefile tests/test-include-by-buffer/Makefile +tests/test-include-by-push/Makefile tests/test-include-by-reentrant/Makefile tests/test-multiple-scanners-nr/Makefile tests/test-multiple-scanners-r/Makefile diff --git a/tests/Makefile.am b/tests/Makefile.am index f3d6b10..b5c96c3 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -53,6 +53,7 @@ DIST_SUBDIRS = \ test-c-cpp-nr \ test-c-cpp-r \ test-include-by-buffer \ + test-include-by-push \ test-include-by-reentrant \ test-prefix-nr \ test-prefix-r \ @@ -91,6 +92,7 @@ SUBDIRS = \ test-c-cpp-nr \ test-c-cpp-r \ test-include-by-buffer \ + test-include-by-push \ test-include-by-reentrant \ test-prefix-nr \ test-prefix-r \ diff --git a/tests/descriptions b/tests/descriptions index 2445520..4b45b74 100644 --- a/tests/descriptions +++ b/tests/descriptions @@ -17,6 +17,7 @@ debug-r - Use debugging functions, reentrant. header-nr - Test generated header file, non-reentrant. header-r - Test generated header file, reentrant. include-by-buffer - YY_BUFFER_STATE, yy_push_state, etc. +include-by-push - yypush_buffer_state, yypop_buffer_state include-by-reentrant - Nested scanners. linedir-r - Check #line directives. lineno-nr - Use %option yylineno, non-reentrant. diff --git a/tests/test-include-by-push/.cvsignore b/tests/test-include-by-push/.cvsignore new file mode 100644 index 0000000..7a7c74b --- /dev/null +++ b/tests/test-include-by-push/.cvsignore @@ -0,0 +1,7 @@ +Makefile +Makefile.in +parser.c +parser.h +scanner.c +test-include-by-push +OUTPUT diff --git a/tests/test-include-by-push/Makefile.am b/tests/test-include-by-push/Makefile.am new file mode 100644 index 0000000..46f700d --- /dev/null +++ b/tests/test-include-by-push/Makefile.am @@ -0,0 +1,49 @@ +# 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-1.input test-2.input test-3.input +CLEANFILES = scanner.c scanner.h parser.c parser.h test-include-by-push OUTPUT $(OBJS) +OBJS = scanner.o # parser.o + +AM_CPPFLAGS = -I$(srcdir) -I$(top_srcdir) -I$(top_builddir) +#LDFLAGS = $(top_srcdir)/libfl.a +#LFLAGS = --header="scanner.h" +#YFLAGS = --defines --output=parser.c + +testname = test-include-by-push + +scanner.c: $(srcdir)/scanner.l + $(FLEX) $< + +parser.c: $(srcdir)/parser.y + $(BISON) $(YFLAGS) $< + +$(testname)$(EXEEXT): $(OBJS) + $(CC) -o $@ $(LDFLAGS) $(OBJS) $(LOADLIBES) + +test: $(testname)$(EXEEXT) + ./$(testname)$(EXEEXT) $(srcdir)/test-1.input + +.c.o: + $(CC) -c -o $@ $(AM_CPPFLAGS) $(CPPFLAGS) $(CFLAGS) $< diff --git a/tests/test-include-by-push/scanner.l b/tests/test-include-by-push/scanner.l new file mode 100644 index 0000000..8556152 --- /dev/null +++ b/tests/test-include-by-push/scanner.l @@ -0,0 +1,92 @@ +/* + * 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. + */ + +%{ +/* A scanner file to build "scanner.c". + Input language is any text. + "#include " causes a buffer switch. + */ +#include +#include +#include "config.h" +%} + +%option 8bit outfile="scanner.c" prefix="test" +%option nounput nomain noyywrap +%option warn + +%x GET_FILENAME + +%% + +{ +^"#include"[[:blank:]]+"<" { BEGIN(GET_FILENAME); } +.|\n { ECHO; } +} + +{ +[[:alnum:]_.-]+> { + /* recurse */ + yytext[yyleng-1]='\0'; + if((yyin=fopen(yytext,"r"))==NULL) { + fprintf(stderr,"*** Error: Could not open include file \"%s\".\n",yytext); + yyterminate(); + } + yypush_buffer_state( yy_create_buffer( yyin, YY_BUF_SIZE )); + BEGIN(0); + } +.|\n { + fprintf(stderr,"Invalid input \"%s\".\n", yytext); + yyterminate(); + } +} + +<> { + fclose(yyin); + yypop_buffer_state(); + if(!YY_CURRENT_BUFFER) + yyterminate(); + } + +%% + +int main(int argc, char** argv); + +int +main ( int argc, char** argv ) +{ + FILE * fp; + if( argc != 2 ) { + fprintf(stderr,"*** Error: Must specifiy one filename.\n"); + exit(-1); + } + if((fp=fopen(argv[1],"r"))==NULL) { + fprintf(stderr,"*** Error: fopen(%s) failed.\n",argv[1]); + exit(-1); + } + yyin = fp; + yyout = stdout; + yylex(); + printf("TEST RETURNING OK.\n"); + return 0; +} diff --git a/tests/test-include-by-push/test-1.input b/tests/test-include-by-push/test-1.input new file mode 100644 index 0000000..355beaa --- /dev/null +++ b/tests/test-include-by-push/test-1.input @@ -0,0 +1,3 @@ +Beginning of "test-1.input". +#include +End of "test-1.input". diff --git a/tests/test-include-by-push/test-2.input b/tests/test-include-by-push/test-2.input new file mode 100644 index 0000000..45f11f9 --- /dev/null +++ b/tests/test-include-by-push/test-2.input @@ -0,0 +1,3 @@ +Beginning of "test-2.input". +#include +End of "test-2.input". diff --git a/tests/test-include-by-push/test-3.input b/tests/test-include-by-push/test-3.input new file mode 100644 index 0000000..6a2d055 --- /dev/null +++ b/tests/test-include-by-push/test-3.input @@ -0,0 +1,2 @@ +Beginning of "test-3.input". +End of "test-3.input". -- cgit v1.2.3