The recent extension of the `maintainer-check' target (to include checks on the consistency of the list of test scripts) has introduced some code duplication. This patch takes care of removing (part of) such duplication.
From 2c2c697dda9d46d079adb1071e73ae300b1fd139 Mon Sep 17 00:00:00 2001 From: Stefano Lattarini <stefano.lattar...@gmail.com> Date: Sat, 26 Dec 2009 00:47:02 +0100 Subject: [PATCH 5/6] maint-check: refactoring to avoid code duplication
The recent extension of the `maintainer-check' target (to include checks on the consistency of the list of test scripts) has introduced some code duplication. This change takes care of removing such duplication. * CheckListOfTests.am: New file. Contains the definition of the `maintainer-check-list-of-tests' target (mostly copied from the equally-named rule in the previous version of `tests/Makefile.am'). * tests/Makefile.am: Include `CheckListOfTests.am'. (maintainer-check-list-of-tests): Removed associated rules, they're defined in included file `CheckListOfTests.am'. (TEST_EXTENSIONS): New, define to `.test'. (MOSTLYCLEANFILES): Initialize to empty. * lib/Automake/tests/Makefile.am: Include `CheckListOfTests.am'. (maintainer-check-list-of-tests): Removed, it's defined in included file `CheckListOfTests.am'. (MOSTLYCLEANFILES): Initialize to empty. --- ChangeLog | 20 +++++++++++ CheckListOfTests.am | 70 ++++++++++++++++++++++++++++++++++++++++ lib/Automake/tests/Makefile.am | 43 +----------------------- lib/Automake/tests/Makefile.in | 31 +++++++++++------- tests/Makefile.am | 44 ++----------------------- tests/Makefile.in | 36 ++++++++++++-------- 6 files changed, 137 insertions(+), 107 deletions(-) create mode 100644 CheckListOfTests.am diff --git a/ChangeLog b/ChangeLog index a4bd40b..c64e8f8 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,23 @@ +2009-12-26 Stefano Lattarini <stefano.lattar...@gmail.com> + + Maint-check: refactoring in makefiles, to avoid code duplication. + The recent extension of the `maintainer-check' target (to include + checks on the consistency of the list of test scripts) has + introduced some code duplication. This change takes care of + removing such duplication. + * CheckListOfTests.am: New file. Contains the definition of the + `maintainer-check-list-of-tests' target (mostly copied from the + equally-named rule in the previous version of `tests/Makefile.am'). + * tests/Makefile.am: Include `CheckListOfTests.am'. + (maintainer-check-list-of-tests): Removed associated rules, they're + defined in included file `CheckListOfTests.am'. + (TEST_EXTENSIONS): New, define to `.test'. + (MOSTLYCLEANFILES): Initialize to empty. + * lib/Automake/tests/Makefile.am: Include `CheckListOfTests.am'. + (maintainer-check-list-of-tests): Removed, it's defined in included + file `CheckListOfTests.am'. + (MOSTLYCLEANFILES): Initialize to empty. + 2009-12-25 Stefano Lattarini <stefano.lattar...@gmail.com> Slighty improve tests acoutbs.test and acoutbs2.test. diff --git a/CheckListOfTests.am b/CheckListOfTests.am new file mode 100644 index 0000000..8927a99 --- /dev/null +++ b/CheckListOfTests.am @@ -0,0 +1,70 @@ +## -*- Automake -*- + +## Copyright (C) 2009 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/>. + + +## temporary files used in the `check-list-of-tests' target +tmk = tests-in-makefile-list.tmp +tfs = tests-on-filesystem-list.tmp +tdf = diff-in-tests-lists.tmp + +## this assumes MOSTLYCLEANFILES has already been defined, even if only +## to an empty value +MOSTLYCLEANFILES += $(tmk) $(tfs) $(tdf) + +## Check that the list of tests given in the Makefile is equal to the +## list of all test scripts in the Automake testsuite. +.PHONY: maintainer-check-list-of-tests +maintainer-check-list-of-tests: + ## prefer unified diffs over plain diffs, for readability + @if diff -u /dev/null /dev/null >/dev/null 2>&1; then \ + diff='diff -u'; \ + else \ + diff='diff'; \ + fi; \ + ## determine which files are to be considered test scripts + set X $(TEST_EXTENSIONS); shift; \ + if test $$# -eq 0; then \ + echo '$@: INTERNAL ERROR: $$(TEST_EXTENSIONS) undefined' \ + 'or empty' >&2; \ + exit 255; \ + fi; \ + shift $$#; \ + ## list of tests in Makefile + for t in $(TESTS); do \ + echo "$$t"; \ + done | sort >$(tmk); \ + ## list of tests on filesystem + for suf in $(TEST_EXTENSIONS); do \ + glob="$(srcdir)/*$$suf"; \ + if test x"$(srcdir)" != x"$(builddir)"; then \ + glob="$$glob $(builddir)/*$$suf"; \ + fi; \ + done; \ + for t in $$glob; do \ + echo "$$t"; \ + done | sed 's,^.*/,,' | sort >$(tfs); \ + ## compare the two lists + if $$diff $(tmk) $(tfs) >$(tdf); then \ + e=0; \ + else \ + echo '$@: list of tests in Makefile an on filesystem differ' >&2; \ + echo "+ $$diff in-makefile on-filesystem" >&2; \ + cat $(tdf) >&2; \ + e=1; \ + fi; \ + rm -f $(tmk) $(tfs) $(tdf); \ + exit $$e; diff --git a/lib/Automake/tests/Makefile.am b/lib/Automake/tests/Makefile.am index dbd4f00..7677453 100644 --- a/lib/Automake/tests/Makefile.am +++ b/lib/Automake/tests/Makefile.am @@ -43,44 +43,5 @@ Version3.pl EXTRA_DIST = $(TESTS) -## temporary files used in the `check-list-of-tests' target -tmk = tests-in-makefile-list.tmp -tfs = tests-on-filesystem-list.tmp -tdf = diff-in-tests-lists.tmp - -MOSTLYCLEANFILES = $(tmk) $(tfs) $(tdf) - -# Check that the list of tests given in the Makefile is equal to the -# list of all test scripts in the Automake testsuite. -maintainer-check-list-of-tests: - @:; \ - ## prefer unified diffs over plain diffs, for readability - if diff -u /dev/null /dev/null >/dev/null 2>&1; then \ - diff='diff -u'; \ - else \ - diff='diff'; \ - fi; \ - ## list of tests in Makefile - for t in $(TESTS); do \ - echo "$$t"; \ - done | sort >$(tmk); \ - ## list of tests on filesystem - glob="$(srcdir)/*.pl"; \ - if test x"$(srcdir)" != x"$(builddir)"; then \ - glob="$$glob $(builddir)/*.pl"; \ - fi; \ - for t in $$glob; do \ - echo "$$t"; \ - done | sed 's,^.*/,,' | sort >$(tfs); \ - ## compare the two lists - if $$diff $(tmk) $(tfs) >$(tdf); then \ - e=0; \ - else \ - echo '$@: list of tests in Makefile an on filesystem differ' >&2; \ - echo "+ $$diff in-makefile on-filesystem" >&2; \ - cat $(tdf) >&2; \ - e=1; \ - fi; \ - rm -f $(tmk) $(tfs) $(tdf); \ - exit $$e; -.PHONY: maintainer-check-list-of-tests +MOSTLYCLEANFILES = ## dummy initialization required +include ../../../CheckListOfTests.am diff --git a/lib/Automake/tests/Makefile.in b/lib/Automake/tests/Makefile.in index c3712b9..002a88a 100644 --- a/lib/Automake/tests/Makefile.in +++ b/lib/Automake/tests/Makefile.in @@ -32,8 +32,9 @@ NORMAL_UNINSTALL = : PRE_UNINSTALL = : POST_UNINSTALL = : build_triplet = @build@ +DIST_COMMON = $(srcdir)/../../../CheckListOfTests.am \ + $(srcdir)/Makefile.am $(srcdir)/Makefile.in subdir = lib/Automake/tests -DIST_COMMON = $(srcdir)/Makefile.am $(srcdir)/Makefile.in ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 am__aclocal_m4_deps = $(top_srcdir)/m4/amversion.m4 \ $(top_srcdir)/m4/auxdir.m4 $(top_srcdir)/m4/init.m4 \ @@ -255,15 +256,15 @@ Version2.pl \ Version3.pl EXTRA_DIST = $(TESTS) +MOSTLYCLEANFILES = $(tmk) $(tfs) $(tdf) tmk = tests-in-makefile-list.tmp tfs = tests-on-filesystem-list.tmp tdf = diff-in-tests-lists.tmp -MOSTLYCLEANFILES = $(tmk) $(tfs) $(tdf) all: all-am .SUFFIXES: .SUFFIXES: .html .log .pl -$(srcdir)/Makefile.in: $(srcdir)/Makefile.am $(am__configure_deps) +$(srcdir)/Makefile.in: $(srcdir)/Makefile.am $(srcdir)/../../../CheckListOfTests.am $(am__configure_deps) @for dep in $?; do \ case '$(am__configure_deps)' in \ *$$dep*) \ @@ -603,22 +604,29 @@ uninstall-am: pdf-am ps ps-am recheck recheck-html uninstall uninstall-am -# Check that the list of tests given in the Makefile is equal to the -# list of all test scripts in the Automake testsuite. +.PHONY: maintainer-check-list-of-tests maintainer-check-list-of-tests: - @:; \ - if diff -u /dev/null /dev/null >/dev/null 2>&1; then \ + @if diff -u /dev/null /dev/null >/dev/null 2>&1; then \ diff='diff -u'; \ else \ diff='diff'; \ fi; \ + set X $(TEST_EXTENSIONS); shift; \ + if test $$# -eq 0; then \ + echo '$@: INTERNAL ERROR: $$(TEST_EXTENSIONS) undefined' \ + 'or empty' >&2; \ + exit 255; \ + fi; \ + shift $$#; \ for t in $(TESTS); do \ echo "$$t"; \ done | sort >$(tmk); \ - glob="$(srcdir)/*.pl"; \ - if test x"$(srcdir)" != x"$(builddir)"; then \ - glob="$$glob $(builddir)/*.pl"; \ - fi; \ + for suf in $(TEST_EXTENSIONS); do \ + glob="$(srcdir)/*$$suf"; \ + if test x"$(srcdir)" != x"$(builddir)"; then \ + glob="$$glob $(builddir)/*$$suf"; \ + fi; \ + done; \ for t in $$glob; do \ echo "$$t"; \ done | sed 's,^.*/,,' | sort >$(tfs); \ @@ -632,7 +640,6 @@ maintainer-check-list-of-tests: fi; \ rm -f $(tmk) $(tfs) $(tdf); \ exit $$e; -.PHONY: maintainer-check-list-of-tests # Tell versions [3.59,3.63) of GNU make to not export all variables. # Otherwise a system limit (for SysV at least) may be exceeded. diff --git a/tests/Makefile.am b/tests/Makefile.am index eac4738..293e52e 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -22,6 +22,8 @@ MAINTAINERCLEANFILES = $(parallel_tests) defs-p: defs Makefile.am $(AM_V_GEN)sed 's,^AM_INIT_AUTOMAKE$$,&([parallel-tests]),' < defs >$@ +TEST_EXTENSIONS = .test + TESTS = \ aclibobj.test \ aclocal.test \ @@ -755,47 +757,9 @@ $(parallel_tests) EXTRA_DIST = ChangeLog-old gen-parallel-tests $(TESTS) -## temporary files used in the `check-list-of-tests' target -tmk = tests-in-makefile-list.tmp -tfs = tests-on-filesystem-list.tmp -tdf = diff-in-tests-lists.tmp - -MOSTLYCLEANFILES = $(tmk) $(tfs) $(tdf) - -# Check that the list of tests given in the Makefile is equal to the -# list of all test scripts in the Automake testsuite. +MOSTLYCLEANFILES = ## dummy initialization required +include ../CheckListOfTests.am maintainer-check-list-of-tests: $(parallel_tests) - @:; \ - ## prefer unified diffs over plain diffs, for readability - if diff -u /dev/null /dev/null >/dev/null 2>&1; then \ - diff='diff -u'; \ - else \ - diff='diff'; \ - fi; \ - ## list of tests in Makefile - for t in $(TESTS); do \ - echo "$$t"; \ - done | sort >$(tmk); \ - ## list of tests on filesystem - glob="$(srcdir)/*.test"; \ - if test x"$(srcdir)" != x"$(builddir)"; then \ - glob="$$glob $(builddir)/*.test"; \ - fi; \ - for t in $$glob; do \ - echo "$$t"; \ - done | sed 's,^.*/,,' | sort >$(tfs); \ - ## compare the two lists - if $$diff $(tmk) $(tfs) >$(tdf); then \ - e=0; \ - else \ - echo '$@: list of tests in Makefile an on filesystem differ' >&2; \ - echo "+ $$diff in-makefile on-filesystem" >&2; \ - cat $(tdf) >&2; \ - e=1; \ - fi; \ - rm -f $(tmk) $(tfs) $(tdf); \ - exit $$e; -.PHONY: maintainer-check-list-of-tests # Each test case depends on defs, aclocal, and automake. check_SCRIPTS = defs defs-p aclocal-$(APIVERSION) automake-$(APIVERSION) diff --git a/tests/Makefile.in b/tests/Makefile.in index fa2b3d0..7977fe0 100644 --- a/tests/Makefile.in +++ b/tests/Makefile.in @@ -32,7 +32,8 @@ NORMAL_UNINSTALL = : PRE_UNINSTALL = : POST_UNINSTALL = : build_triplet = @build@ -DIST_COMMON = README $(srcdir)/Makefile.am $(srcdir)/Makefile.in \ +DIST_COMMON = README $(srcdir)/../CheckListOfTests.am \ + $(srcdir)/Makefile.am $(srcdir)/Makefile.in \ $(srcdir)/aclocal.in $(srcdir)/automake.in $(srcdir)/defs.in \ $(srcdir)/parallel-tests.am subdir = tests @@ -135,7 +136,6 @@ RECHECK_LOGS = $(TEST_LOGS) AM_RECURSIVE_TARGETS = check check-html recheck recheck-html TEST_SUITE_LOG = test-suite.log TEST_SUITE_HTML = $(TEST_SUITE_LOG:.log=.html) -TEST_EXTENSIONS = .test am__test_logs1 = $(TESTS:=.log) TEST_LOGS = $(am__test_logs1:.test.log=.log) TEST_LOG_COMPILE = $(TEST_LOG_COMPILER) $(AM_TEST_LOG_FLAGS) \ @@ -263,6 +263,7 @@ pr401b-p.test \ pr401c-p.test MAINTAINERCLEANFILES = $(parallel_tests) +TEST_EXTENSIONS = .test TESTS = \ aclibobj.test \ aclocal.test \ @@ -995,10 +996,10 @@ yaccvpath.test \ $(parallel_tests) EXTRA_DIST = ChangeLog-old gen-parallel-tests $(TESTS) +MOSTLYCLEANFILES = $(tmk) $(tfs) $(tdf) tmk = tests-in-makefile-list.tmp tfs = tests-on-filesystem-list.tmp tdf = diff-in-tests-lists.tmp -MOSTLYCLEANFILES = $(tmk) $(tfs) $(tdf) # Each test case depends on defs, aclocal, and automake. check_SCRIPTS = defs defs-p aclocal-$(APIVERSION) automake-$(APIVERSION) @@ -1006,7 +1007,7 @@ all: all-am .SUFFIXES: .SUFFIXES: .html .log .test -$(srcdir)/Makefile.in: $(srcdir)/Makefile.am $(srcdir)/parallel-tests.am $(am__configure_deps) +$(srcdir)/Makefile.in: $(srcdir)/Makefile.am $(srcdir)/parallel-tests.am $(srcdir)/../CheckListOfTests.am $(am__configure_deps) @for dep in $?; do \ case '$(am__configure_deps)' in \ *$$dep*) \ @@ -1365,22 +1366,29 @@ $(parallel_tests): $(parallel_tests:-p.test=.test) Makefile.am defs-p: defs Makefile.am $(AM_V_GEN)sed 's,^AM_INIT_AUTOMAKE$$,&([parallel-tests]),' < defs >$@ -# Check that the list of tests given in the Makefile is equal to the -# list of all test scripts in the Automake testsuite. -maintainer-check-list-of-tests: $(parallel_tests) - @:; \ - if diff -u /dev/null /dev/null >/dev/null 2>&1; then \ +.PHONY: maintainer-check-list-of-tests +maintainer-check-list-of-tests: + @if diff -u /dev/null /dev/null >/dev/null 2>&1; then \ diff='diff -u'; \ else \ diff='diff'; \ fi; \ + set X $(TEST_EXTENSIONS); shift; \ + if test $$# -eq 0; then \ + echo '$@: INTERNAL ERROR: $$(TEST_EXTENSIONS) undefined' \ + 'or empty' >&2; \ + exit 255; \ + fi; \ + shift $$#; \ for t in $(TESTS); do \ echo "$$t"; \ done | sort >$(tmk); \ - glob="$(srcdir)/*.test"; \ - if test x"$(srcdir)" != x"$(builddir)"; then \ - glob="$$glob $(builddir)/*.test"; \ - fi; \ + for suf in $(TEST_EXTENSIONS); do \ + glob="$(srcdir)/*$$suf"; \ + if test x"$(srcdir)" != x"$(builddir)"; then \ + glob="$$glob $(builddir)/*$$suf"; \ + fi; \ + done; \ for t in $$glob; do \ echo "$$t"; \ done | sed 's,^.*/,,' | sort >$(tfs); \ @@ -1394,7 +1402,7 @@ maintainer-check-list-of-tests: $(parallel_tests) fi; \ rm -f $(tmk) $(tfs) $(tdf); \ exit $$e; -.PHONY: maintainer-check-list-of-tests +maintainer-check-list-of-tests: $(parallel_tests) clean-local: clean-local-check .PHONY: clean-local-check -- 1.6.5