From dd7eda5be09771a831a80215e0e44dd0c47823c2 Mon Sep 17 00:00:00 2001 From: Will Estes Date: Tue, 1 Jul 2014 20:56:44 -0400 Subject: refactor lineno_r test for new test suite layout --- tests/.gitignore | 2 + tests/Makefile.am | 5 ++- tests/lineno_r.l | 97 +++++++++++++++++++++++++++++++++++++++++ tests/lineno_r.one.txt | 19 ++++++++ tests/test-lineno-r/.gitignore | 8 ---- tests/test-lineno-r/Makefile.am | 45 ------------------- tests/test-lineno-r/scanner.l | 97 ----------------------------------------- tests/test-lineno-r/test.input | 19 -------- 8 files changed, 122 insertions(+), 170 deletions(-) create mode 100644 tests/lineno_r.l create mode 100644 tests/lineno_r.one.txt delete mode 100644 tests/test-lineno-r/.gitignore delete mode 100644 tests/test-lineno-r/Makefile.am delete mode 100644 tests/test-lineno-r/scanner.l delete mode 100644 tests/test-lineno-r/test.input diff --git a/tests/.gitignore b/tests/.gitignore index 853a1a8..618c6af 100644 --- a/tests/.gitignore +++ b/tests/.gitignore @@ -51,6 +51,8 @@ include_by_reentrant.direct include_by_reentrant.direct.c lineno_nr.one lineno_nr.c +lineno_r.one +lineno_r.c mem_nr mem_nr.c mem_r diff --git a/tests/Makefile.am b/tests/Makefile.am index 5847359..03fd1a3 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -114,7 +114,8 @@ PTHREAD_TESTS = \ pthread.pthread ONE_TESTS = \ - lineno_nr.one + lineno_nr.one \ + lineno_r.one alloc_extra_SOURCES = alloc_extra.l array_nr_SOURCES = array_nr.l @@ -139,6 +140,7 @@ include_by_buffer_direct_SOURCES = include_by_buffer.direct.l include_by_push_direct_SOURCES = include_by_push.direct.l include_by_reentrant_direct_SOURCES = include_by_reentrant.direct.l lineno_nr_one_SOURCES = lineno_nr.l +lineno_r_one_SOURCES = lineno_r.l mem_nr_SOURCES = mem_nr.l mem_r_SOURCES = mem_r.l multiple_scanners_nr_SOURCES = multiple_scanners_nr_main.c multiple_scanners_nr_1.l multiple_scanners_nr_2.l @@ -222,6 +224,7 @@ basic_nr.txt \ include_by_reentrant.direct_2.txt \ include_by_reentrant.direct_3.txt \ lineno_nr.one.txt \ + lineno_r.one.txt \ mem_nr.txt \ mem_r.txt \ noansi_nr.txt \ diff --git a/tests/lineno_r.l b/tests/lineno_r.l new file mode 100644 index 0000000..4132ed3 --- /dev/null +++ b/tests/lineno_r.l @@ -0,0 +1,97 @@ +/* + * 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 template scanner file to build "scanner.c". + Run as: + test-lineno-r # report flex's yylineno + test-lineno-r 1 # report count_newlines(stdin) +*/ + +#include +#include +#include "config.h" + +%} + +%option 8bit prefix="test" +%option nounput nomain noyywrap yylineno reentrant +%option warn + +WORD [[:alpha:]]+ +DIGIT [[:digit:]] + +%% + /* The goal here is to test the yylineno processing by: + - providing some rules than CAN match newlines and + other rules that can NOT match newlines, + - matching several newlines in one rule, + - directly modifying yylineno. + */ + +"yylineno++" yylineno++; +"yylineno--" yylineno--; +[[:blank:]]+ +{WORD} +{DIGIT}+(\n{DIGIT}+)* +\n +. +<> { printf("%d\n", yylineno); + yyterminate(); + } + +%% + +/* returns number of '\n' characters in input, plus one. + This is what flex does, essentially. */ + +static int +count_newlines (FILE* in) +{ + int n=1,c; + while ((c=fgetc(in)) != EOF) + if( c == '\n') + n++; + return n; +} + +int main ( int argc, char** argv ); + +int +main (argc, argv) + int argc; + char ** argv; +{ + if( argc > 1 ) + printf("%d\n", count_newlines(stdin)); + + else{ + yyscan_t s; + yylex_init(&s); + yyset_in(stdin,s); + yyset_out(stdout,s); + yylex(s); + yylex_destroy(s); + } + return 0; +} diff --git a/tests/lineno_r.one.txt b/tests/lineno_r.one.txt new file mode 100644 index 0000000..c1eb961 --- /dev/null +++ b/tests/lineno_r.one.txt @@ -0,0 +1,19 @@ +These words +are separated +by newlines +and sometimes + spaces +too. +The next three lines are numbers with only intervening newlines +01123 +581321 +34 +And now for some blank lines.... + + +Finally, we directly modify yylineno, but then change it back afterwards +(see scanner.l): + +yylineno++ + +yylineno-- diff --git a/tests/test-lineno-r/.gitignore b/tests/test-lineno-r/.gitignore deleted file mode 100644 index 9c9f4d0..0000000 --- a/tests/test-lineno-r/.gitignore +++ /dev/null @@ -1,8 +0,0 @@ -Makefile -Makefile.in -parser.c -parser.h -scanner.c -test-lineno-r -OUTPUT -.deps diff --git a/tests/test-lineno-r/Makefile.am b/tests/test-lineno-r/Makefile.am deleted file mode 100644 index 8ded4b3..0000000 --- a/tests/test-lineno-r/Makefile.am +++ /dev/null @@ -1,45 +0,0 @@ -# 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.c $(testname)$(EXEEXT) OUTPUT $(OBJS) -OBJS = scanner.o - -AM_CPPFLAGS = -I$(srcdir) -I$(top_srcdir) -I$(top_builddir) - -testname = test-lineno-r - -scanner.c: $(srcdir)/scanner.l - $(FLEX) $(LFLAGS) $< - - -$(testname)$(EXEEXT): $(OBJS) - $(CC) $(CFLAGS) -o $@ $(LDFLAGS) $(OBJS) $(LOADLIBES) - -test: $(testname)$(EXEEXT) - test `./$(testname)$(EXEEXT) < $(srcdir)/test.input` -eq \ - `./$(testname)$(EXEEXT) 1 < $(srcdir)/test.input` || exit 1 - -.c.o: - $(CC) -c -o $@ $(AM_CPPFLAGS) $(CPPFLAGS) $(CFLAGS) $< diff --git a/tests/test-lineno-r/scanner.l b/tests/test-lineno-r/scanner.l deleted file mode 100644 index 8933f5f..0000000 --- a/tests/test-lineno-r/scanner.l +++ /dev/null @@ -1,97 +0,0 @@ -/* - * 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 template scanner file to build "scanner.c". - Run as: - test-lineno-r # report flex's yylineno - test-lineno-r 1 # report count_newlines(stdin) -*/ - -#include -#include -#include "config.h" - -%} - -%option 8bit outfile="scanner.c" prefix="test" -%option nounput nomain noyywrap yylineno reentrant -%option warn - -WORD [[:alpha:]]+ -DIGIT [[:digit:]] - -%% - /* The goal here is to test the yylineno processing by: - - providing some rules than CAN match newlines and - other rules that can NOT match newlines, - - matching several newlines in one rule, - - directly modifying yylineno. - */ - -"yylineno++" yylineno++; -"yylineno--" yylineno--; -[[:blank:]]+ -{WORD} -{DIGIT}+(\n{DIGIT}+)* -\n -. -<> { printf("%d\n", yylineno); - yyterminate(); - } - -%% - -/* returns number of '\n' characters in input, plus one. - This is what flex does, essentially. */ - -static int -count_newlines (FILE* in) -{ - int n=1,c; - while ((c=fgetc(in)) != EOF) - if( c == '\n') - n++; - return n; -} - -int main ( int argc, char** argv ); - -int -main (argc, argv) - int argc; - char ** argv; -{ - if( argc > 1 ) - printf("%d\n", count_newlines(stdin)); - - else{ - yyscan_t s; - yylex_init(&s); - yyset_in(stdin,s); - yyset_out(stdout,s); - yylex(s); - yylex_destroy(s); - } - return 0; -} diff --git a/tests/test-lineno-r/test.input b/tests/test-lineno-r/test.input deleted file mode 100644 index c1eb961..0000000 --- a/tests/test-lineno-r/test.input +++ /dev/null @@ -1,19 +0,0 @@ -These words -are separated -by newlines -and sometimes - spaces -too. -The next three lines are numbers with only intervening newlines -01123 -581321 -34 -And now for some blank lines.... - - -Finally, we directly modify yylineno, but then change it back afterwards -(see scanner.l): - -yylineno++ - -yylineno-- -- cgit v1.2.3