tests: less uses of "make -e"; avoid spurious failures in 'check-cc-no-c-o'
[platform/upstream/automake.git] / t / Makefile.inc
1 ## Included by top-level Makefile for Automake.
2
3 ## Copyright (C) 1995-2013 Free Software Foundation, Inc.
4 ##
5 ## This program is free software; you can redistribute it and/or modify
6 ## it under the terms of the GNU General Public License as published by
7 ## the Free Software Foundation; either version 2, or (at your option)
8 ## any later version.
9 ##
10 ## This program is distributed in the hope that it will be useful,
11 ## but WITHOUT ANY WARRANTY; without even the implied warranty of
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 ## GNU General Public License for more details.
14 ##
15 ## You should have received a copy of the GNU General Public License
16 ## along with this program.  If not, see <http://www.gnu.org/licenses/>.
17
18 ## ------------ ##
19 ##  Testsuite.  ##
20 ## ------------ ##
21
22 # Run the tests with a proper shell detected at configure time.
23 LOG_COMPILER = $(AM_TEST_RUNNER_SHELL)
24
25 TEST_EXTENSIONS = .pl .sh .tap
26 SH_LOG_COMPILER = $(LOG_COMPILER)
27 TAP_LOG_COMPILER = $(LOG_COMPILER)
28 PL_LOG_COMPILER = $(PERL)
29 AM_PL_LOG_FLAGS = -Mstrict -I $(builddir)/lib -I $(srcdir)/lib -w
30
31 TAP_LOG_DRIVER = AM_TAP_AWK='$(AWK)' $(SHELL) $(srcdir)/lib/tap-driver.sh
32
33 AM_TAP_LOG_DRIVER_FLAGS = --merge
34
35 EXTRA_DIST += %D%/README %D%/ax/is %D%/ax/is_newest
36
37 ## Will be updated later.
38 TESTS =
39
40 # Some testsuite-influential variables should be overridable from the
41 # test scripts, but not from the environment.
42 # Keep this in sync with the similar list in ax/runtest.in.
43 AM_TESTS_ENVIRONMENT = \
44   for v in \
45     required \
46     am_test_protocol \
47     am_serial_tests \
48     am_test_prefer_config_shell \
49     am_original_AUTOMAKE \
50     am_original_ACLOCAL \
51     am_test_lib_sourced \
52     test_lib_sourced \
53   ; do \
54     eval test x"\$${$$v}" = x || unset $$v; \
55   done;
56 # We want warning messages and explanations for skipped tests to go to
57 # the console if possible, so set up 'stderr_fileno_' properly.
58 AM_TESTS_FD_REDIRECT = 9>&2
59 AM_TESTS_ENVIRONMENT += stderr_fileno_=9; export stderr_fileno_;
60
61 # For sourcing of extra "shell libraries" by our test scripts.  As per
62 # POSIX, sourcing a file with '.' will cause it to be looked up in $PATH
63 # in case it is given with a relative name containing no slashes.
64 AM_TESTS_ENVIRONMENT += \
65   if test $(srcdir) != .; then \
66     PATH='$(abs_srcdir)/%D%/ax'$(PATH_SEPARATOR)$$PATH; \
67   fi; \
68   PATH='$(abs_builddir)/%D%/ax'$(PATH_SEPARATOR)$$PATH; \
69   export PATH;
70
71 # Hand-written tests.
72
73 include $(srcdir)/%D%/list-of-tests.mk
74
75 TESTS += $(handwritten_TESTS)
76 EXTRA_DIST += $(handwritten_TESTS)
77
78 # Automatically-generated tests wrapping hand-written ones.
79 # Also, automatically-computed dependencies for tests.
80
81 include $(srcdir)/%D%/testsuite-part.am
82
83 TESTS += $(generated_TESTS)
84 EXTRA_DIST += $(generated_TESTS)
85
86 $(srcdir)/%D%/testsuite-part.am:
87         $(AM_V_at)rm -f %D%/testsuite-part.tmp $@
88         $(AM_V_GEN)$(PERL) $(srcdir)/gen-testsuite-part \
89           --srcdir $(srcdir) > %D%/testsuite-part.tmp
90         $(AM_V_at)chmod a-w %D%/testsuite-part.tmp
91         $(AM_V_at)mv -f %D%/testsuite-part.tmp $@
92 EXTRA_DIST += gen-testsuite-part
93
94 # The dependecies declared here are not truly complete, but such
95 # completeness would cause more issues than it would solve.  See
96 # automake bug#11347.
97 $(generated_TESTS): $(srcdir)/gen-testsuite-part
98 $(srcdir)/%D%/testsuite-part.am: $(srcdir)/gen-testsuite-part
99 $(srcdir)/%D%/testsuite-part.am: Makefile.am
100
101 # Hand-written tests for stuff in 'contrib/'.
102 include $(srcdir)/contrib/%D%/Makefile.inc
103 TESTS += $(contrib_TESTS)
104 EXTRA_DIST += $(contrib_TESTS)
105
106 # Static dependencies valid for each test case (also further
107 # extended later).  Note that use 'noinst_' rather than 'check_'
108 # as the prefix, because we really want them to be built by
109 # "make all".  This makes it easier to run the test cases by
110 # hand after having simply configured and built the package.
111
112 nodist_noinst_SCRIPTS += \
113   %D%/wrap/aclocal-$(APIVERSION) \
114   %D%/wrap/automake-$(APIVERSION)
115
116 dist_noinst_DATA += \
117   %D%/ax/test-init.sh \
118   %D%/ax/test-lib.sh \
119   %D%/ax/am-test-lib.sh \
120   %D%/ax/tap-functions.sh
121
122 # Few more static dependencies.
123 %D%/distcheck-missing-m4.log: %D%/ax/distcheck-hook-m4.am
124 %D%/distcheck-outdated-m4.log: %D%/ax/distcheck-hook-m4.am
125 EXTRA_DIST += %D%/ax/distcheck-hook-m4.am
126
127 %D%/ax/test-defs.sh: %D%/ax/test-defs.in Makefile
128         $(AM_V_at)rm -f $@ $@-t
129         $(AM_V_at)$(MKDIR_P) %D%/ax
130         $(AM_V_GEN)in=%D%/ax/test-defs.in \
131           && $(do_subst) <$(srcdir)/$$in >$@-t
132         $(generated_file_finalize)
133 EXTRA_DIST += %D%/ax/test-defs.in
134 CLEANFILES += %D%/ax/test-defs.sh
135 nodist_noinst_DATA += %D%/ax/test-defs.sh
136
137 %D%/ax/shell-no-trail-bslash: %D%/ax/shell-no-trail-bslash.in Makefile
138         $(AM_V_at)rm -f $@ $@-t
139         $(AM_V_GEN)in=%D%/ax/shell-no-trail-bslash.in \
140           && $(MKDIR_P) %D%/ax \
141           && $(do_subst) <$(srcdir)/$$in >$@-t \
142           && chmod a+x $@-t
143         $(generated_file_finalize)
144 EXTRA_DIST += %D%/ax/shell-no-trail-bslash.in
145 CLEANFILES += %D%/ax/shell-no-trail-bslash
146 nodist_noinst_SCRIPTS += %D%/ax/shell-no-trail-bslash
147
148 %D%/ax/cc-no-c-o: %D%/ax/cc-no-c-o.in Makefile
149         $(AM_V_at)rm -f $@ $@-t
150         $(AM_V_GEN)in=%D%/ax/cc-no-c-o.in \
151           && $(MKDIR_P) %D%/ax \
152           && $(do_subst) <$(srcdir)/$$in >$@-t \
153           && chmod a+x $@-t
154         $(generated_file_finalize)
155 EXTRA_DIST += %D%/ax/cc-no-c-o.in
156 CLEANFILES += %D%/ax/cc-no-c-o
157 nodist_noinst_SCRIPTS += %D%/ax/cc-no-c-o
158
159 runtest: %D%/ax/runtest.in Makefile
160         $(AM_V_at)rm -f $@ $@-t
161         $(AM_V_GEN)in=%D%/ax/runtest.in \
162           && $(MKDIR_P) %D%/ax \
163           && $(do_subst) <$(srcdir)/$$in >$@-t \
164           && chmod a+x $@-t
165         $(generated_file_finalize)
166 EXTRA_DIST += %D%/ax/runtest.in
167 CLEANFILES += runtest
168 nodist_noinst_SCRIPTS += runtest
169
170 # If two test scripts have the same basename, they will end up sharing
171 # the same log file, leading to all sort of undefined and undesired
172 # behaviours.
173 check-no-repeated-test-name:
174         @LC_ALL=C; export LC_ALL; \
175          lst='$(TEST_LOGS)'; for log in $$lst; do echo $$log; done \
176            | sort | uniq -c | awk '($$1 > 1) { print }' \
177            | sed 's/\.log$$//' | grep . >&2 \
178            && { \
179              echo $@: test names listed above are duplicated >&2; \
180              exit 1; \
181            }; :
182 check-local: check-no-repeated-test-name
183 .PHONY: check-no-repeated-test-name
184
185 # Check that our test cases are syntactically correct.
186 # See automake bug#11898.
187 check-tests-syntax:
188         @st=0; \
189         err () { echo "$@: $$*" >&2; st=1; }; \
190 ## The user might do something like "make check TESTS=t/foo" or
191 ## "make check TESTS_LOGS=t/foo.log" and expect (say) the test
192 ## 't/foo.sh' to be run; this has worked well until today, and
193 ## we want to continue supporting this use case.
194         bases=`for log in : $(TEST_LOGS); do echo $$log; done \
195           | sed -e '/^:$$/d' -e 's/\.log$$//'`; \
196         for bas in $$bases; do \
197           for suf in sh tap pl; do \
198             tst=$$bas.$$suf; \
199 ## Emulate VPATH search.
200             if test -f $$tst; then \
201               break; \
202             elif test -f $(srcdir)/$$tst; then \
203               tst=$(srcdir)/$$tst; \
204               break; \
205             else \
206               tst=''; \
207             fi; \
208           done; \
209           test -n "$$tst" || err "couldn't find test '$$bas'"; \
210 ## Don't check that perl tests are valid shell scripts!
211           test $$suf = pl && continue; \
212           $(AM_V_P) && echo " $(AM_TEST_RUNNER_SHELL) -n $$tst"; \
213           $(AM_TEST_RUNNER_SHELL) -n "$$tst" \
214             || err "test '$$tst' syntactically invalid"; \
215         done; \
216         exit $$st
217 check-local: check-tests-syntax
218 .PHONY: check-tests-syntax
219
220 # Recipes with a trailing backslash character (possibly followed by
221 # blank characters only) can cause spurious syntax errors with at
222 # least older bash versions (e.g., bash 2.05b), and can be potentially
223 # be unportable to other weaker shells.  Run the testsuite in a way
224 # that helps catching such problems in Automake-generated recipes.
225 # See automake bug#10436.
226 check-no-trailing-backslash-in-recipes:
227         $(AM_V_GEN)$(MAKE) $(AM_MAKEFLAGS) check \
228           CONFIG_SHELL='$(abs_top_builddir)/%D%/ax/shell-no-trail-bslash'
229 .PHONY: check-no-trailing-backslash-in-recipes
230
231 # Some compilers out there (hello, MSVC) still choke on "-c -o" being
232 # passed together on the command line.  Run the whole testsuite faking
233 # the presence of such a compiler, to help catch regressions that would
234 # otherwise only present themselves later "in the wild".  See also the
235 # long discussion about automake bug#13378.
236 check-cc-no-c-o:
237         $(AM_V_GEN)$(MAKE) $(AM_MAKEFLAGS) check \
238           AM_TESTSUITE_SIMULATING_NO_CC_C_O=yes
239 .PHONY: check-cc-no-c-o
240
241 ## Checking the list of tests.
242 test_subdirs = %D% %D%/pm contrib/%D%
243 include %D%/CheckListOfTests.am
244
245 # Run the testsuite with the installed aclocal and automake.
246 installcheck-local: installcheck-testsuite
247 installcheck-testsuite:
248         $(AM_V_GEN)$(MAKE) $(AM_MAKEFLAGS) check \
249           am_running_installcheck=yes
250
251 # Performance tests.
252 .PHONY: perf
253 perf: all
254         $(AM_V_GEN)$(MAKE) $(AM_MAKEFLAGS) check \
255           TEST_SUITE_LOG='$(PERF_TEST_SUITE_LOG)' TESTS='$(perf_TESTS)'
256 PERF_TEST_SUITE_LOG = %D%/perf/test-suite.log
257 CLEANFILES += $(PERF_TEST_SUITE_LOG)
258 EXTRA_DIST += $(perf_TESTS)
259
260 clean-local: clean-local-check
261 .PHONY: clean-local-check
262 clean-local-check:
263 ## Directories candidate to be test directories match this wildcard.
264         @globs='%D%/*.dir %D%/*/*.dir */%D%/*.dir */%D%/*/*.dir'; \
265 ## The 'nullglob' bash option is not portable, so use perl.
266         dirs=`$(PERL) -e "print join(' ', glob('$$globs'));"` || exit 1; \
267         if test -n "$$dirs"; then \
268 ## Errors in find are acceptable, errors in rm are not.
269             find $$dirs -type d ! -perm -700 -exec chmod u+rwx {} ';'; \
270             echo " rm -rf $$dirs"; \
271             rm -rf $$dirs || exit 1; \
272         fi
273
274 # vim: ft=automake noet