From 05aa7398db64e97090b0ba5fbccd4a31ebaf9c8c Mon Sep 17 00:00:00 2001 From: Stefano Lattarini Date: Fri, 28 Jan 2011 16:57:05 +0100 Subject: [PATCH] coverage: more on 'yacc -d' and recovery from deleted headers * tests/yacc-deleted-headers.test: New test. * tests/Makefile.am (TESTS): Update. --- ChangeLog | 6 ++ tests/Makefile.am | 1 + tests/Makefile.in | 1 + tests/yacc-deleted-headers.test | 165 ++++++++++++++++++++++++++++++++ 4 files changed, 173 insertions(+) create mode 100755 tests/yacc-deleted-headers.test diff --git a/ChangeLog b/ChangeLog index 59fadb747..f4d7a9927 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2011-01-29 Stefano Lattarini + + coverage: more on 'yacc -d' and recovery from deleted headers + * tests/yacc-deleted-headers.test: New test. + * tests/Makefile.am (TESTS): Update. + 2011-01-29 Stefano Lattarini tests: remove redundancy from silent lex/yacc tests diff --git a/tests/Makefile.am b/tests/Makefile.am index d409adcf1..8422455d7 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -805,6 +805,7 @@ yacc6.test \ yacc7.test \ yacc8.test \ yaccdry.test \ +yacc-deleted-headers.test \ yacc-dist-nobuild.test \ yacc-nodist.test \ yaccpp.test \ diff --git a/tests/Makefile.in b/tests/Makefile.in index d7a26c8e6..a1cd3e2d4 100644 --- a/tests/Makefile.in +++ b/tests/Makefile.in @@ -1074,6 +1074,7 @@ yacc6.test \ yacc7.test \ yacc8.test \ yaccdry.test \ +yacc-deleted-headers.test \ yacc-dist-nobuild.test \ yacc-nodist.test \ yaccpp.test \ diff --git a/tests/yacc-deleted-headers.test b/tests/yacc-deleted-headers.test new file mode 100755 index 000000000..6d6a0a13b --- /dev/null +++ b/tests/yacc-deleted-headers.test @@ -0,0 +1,165 @@ +#! /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 that we can recover from deleted headers generated by `yacc -d'. + +required=yacc +. ./defs || Exit 1 + +set -e + +cat >> configure.in << 'END' +AC_PROG_CC +AC_PROG_YACC +AC_OUTPUT +END + +cat > Makefile.am <<'END' +bin_PROGRAMS = p1 p2 p3 p4 +# The order in which files are listed in the p*_SOURCES variables +# below is significant, since it causes make failures whenever +# the proper definition of BUILT_SOURCES or the declaration of +# extra dependencies for `main3.o' are removed. +p1_SOURCES = main1.c parse1.y +p2_SOURCES = main2.c parse2.y +p3_SOURCES = main3.c parse3.y parse3.h +p4_SOURCES = parse4.y +AM_YFLAGS = -d +p2_YFLAGS = -d + +BUILT_SOURCES = parse1.h p2-parse2.h + +# When we know which files include a yacc-generated header, we +# should be able to just declare dependencies directly instead +# of relying on the BUILT_SOURCES hack, and things should still +# work correctly. +main3.@OBJEXT@: parse3.h + +.PHONY: clean-p3 build-p3 +build-p3: p3$(EXEEXT) +clean-p3: + rm -f p3$(EXEEXT) +END + +cat > parse1.y << 'END' +%{ +#include "parse1.h" +int yylex () { return 0; } +void yyerror (char *s) { return; } +%} +%token ZARDOZ +%% +x : 'x' {}; +%% +END + +cat > main1.c << 'END' +#include "parse1.h" +int main (void) +{ + return ZARDOZ + yyparse (); +} +END + +sed 's/"parse1\.h"/"p2-parse2.h"/' parse1.y > parse2.y +sed 's/"parse1\.h"/"p2-parse2.h"/' main1.c > main2.c + +sed 's/"parse1\.h"/"parse3.h"/' parse1.y > parse3.y +sed 's/"parse1\.h"/"parse3.h"/' main1.c > main3.c + +cat > parse4.y << 'END' +%{ +int yylex () { return 0; } +void yyerror (char *s) { return; } +%} +%% +x : 'x' {}; +%% +int main (void) +{ + return 0; +} +END + +$ACLOCAL +$AUTOCONF +$AUTOMAKE -a + +./configure +$MAKE + +headers='parse1.h p2-parse2.h parse3.h parse4.h' + +# Check that we remake only the necessary headers. + +rm -f $headers +$MAKE parse1.h +test -f parse1.h +test ! -r p2-parse2.h +test ! -r parse3.h +test ! -r parse4.h + +rm -f $headers +$MAKE p2-parse2.h +test ! -r parse1.h +test -f p2-parse2.h +test ! -r parse3.h +test ! -r parse4.h + +rm -f $headers +$MAKE parse3.h +test ! -r parse1.h +test ! -r p2-parse2.h +test -f parse3.h +test ! -r parse4.h +# Since we declared parse3.h into $(p3_SOURCES), make should be +# able to rebuild it automatically before remaking `p3'. +rm -f $headers +$MAKE clean-p3 +test ! -f parse3.h # Sanity check. +$MAKE build-p3 +test -f parse3.h + +$MAKE + +rm -f $headers +$MAKE parse4.h +test ! -r parse1.h +test ! -r p2-parse2.h +test ! -r parse3.h +test -f parse4.h + +# Now remake all the headers together. + +rm -f $headers +$MAKE $headers +test -f parse1.h +test -f p2-parse2.h +test -f parse3.h +test -f parse4.h + +# Most headers should be remade by "make all". + +rm -f $headers +$MAKE all +test -f parse1.h +test -f p2-parse2.h +test -f parse3.h +# parse4.h is not declared in any *_SOURCES variable, nor #included +# by any C source file, so it shouldn't be rebuilt by "make all". +test ! -r parse4.h + +: -- 2.47.2