]> granicus.if.org Git - flex/commitdiff
Added test for #line directives.
authorJohn Millaway <john43@users.sourceforge.net>
Wed, 26 Mar 2003 03:26:50 +0000 (03:26 +0000)
committerJohn Millaway <john43@users.sourceforge.net>
Wed, 26 Mar 2003 03:26:50 +0000 (03:26 +0000)
configure.in
tests/Makefile.am
tests/descriptions
tests/test-linedir-r/.cvsignore [new file with mode: 0644]
tests/test-linedir-r/Makefile.am [new file with mode: 0644]
tests/test-linedir-r/check-lines.awk [new file with mode: 0644]
tests/test-linedir-r/main.c [new file with mode: 0644]
tests/test-linedir-r/scanner.l [new file with mode: 0644]
tests/test-linedir-r/test.input [new file with mode: 0644]

index 366aeca4f127c7704531beff088836fcc8b237ee..7742cf1db025d9c5fe8baa077638edce4cca0734 100644 (file)
@@ -111,6 +111,7 @@ tests/test-string-r/Makefile
 tests/test-yyextra/Makefile
 tests/test-lineno-nr/Makefile
 tests/test-lineno-r/Makefile
+tests/test-linedir-r/Makefile
 tests/test-debug-r/Makefile
 tests/test-debug-nr/Makefile
 tests/test-mem-nr/Makefile
index daeefcbbb1627cf55f39b58c523d2eab732c6d6f..f3d6b10bc8bd9b7624a17eecd70b43bca35563c7 100644 (file)
@@ -46,6 +46,7 @@ DIST_SUBDIRS = \
        test-debug-r \
        test-lineno-r \
        test-lineno-nr \
+       test-linedir-r \
        TEMPLATE \
        test-array-nr \
        test-array-r \
@@ -84,6 +85,7 @@ SUBDIRS = \
        test-debug-r \
        test-lineno-r \
        test-lineno-nr \
+       test-linedir-r \
        test-array-nr \
        test-array-r \
        test-c-cpp-nr \
index 90e842047b758187473a6d6e3ae96553b0abcb31..2445520193b98af7c7704c49e66c8a133155c10d 100644 (file)
@@ -10,23 +10,29 @@ bison-yylloc          - Reentrant scanner + pure parser. Requires bison.
 bison-yylval          - Reentrant scanner + pure parser. Requires bison.
 c-cpp-nr              - Compile a C scanner with C++ compiler, nonreentrant.
 c-cpp-r               - Compile a C scanner with C++ compiler, reentrant.
+c++-basic             - The C++ scanner.
+c++-multiple-scanners - Multiple C++ scanners.
 debug-nr              - Use yy_flex_debug, non-reentrant.
 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-reentrant  - Nested scanners.
+linedir-r             - Check #line directives.
 lineno-nr             - Use %option yylineno, non-reentrant.
 lineno-r              - Use %option yylineno, reentrant.
 mem-nr                - Override memory api, non-reentrant.
 mem-r                 - Override memory api, reentrant.
 multiple-scanners-nr  - #include and run two separate scanners, non-reentrant.
 multiple-scanners-r   - #include and run two separate scanners, reentrant.
+noansi-nr             - test %option noansi-*, non-reentrant.
+noansi-r              - test %option noansi-*, reentrant.
 posix                 - Test %option posix-compat.
 posixly-correct       - Test POSIXLY_CORRECT variable.
 prefix-nr             - Verify prefixes are working, nonreentrant.
 prefix-r              - Verify prefixes are working, reentrant.
 pthread               - Pthreads test. A NO-OP if libpthread not found.
+reject                - Check REJECT code.
 string-nr             - Scan strings, non-reentrant.
 string-r              - Scan strings, reentrant.
 table-opts            - Try every table compression option.
