doc: typos in test file.
[automake.git] / t / lex-header.sh
blob2dd5a4ffc8827e3c067fad17492e46cba645671f
1 #! /bin/sh
2 # Copyright (C) 2011-2024 Free Software Foundation, Inc.
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.
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.
14 # You should have received a copy of the GNU General Public License
15 # along with this program. If not, see <https://www.gnu.org/licenses/>.
17 # Automake lex support can work with flex '--header-file' option (see
18 # bugs #8844 and #9933).
20 required='cc flex'
21 . test-init.sh
23 # Here, we need to use the use flex option '--header-file', but some
24 # older flex versions don't support is (see automake bug#11524 and
25 # bug#12836). Skip this test if such an old flex version is detected.
26 $LEX --help | grep '.*--header-file' \
27 || skip_ "flex doesn't support the '--header-file' option"
29 cat >> configure.ac << 'END'
30 AC_PROG_CC
31 AC_PROG_LEX
32 AC_OUTPUT
33 END
35 cat > Makefile.am << 'END'
36 AM_LFLAGS = --never-interactive
38 bin_PROGRAMS = foo
39 foo_SOURCES = lexer.l main.c mylex.h
40 foo_LFLAGS = --header-file=mylex.h
41 BUILT_SOURCES = mylex.h
42 # Recover from removal of header.
43 mylex.h: foo-lexer.c
44 test -f $@ || rm -f foo-lexer.c
45 test -f $@ || $(MAKE) $(AM_MAKEFLAGS) foo-lexer.c
46 END
48 cat > lexer.l << 'END'
49 %option noyywrap
51 "GOOD" return EOF;
54 END
56 cat > main.c <<'END'
57 #include "mylex.h"
58 int main (void)
60 /* We don't use a 'while' loop here (like a real lexer would do)
61 to avoid possible hangs. */
62 if (yylex () == EOF)
63 return 0;
64 else
65 return 1;
67 END
69 $ACLOCAL
70 $AUTOCONF
71 $AUTOMAKE -a
73 ./configure
75 # Program should build and run.
76 $MAKE
77 if ! cross_compiling; then
78 echo GOOD | ./foo
79 echo BAD | ./foo && exit 1
80 : For shells with busted 'set -e'.
83 # Recovering from header removal.
84 rm -f mylex.h
85 $MAKE
86 test -f mylex.h
88 # Sanity check on distribution.
89 yl_distcheck