test harness: improve catching of usage errors in script 'test-driver'
[platform/upstream/automake.git] / t / lex-multiple.sh
1 #! /bin/sh
2 # Copyright (C) 2012-2013 Free Software Foundation, Inc.
3 #
4 # This program is free software; you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation; either version 2, or (at your option)
7 # any later version.
8 #
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 # GNU General Public License for more details.
13 #
14 # You should have received a copy of the GNU General Public License
15 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
16
17 # Check that we can build a program using several lexers at once
18 # (assuming Flex is used).  That is a little tricky, but possible.
19 # See:
20 # <http://lists.gnu.org/archive/html/automake/2010-10/msg00081.html>
21 # <http://lists.gnu.org/archive/html/automake/2009-03/msg00061.html>
22
23 required='cc flex'
24 . test-init.sh
25
26 cat >> configure.ac << 'END'
27 AC_PROG_CC
28 AC_PROG_LEX
29 AM_PROG_AR
30 AC_PROG_RANLIB
31 AC_OUTPUT
32 END
33
34 cat > Makefile.am << 'END'
35 bin_PROGRAMS = zardoz
36
37 zardoz_SOURCES = main.c
38 # Convenience libraries.
39 noinst_LIBRARIES = liblex.a liblex-foo.a liblex-bar.a
40 zardoz_LDADD = $(noinst_LIBRARIES)
41
42 liblex_a_SOURCES = 0.l
43
44 # We need the output to always be named 'lex.yy.c', in order for
45 # ylwrap to pick it up.
46 liblex_foo_a_LFLAGS = -Pfoo -olex.yy.c
47 liblex_foo_a_SOURCES = a.l
48
49 # Ditto.
50 liblex_bar_a_LFLAGS = -Pbar_ -olex.yy.c
51 liblex_bar_a_SOURCES = b.l
52 END
53
54 cat > main.c << 'END'
55 #include <stdio.h>
56 #include <stdlib.h>
57 #include <string.h>
58
59 int main (int argc, char *argv[])
60 {
61   if (argc != 2)
62     abort ();
63   else if (!strcmp(argv[1], "--vanilla"))
64     return (yylex () != 121);
65   else if (!strcmp(argv[1], "--foo"))
66     return (foolex () != 121);
67   else if (!strcmp(argv[1], "--bar"))
68     return (bar_lex () != 121);
69   else
70     abort ();
71 }
72 END
73
74 cat > 0.l << 'END'
75 %{
76 #define YY_NO_UNISTD_H 1
77 %}
78 %%
79 "VANILLA" { printf (":%s:\n", yytext); return 121; }
80 . { printf (":%s:\n", yytext); return 1; }
81 %%
82 /* Avoid possible link errors. */
83 int yywrap (void) { return 1; }
84 END
85
86 sed 's/VANILLA/FOO/' 0.l > a.l
87 sed 's/VANILLA/BAR/' 0.l > b.l
88
89 $ACLOCAL
90 $AUTOCONF
91 $AUTOMAKE --add-missing
92
93 ./configure
94 $MAKE
95
96 if ! cross_compiling; then
97   echo VANILLA | ./zardoz --vanilla
98   echo FOO | ./zardoz --foo
99   echo BAR | ./zardoz --bar
100   ./zardoz --vanilla </dev/null && exit 1
101   echo BAR | ./zardoz --foo && exit 1
102   : For shells with busted 'set -e'.
103 fi
104
105 yl_distcheck
106
107 :