diff --git a/tests/test-linedir-r/.cvsignore b/tests/test-linedir-r/.cvsignore
new file mode 100644 (file)
index 0000000..8642445
--- /dev/null
@@ -0,0 +1,6 @@
+Makefile
+Makefile.in
+scanner.c
+scanner.h
+test-linedir-r
+OUTPUT
diff --git a/tests/test-linedir-r/Makefile.am b/tests/test-linedir-r/Makefile.am
new file mode 100644 (file)
index 0000000..f440925
--- /dev/null
@@ -0,0 +1,56 @@
+# 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
+
+builddir = @builddir@
+
+EXTRA_DIST = scanner.l test.input main.c
+CLEANFILES = scanner.c scanner.h test-linedir-r OUTPUT $(OBJS)
+OBJS = scanner.o main.o
+
+AM_CPPFLAGS = -I$(srcdir) -I$(top_srcdir) -I$(top_builddir) -I$(builddir)
+#LDFLAGS = $(top_srcdir)/libfl.a 
+LFLAGS = --header="scanner.h"
+#YFLAGS = --defines --output=parser.c
+
+testname = test-linedir-r
+
+scanner.c: $(srcdir)/scanner.l
+       $(FLEX) $(LFLAGS) $<
+
+parser.c: $(srcdir)/parser.y
+       $(BISON) $(YFLAGS) $<
+
+$(testname)$(EXEEXT): $(OBJS)
+       $(CC) -o $@ $(LDFLAGS) $(OBJS) $(LOADLIBES)
+
+test: $(testname)$(EXEEXT)
+       ./$(testname)$(EXEEXT) < $(srcdir)/test.input
+       cat -n scanner.c | grep '#line' | grep scanner.c | awk -f $(srcdir)/check-lines.awk
+       cat -n scanner.h | grep '#line' | grep scanner.h | awk -f $(srcdir)/check-lines.awk
+
+.c.o:
+       $(CC) -c -o $@ $(AM_CPPFLAGS) $(CPPFLAGS) $(CFLAGS) $<
+
+scanner.h: scanner.c
+main.o: scanner.h
diff --git a/tests/test-linedir-r/check-lines.awk b/tests/test-linedir-r/check-lines.awk
new file mode 100644 (file)
index 0000000..6a1e5ec
--- /dev/null
@@ -0,0 +1,7 @@
+{
+  if( /#line/ && $1 != ($3 - 1)) {
+    printf "Line directive mismatch at line %d: %s\n", NR, $0;
+    exit 1;
+  }
+}
+
diff --git a/tests/test-linedir-r/main.c b/tests/test-linedir-r/main.c
new file mode 100644 (file)
index 0000000..6ba9808
--- /dev/null
@@ -0,0 +1,58 @@
+/*
+ * 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 "scanner.h"
+
+int
+main ( int argc, char** argv )
+{
+    yyscan_t  scanner;
+    FILE *fp;
+    char * extra = "EXTRA";
+    
+    testlex_init(&scanner);
+    testset_in(stdin,scanner);
+    testset_out(stdout,scanner);    
+    testset_extra(extra,scanner);
+    
+    fp = testget_in(scanner);
+    fp = testget_out(scanner);
+
+    while(testlex(scanner)) {
+        char * text;
+        int line;
+        line = testget_lineno(scanner);
+        text = testget_text(scanner);
+        
+        if( (char*)testget_extra(scanner) != extra)
+            break;
+        
+        if ( !text || line < 0)
+            continue;
+    }
+    testlex_destroy(scanner);
+    return 0;
+}
+
+
+/* vim:set tabstop=8 softtabstop=4 shiftwidth=4: */
diff --git a/tests/test-linedir-r/scanner.l b/tests/test-linedir-r/scanner.l
new file mode 100644 (file)
index 0000000..e87cc60
--- /dev/null
@@ -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.
+ */
+
+%{
+/* Build "scanner.c". 
+   The scanner is not important. 
+   This test is really about getting the line directives correct.
+*/
+#include <stdio.h>
+#include <stdlib.h>
+#include "config.h"
+
+%}
+
+%option reentrant
+%option 8bit outfile="scanner.c" prefix="test"
+%option nounput nomain noyywrap 
+%option warn
+
+%%
+
+.|\n              { }
+
+%%
+
diff --git a/tests/test-linedir-r/test.input b/tests/test-linedir-r/test.input
new file mode 100644 (file)
index 0000000..2ce5001
--- /dev/null
@@ -0,0 +1,3 @@
+Any input is ok for this scanner.
+We only care if it links.
+