From c5b255bacb70ccb09b923f1a5acb4e6abca88385 Mon Sep 17 00:00:00 2001 From: Stefano Lattarini Date: Wed, 5 Jan 2011 16:07:56 +0100 Subject: [PATCH] yacc: extend and improve tests * tests/yacc-basic.test: Also check that the intermediate C file is mentioned in the generated Makefile.in, and that it is created by the first make invocation. * tests/yacc3.test: Test removed, superseded by ... * tests/yacc-d-basic.test: ... this new test. * tests/yacc2.test: Add reference to that new test in the heading comments. * tests/yacc-d-vpath.test: New test. * tests/yaccvpath.test: Updated heading comments. Do not require gcc anymore, as any working C compiler should be enough. Remove redundant comments. * tests/yacc-nodist.test: New test. * tests/yacc-dist-nobuild.test: New test. * tests/Makefile.am (TESTS): Update. --- ChangeLog | 18 ++++ tests/Makefile.am | 5 +- tests/Makefile.in | 5 +- tests/yacc-basic.test | 12 ++- tests/yacc-d-basic.test | 158 +++++++++++++++++++++++++++++++++++ tests/yacc-d-vpath.test | 112 +++++++++++++++++++++++++ tests/yacc-dist-nobuild.test | 89 ++++++++++++++++++++ tests/yacc-nodist.test | 101 ++++++++++++++++++++++ tests/yacc2.test | 3 +- tests/yacc3.test | 52 ------------ tests/yaccvpath.test | 13 +-- 11 files changed, 503 insertions(+), 65 deletions(-) create mode 100755 tests/yacc-d-basic.test create mode 100755 tests/yacc-d-vpath.test create mode 100755 tests/yacc-dist-nobuild.test create mode 100755 tests/yacc-nodist.test delete mode 100755 tests/yacc3.test diff --git a/ChangeLog b/ChangeLog index 13fdc61e0..d05135f63 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,21 @@ +2011-01-08 Stefano Lattarini + + yacc: extend and improve tests + * tests/yacc-basic.test: Also check that the intermediate C file + is mentioned in the generated Makefile.in, and that it is created + by the first make invocation. + * tests/yacc3.test: Test removed, superseded by ... + * tests/yacc-d-basic.test: ... this new test. + * tests/yacc2.test: Add reference to that new test in the heading + comments. + * tests/yacc-d-vpath.test: New test. + * tests/yaccvpath.test: Updated heading comments. Do not require + gcc anymore, as any working C compiler should be enough. Remove + redundant comments. + * tests/yacc-nodist.test: New test. + * tests/yacc-dist-nobuild.test: New test. + * tests/Makefile.am (TESTS): Update. + 2010-12-13 Stefano Lattarini Extend, fix and improve tests on Lex and Yacc support. diff --git a/tests/Makefile.am b/tests/Makefile.am index 00829ef5b..15d3b2865 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -796,18 +796,21 @@ whoami.test \ xsource.test \ xz.test \ yacc-basic.test \ +yacc-d-basic.test \ yacc-clean.test \ yacc.test \ yacc2.test \ -yacc3.test \ yacc4.test \ yacc5.test \ yacc6.test \ yacc7.test \ yacc8.test \ yaccdry.test \ +yacc-dist-nobuild.test \ +yacc-nodist.test \ yaccpp.test \ yaccvpath.test \ +yacc-d-vpath.test \ yflags.test \ yflags2.test \ $(parallel_tests) diff --git a/tests/Makefile.in b/tests/Makefile.in index 3813e8f4e..6233b8240 100644 --- a/tests/Makefile.in +++ b/tests/Makefile.in @@ -1063,18 +1063,21 @@ whoami.test \ xsource.test \ xz.test \ yacc-basic.test \ +yacc-d-basic.test \ yacc-clean.test \ yacc.test \ yacc2.test \ -yacc3.test \ yacc4.test \ yacc5.test \ yacc6.test \ yacc7.test \ yacc8.test \ yaccdry.test \ +yacc-dist-nobuild.test \ +yacc-nodist.test \ yaccpp.test \ yaccvpath.test \ +yacc-d-vpath.test \ yflags.test \ yflags2.test \ $(parallel_tests) diff --git a/tests/yacc-basic.test b/tests/yacc-basic.test index af0c488b0..e8bf27d00 100755 --- a/tests/yacc-basic.test +++ b/tests/yacc-basic.test @@ -1,5 +1,5 @@ #! /bin/sh -# Copyright (C) 2010 Free Software Foundation, Inc. +# Copyright (C) 2010, 2011 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 @@ -32,6 +32,10 @@ END cat > Makefile.am << 'END' bin_PROGRAMS = foo foo_SOURCES = parse.y foo.c + +.PHONY: echo-distcom +echo-distcom: + @echo ' ' $(DIST_COMMON) ' ' END cat > parse.y << 'END' @@ -55,12 +59,18 @@ $AUTOMAKE -a ./configure $MAKE +# The `parse.c' file must be created and not removed (i.e., not treated +# like an "intermediate file" in the GNU make sense). +test -f parse.c echo a | ./foo echo b | ./foo && Exit 1 # The generated file `parse.c' must be shipped. +$MAKE echo-distcom +$MAKE -s echo-distcom | grep '[ /]parse.c ' $MAKE distdir +ls -l $distdir test -f $distdir/parse.c # Sanity check on distribution. diff --git a/tests/yacc-d-basic.test b/tests/yacc-d-basic.test new file mode 100755 index 000000000..f5f88d8af --- /dev/null +++ b/tests/yacc-d-basic.test @@ -0,0 +1,158 @@ +#! /bin/sh +# Copyright (C) 2011 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 . + +# Tests on basic Yacc support for when we have -d in YFLAGS, AM_YFLAGS +# or maude_YFLAGS. + +required=bison +. ./defs || Exit 1 + +set -e + +tab=' ' +distdir=$me-1.0 + +cat >> configure.in << 'END' +AC_PROG_CC +AC_PROG_YACC +AC_CONFIG_FILES([foo/Makefile bar/Makefile baz/Makefile]) +AC_OUTPUT +END + +cat > Makefile.am <<'END' +SUBDIRS = foo bar baz +END + +mkdir foo bar baz + +cat > foo/Makefile.am <<'END' +bin_PROGRAMS = zardoz +zardoz_SOURCES = parse.y main.c +.PHONY: echo-distcom +echo-distcom: + @echo ' ' $(DIST_COMMON) ' ' +END +cp foo/Makefile.am bar/Makefile.am +cp foo/Makefile.am baz/Makefile.am + +cat > foo/parse.y << 'END' +%{ +#include "parse.h" +int yylex () { return 0; } +void yyerror (char *s) {} +%} +%% +x : 'x' {}; +%% +END +cp foo/parse.y bar/parse.y + +cat > foo/main.c << 'END' +#include "parse.h" +int main () +{ + return yyparse (); +} +END +cp foo/main.c bar/main.c + +# Even the generated header file is renamed when target-specific YFLAGS +# are used. This might not be the best behavior, but it has been in +# place for quite a long time, so just go along with it for now. +sed 's/"parse\.h"/"zardoz-parse.h"/' foo/parse.y > baz/parse.y +sed 's/"parse\.h"/"zardoz-parse.h"/' foo/main.c > baz/main.c + +$ACLOCAL +$AUTOCONF + +$AUTOMAKE -a +$FGREP parse.h foo/Makefile.in bar/Makefile.in baz/Makefile.in && Exit 1 + +cat >> foo/Makefile.am <> bar/Makefile.am <> baz/Makefile.am <. + +# This test checks that dependent files are updated before including +# in the distribution. `parse.c' depends on `parse.y'. The latter is +# updated so that `parse.c' should be rebuilt. Then we are running +# `make' and `make distdir' and check whether the version of `parse.c' +# to be distributed is up to date. + +# Please keep this in sync with sister test `yaccvpath.test'. + +required=bison +. ./defs || Exit 1 + +set -e + +distdir=$me-1.0 + +cat >> configure.in << 'END' +AC_PROG_CC +AC_PROG_YACC +AC_OUTPUT +END + +cat > Makefile.am << 'END' +bin_PROGRAMS = foo +foo_SOURCES = parse.y foo.c +AM_YFLAGS = -d +END + +# Original parser, with `foobar' +cat > parse.y << 'END' +%{ +int yylex () {return 0;} +void yyerror (char *s) {} +%} +%token FOOBAR +%% +foobar : 'f' 'o' 'o' 'b' 'a' 'r' {}; +END + +cat > foo.c << 'END' +#include "parse.h" +int main () { return 0; } +END + +$ACLOCAL +$AUTOCONF +$AUTOMAKE -a + +$YACC -d parse.y +mv y.tab.c parse.c +mv y.tab.h parse.h +# Sanity checks. +grep foobar parse.c +grep FOOBAR parse.h + +mkdir sub +cd sub +../configure + +$sleep + +# New parser, with `fubar' +cat > ../parse.y << 'END' +%{ +int yylex () {return 0;} +void yyerror (char *s) {} +%} +%token FUBAR +%% +fubar : 'f' 'u' 'b' 'a' 'r' {}; +END + +$MAKE +$MAKE distdir +$FGREP fubar $distdir/parse.c +$FGREP FUBAR $distdir/parse.h + +# Now check to make sure that `make dist' will rebuild the parser. + +$sleep + +# New parser, with `maude' +cat > ../parse.y << 'END' +%{ +int yylex () {return 0;} +void yyerror (char *s) {} +%} +%token MAUDE +%% +maude : 'm' 'a' 'u' 'd' 'e' {}; +END + +$MAKE distdir +$FGREP maude $distdir/parse.c +$FGREP MAUDE $distdir/parse.h + +: diff --git a/tests/yacc-dist-nobuild.test b/tests/yacc-dist-nobuild.test new file mode 100755 index 000000000..a6444dea1 --- /dev/null +++ b/tests/yacc-dist-nobuild.test @@ -0,0 +1,89 @@ +#! /bin/sh +# Copyright (C) 2011 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 . + +# Check that distributed Yacc-generated parsers are not uselessly +# remade from an unpacked distributed tarball. + +required=bison +. ./defs || Exit 1 + +set -e + +distdir=$me-1.0 + +cat >> configure.in << 'END' +AC_PROG_CC +AC_PROG_YACC +AC_OUTPUT +END + +cat > Makefile.am << 'END' +bin_PROGRAMS = foobar zardoz +foobar_SOURCES = parse.y main.c +zardoz_SOURCES = $(foobar_SOURCES) +zardoz_YFLAGS = -d +END + +cat > parse.y << 'END' +%{ +int yylex () { return 0; } +void yyerror (char *s) {} +%} +%% +foobar : 'f' 'o' 'o' 'b' 'a' 'r' {}; +END + +cat > main.c << 'END' +int main () { return 0; } +END + +$ACLOCAL +$AUTOCONF +$AUTOMAKE -a + +./configure +$MAKE + +$MAKE distdir +chmod -R a-w $distdir + +mkdir bin +cat > bin/yacc <<'END' +#!/bin/sh +echo "$0 invoked, shouldn't happen!" >&2 +exit 1 +END +cp bin/yacc bin/bison +chmod a+x bin/yacc bin/bison +PATH=`pwd`/bin$PATH_SEPARATOR$PATH + +YACC=yacc BISON=bison +export YACC BISON + +mkdir build +cd build +../$distdir/configure +$MAKE + +# Sanity check. +chmod u+w ../$distdir +rm -f ../$distdir/parse.c +chmod a-w ../$distdir +$MAKE >out 2>&1 && { cat out; Exit 1; } +cat out +$FGREP parse.c out + +: diff --git a/tests/yacc-nodist.test b/tests/yacc-nodist.test new file mode 100755 index 000000000..2b4ce09a5 --- /dev/null +++ b/tests/yacc-nodist.test @@ -0,0 +1,101 @@ +#! /bin/sh +# Copyright (C) 2011 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 . + +# Checks for .c and .h files derived from non-distributed .y sources. + +required=bison +. ./defs || Exit 1 + +set -e + +cat >> configure.in << 'END' +AC_PROG_CC +AC_PROG_YACC +AC_CONFIG_FILES([sub1/Makefile sub2/Makefile]) +AC_OUTPUT +END + +cat > Makefile.am << 'END' +SUBDIRS = sub1 sub2 +.PHONY: test +test-build: all + ls -l . sub1 sub2 + test -f sub1/parse.y + test -f sub1/parse.c + test -f sub2/parse.y + test -f sub2/parse.c + test -f sub2/parse.h +test-dist: distdir + ls -l $(distdir) $(distdir)/sub1 $(distdir)/sub2 + test ! -r $(distdir)/sub1/parse.y + test ! -r $(distdir)/sub1/parse.c + test ! -r $(distdir)/sub1/parse.h + test ! -r $(distdir)/sub2/parse.y + test ! -r $(distdir)/sub2/parse.c + test ! -r $(distdir)/sub2/parse.h +check-local: test-build test-dist +END + +mkdir sub1 sub2 + +cat > sub1/Makefile.am << 'END' +parse.y: + rm -f $@ $@-t + :; { : \ + && echo "%{" \ + && echo "int yylex () { return 0; }" \ + && echo "void yyerror (char *s) {}" \ + && echo "%}" \ + && echo "%%" \ + && echo "maude : 'm' 'a' 'u' 'd' 'e' {}"; \ + } > $@-t + chmod a-w $@-t + mv -f $@-t $@ +bin_PROGRAMS = prog +prog_SOURCES = main.c +nodist_prog_SOURCES = parse.y +CLEANFILES = $(nodist_prog_SOURCES) +END + +cat sub1/Makefile.am - > sub2/Makefile.am << 'END' +AM_YFLAGS = -d +BUILT_SOURCES = parse.h +END + +cat > sub1/main.c << 'END' +int main () +{ + return yyparse (); +} +END +cat - sub1/main.c > sub2/main.c << 'END' +#include "parse.h" +END + +$ACLOCAL +$AUTOCONF +$AUTOMAKE -a + +./configure +$MAKE +$MAKE test-build +$MAKE test-dist + +# But the distribution must work correctly, assuming the user has +# the proper tools to process yacc files. +$MAKE distcheck + +: diff --git a/tests/yacc2.test b/tests/yacc2.test index f598595c7..959c6b5a3 100755 --- a/tests/yacc2.test +++ b/tests/yacc2.test @@ -1,5 +1,5 @@ #! /bin/sh -# Copyright (C) 1999, 2001, 2002, 2003, 2006, 2010 Free Software +# Copyright (C) 1999, 2001, 2002, 2003, 2006, 2010, 2011 Free Software # Foundation, Inc. # # This program is free software; you can redistribute it and/or modify @@ -17,6 +17,7 @@ # Test to make sure intermediate .h file is not generated nor removed # if (AM_)?YFLAGS do not contain -d. Requested by Jim Meyering. +# See also the related semantic test `yacc-d-basic.test'. . ./defs || Exit 1 diff --git a/tests/yacc3.test b/tests/yacc3.test deleted file mode 100755 index 46f8d3e7f..000000000 --- a/tests/yacc3.test +++ /dev/null @@ -1,52 +0,0 @@ -#! /bin/sh -# Copyright (C) 1999, 2001, 2002, 2006, 2010 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 . - -# Ensure that generated .h file is distributed iff we have -d in -# (AM_)?YFLAGS. - -. ./defs || Exit 1 - -set -e - -cat >> configure.in << 'END' -AC_PROG_CC -AC_PROG_YACC -END - -cat > Makefile.am <<'END' -AUTOMAKE_OPTIONS = no-dependencies -bin_PROGRAMS = zardoz -zardoz_SOURCES = zardoz.y -END - -$ACLOCAL -$AUTOMAKE -a - -# It should not be disted here -$FGREP 'zardoz.h' Makefile.in && Exit 1 - -cp Makefile.am Makefile.sav -# Test all available flags to make sure header is distributed with -# `-d'. -for flag in YFLAGS AM_YFLAGS zardoz_YFLAGS; do - cp Makefile.sav Makefile.am - echo "$flag = -d" >> Makefile.am - $AUTOMAKE -Wno-gnu - $FGREP 'zardoz.h' Makefile.in -done - -: diff --git a/tests/yaccvpath.test b/tests/yaccvpath.test index 7f4467114..c4dc400ca 100755 --- a/tests/yaccvpath.test +++ b/tests/yaccvpath.test @@ -1,5 +1,6 @@ #! /bin/sh -# Copyright (C) 2001, 2002, 2003, 2010 Free Software Foundation, Inc. +# Copyright (C) 2001, 2002, 2003, 2010, 2011 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 @@ -20,9 +21,9 @@ # `make' and `make distdir' and check whether the version of `parse.c' # to be distributed is up to date. -# Please keep this in sync with sister test `lexvapth.test'. +# Please keep this in sync with sister test `yacc-d-vpath.test'. -required='gcc bison' +required=bison . ./defs || Exit 1 set -e @@ -65,8 +66,6 @@ mkdir sub cd sub ../configure -# A delay is needed to make sure that the new parse.y is indeed newer -# than parse.c, i.e. the they don't have the same timestamp. $sleep # New parser, with `fubar' @@ -83,12 +82,8 @@ $MAKE $MAKE distdir $FGREP fubar $distdir/parse.c -# # Now check to make sure that `make dist' will rebuild the parser. -# -# A delay is needed to make sure that the new parse.y is indeed newer -# than parse.c, i.e. the they don't have the same timestamp. $sleep # New parser, with `maude' -- 2.47.2