automake-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[FYI] {maint} coverage: using multiple lexers in a single program


From: Stefano Lattarini
Subject: [FYI] {maint} coverage: using multiple lexers in a single program
Date: Sat, 12 Jan 2013 17:36:04 +0100

Using Flex and Automake built-in support for lex, that is possible.
A little tricky, but not difficult.

See:
<http://lists.gnu.org/archive/html/automake/2010-10/msg00081.html>
<http://lists.gnu.org/archive/html/automake/2009-03/msg00061.html>

* t/lex-multiple.sh: New test.
* t/list-of-tests.mk: Add it.

Signed-off-by: Stefano Lattarini <address@hidden>
---
 t/lex-multiple.sh  | 107 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 t/list-of-tests.mk |   1 +
 2 files changed, 108 insertions(+)
 create mode 100755 t/lex-multiple.sh

diff --git a/t/lex-multiple.sh b/t/lex-multiple.sh
new file mode 100755
index 0000000..e1c71a1
--- /dev/null
+++ b/t/lex-multiple.sh
@@ -0,0 +1,107 @@
+#! /bin/sh
+# Copyright (C) 2012 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+# Check that we can build a program using several lexers at once
+# (assuming Flex is used).  That is a little tricky, but possible.
+# See:
+# <http://lists.gnu.org/archive/html/automake/2010-10/msg00081.html>
+# <http://lists.gnu.org/archive/html/automake/2009-03/msg00061.html>
+
+required='cc flex'
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_PROG_CC
+AC_PROG_LEX
+AM_PROG_AR
+AC_PROG_RANLIB
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+bin_PROGRAMS = zardoz
+
+zardoz_SOURCES = main.c
+# Convenience libraries.
+noinst_LIBRARIES = liblex.a liblex-foo.a liblex-bar.a
+zardoz_LDADD = $(noinst_LIBRARIES)
+
+liblex_a_SOURCES = 0.l
+
+# We need the output to always be named 'lex.yy.c', in order for
+# ylwrap to pick it up.
+liblex_foo_a_LFLAGS = -Pfoo --outfile=lex.yy.c
+liblex_foo_a_SOURCES = a.l
+
+# Ditto.
+liblex_bar_a_LFLAGS = -Pbar_ --outfile=lex.yy.c
+liblex_bar_a_SOURCES = b.l
+END
+
+cat > main.c << 'END'
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+int main (int argc, char *argv[])
+{
+  if (argc != 2)
+    abort ();
+  else if (!strcmp(argv[1], "--vanilla"))
+    return (yylex () != 121);
+  else if (!strcmp(argv[1], "--foo"))
+    return (foolex () != 121);
+  else if (!strcmp(argv[1], "--bar"))
+    return (bar_lex () != 121);
+  else
+    abort ();
+}
+END
+
+cat > 0.l << 'END'
+%{
+#define YY_NO_UNISTD_H 1
+%}
+%%
+"VANILLA" { printf (":%s:\n", yytext); return 121; }
+. { printf (":%s:\n", yytext); return 1; }
+%%
+/* Avoid possible link errors. */
+int yywrap (void) { return 1; }
+END
+
+sed 's/VANILLA/FOO/' 0.l > a.l
+sed 's/VANILLA/BAR/' 0.l > b.l
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE --add-missing
+
+./configure
+$MAKE
+
+if ! cross_compiling; then
+  echo VANILLA | ./zardoz --vanilla
+  echo FOO | ./zardoz --foo
+  echo BAR | ./zardoz --bar
+  ./zardoz --vanilla </dev/null && exit 1
+  echo BAR | ./zardoz --foo && exit 1
+  : For shells with busted 'set -e'.
+fi
+
+$MAKE distcheck
+
+:
diff --git a/t/list-of-tests.mk b/t/list-of-tests.mk
index 5cda804..d2b6876 100644
--- a/t/list-of-tests.mk
+++ b/t/list-of-tests.mk
@@ -570,6 +570,7 @@ t/lex-header.sh \
 t/lex-lib.sh \
 t/lex-lib-external.sh \
 t/lex-libobj.sh \
+t/lex-multiple.sh \
 t/lex-noyywrap.sh \
 t/lex-clean-cxx.sh \
 t/lex-clean.sh \
-- 
1.8.1.rc3.192.g2d0029e




reply via email to

[Prev in Thread] Current Thread [Next in Thread]