Output alists with dotted pair notation in .dir-locals.el
[emacs.git] / test / Makefile.in
blobadb316c3d9cabd2bfa74b454c38e11a2c5e1b3d1
1 ### @configure_input@
3 # Copyright (C) 2010-2018 Free Software Foundation, Inc.
5 # This file is part of GNU Emacs.
7 # GNU Emacs is free software: you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation, either version 3 of the License, or
10 # (at your option) any later version.
12 # GNU Emacs is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>.
20 ### Commentary:
22 ## Some targets:
23 ## check: re-run all tests, writing to .log files.
24 ## check-maybe: run all tests which are outdated with their .log file
25 ## or the source files they are testing.
26 ## filename.log: run tests from filename.el(c) if .log file needs updating
27 ## filename: re-run tests from filename.el(c), with no logging
29 ### Code:
31 SHELL = @SHELL@
33 srcdir = @srcdir@
34 abs_top_srcdir=@abs_top_srcdir@
35 VPATH = $(srcdir)
37 FIND_DELETE = @FIND_DELETE@
38 MKDIR_P = @MKDIR_P@
39 CC = @CC@
40 CFLAGS = @CFLAGS@
41 PROFILING_CFLAGS = @PROFILING_CFLAGS@
42 WARN_CFLAGS = @WARN_CFLAGS@
43 WERROR_CFLAGS = @WERROR_CFLAGS@
44 CPPFLAGS = @CPPFLAGS@
45 SO = @MODULES_SUFFIX@
47 SEPCHAR = @SEPCHAR@
50 # 'make' verbosity.
51 AM_DEFAULT_VERBOSITY = @AM_DEFAULT_VERBOSITY@
53 AM_V_CCLD = $(am__v_CCLD_@AM_V@)
54 am__v_CCLD_ = $(am__v_CCLD_@AM_DEFAULT_V@)
55 am__v_CCLD_0 = @echo " CCLD " $@;
56 am__v_CCLD_1 =
58 AM_V_ELC = $(am__v_ELC_@AM_V@)
59 am__v_ELC_ = $(am__v_ELC_@AM_DEFAULT_V@)
60 am__v_ELC_0 = @echo " ELC " $@;
61 am__v_ELC_1 =
63 AM_V_GEN = $(am__v_GEN_@AM_V@)
64 am__v_GEN_ = $(am__v_GEN_@AM_DEFAULT_V@)
65 am__v_GEN_0 = @echo " GEN " $@;
66 am__v_GEN_1 =
68 AM_V_at = $(am__v_at_@AM_V@)
69 am__v_at_ = $(am__v_at_@AM_DEFAULT_V@)
70 am__v_at_0 = @
71 am__v_at_1 =
74 # We never change directory before running Emacs, so a relative file
75 # name is fine, and makes life easier. If we need to change
76 # directory, we can use emacs --chdir.
77 EMACS = ../src/emacs
79 EMACS_EXTRAOPT=
81 # Command line flags for Emacs.
82 # Apparently MSYS bash would convert "-L :" to "-L ;" anyway,
83 # but we might as well be explicit.
84 EMACSOPT = --no-init-file --no-site-file --no-site-lisp -L "$(SEPCHAR)$(srcdir)" $(EMACS_EXTRAOPT)
86 # Prevent any settings in the user environment causing problems.
87 unexport EMACSDATA EMACSDOC EMACSPATH GREP_OPTIONS
89 ## To run tests under a debugger, set this to eg: "gdb --args".
90 GDB =
92 # The locale to run tests under. Tests should work if this is set to
93 # any supported locale. Use the C locale by default, as it should be
94 # supported everywhere.
95 TEST_LOCALE = C
97 # Set this to 'yes' to run the tests in an interactive instance.
98 TEST_INTERACTIVE ?= no
100 ifeq ($(TEST_INTERACTIVE),yes)
101 TEST_RUN_ERT = --eval '(ert (quote ${SELECTOR_ACTUAL}))'
102 else
103 TEST_RUN_ERT = --batch --eval '(ert-run-tests-batch-and-exit (quote ${SELECTOR_ACTUAL}))' ${WRITE_LOG}
104 endif
106 # Whether to run tests from .el files in preference to .elc, we do
107 # this by default since it gives nicer stacktraces.
108 # If you just want a pass/fail, setting this to no is much faster.
109 export TEST_LOAD_EL ?= \
110 $(if $(findstring $(MAKECMDGOALS), all check check-maybe),no,yes)
112 # Additional settings for ert.
113 ert_opts =
115 # Maximum length of lines in ert backtraces; nil for no limit.
116 # (if empty, use the default ert-batch-backtrace-right-margin).
117 TEST_BACKTRACE_LINE_LENGTH =
119 ifneq (${TEST_BACKTRACE_LINE_LENGTH},)
120 ert_opts += --eval '(setq ert-batch-backtrace-right-margin ${TEST_BACKTRACE_LINE_LENGTH})'
121 endif
123 ifeq (@HAVE_MODULES@, yes)
124 MODULES_EMACSOPT := --module-assertions
125 else
126 MODULES_EMACSOPT :=
127 endif
129 # The actual Emacs command run in the targets below.
130 # Prevent any setting of EMACSLOADPATH in user environment causing problems.
131 emacs = EMACSLOADPATH= LC_ALL=$(TEST_LOCALE) \
132 EMACS_TEST_DIRECTORY=$(abspath $(srcdir)) \
133 $(GDB) "$(EMACS)" $(MODULES_EMACSOPT) $(EMACSOPT)
135 # Set HOME to a nonexistent directory to prevent tests from accessing
136 # it accidentally (e.g., popping up a gnupg dialog if ~/.authinfo.gpg
137 # exists, or writing to ~/.bzr.log when running bzr commands).
138 TEST_HOME = /nonexistent
140 test_module_dir := data/emacs-module
142 .PHONY: all check
144 all: check
146 SELECTOR_DEFAULT = (not (or (tag :expensive-test) (tag :unstable)))
147 SELECTOR_EXPENSIVE = (not (tag :unstable))
148 SELECTOR_ALL = t
149 ifdef SELECTOR
150 SELECTOR_ACTUAL=$(SELECTOR)
151 else ifndef MAKECMDGOALS
152 SELECTOR_ACTUAL=$(SELECTOR_DEFAULT)
153 else ifeq ($(MAKECMDGOALS),all)
154 SELECTOR_ACTUAL=$(SELECTOR_DEFAULT)
155 else ifeq ($(MAKECMDGOALS),check)
156 SELECTOR_ACTUAL=$(SELECTOR_DEFAULT)
157 else ifeq ($(MAKECMDGOALS),check-maybe)
158 SELECTOR_ACTUAL=$(SELECTOR_DEFAULT)
159 else
160 SELECTOR_ACTUAL=$(SELECTOR_EXPENSIVE)
161 endif
163 ## Byte-compile all test files to test for errors.
164 %.elc: %.el
165 $(AM_V_ELC)$(emacs) --batch -f batch-byte-compile $<
167 ## Save logs, and show logs for failed tests.
168 WRITE_LOG = > $@ 2>&1 || { STAT=$$?; cat $@; exit $$STAT; }
169 ifdef EMACS_HYDRA_CI
170 ## On Hydra, always show logs for certain problematic tests.
171 lisp/net/tramp-tests.log \
172 : WRITE_LOG = 2>&1 | tee $@
173 endif
175 ifeq ($(TEST_LOAD_EL), yes)
176 testloadfile = $*.el
177 else
178 testloadfile = $*
179 endif
181 %.log: %.elc
182 $(AM_V_at)${MKDIR_P} $(dir $@)
183 $(AM_V_GEN)HOME=$(TEST_HOME) $(emacs) \
184 -l ert ${ert_opts} -l $(testloadfile) \
185 $(TEST_RUN_ERT)
187 ifeq (@HAVE_MODULES@, yes)
188 maybe_exclude_module_tests :=
189 else
190 maybe_exclude_module_tests := -name emacs-module-tests.el -prune -o
191 endif
193 ## To speed up parallel builds, put these slow test files (which can
194 ## take longer than all the rest combined) at the start of the list.
195 SLOW_TESTS = ${srcdir}/lisp/net/tramp-tests.el
197 ELFILES := $(sort $(shell find ${srcdir} -path "${srcdir}/manual" -prune -o \
198 -path "${srcdir}/data" -prune -o \
199 -name "*resources" -prune -o \
200 ${maybe_exclude_module_tests} \
201 -name "*.el" ! -name ".*" -print))
203 $(foreach slow,${SLOW_TESTS},$(eval ELFILES:= ${slow} $(filter-out ${slow},${ELFILES})))
205 ## .log files may be in a different directory for out of source builds
206 LOGFILES := $(patsubst %.el,%.log, \
207 $(patsubst $(srcdir)/%,%,$(ELFILES)))
208 TESTS := $(LOGFILES:.log=)
210 ## If we have to interrupt a hanging test, preserve the log so we can
211 ## see what the problem was.
212 .PRECIOUS: %.log
214 ## Stop make deleting these as intermediate files.
215 .SECONDARY: ${ELFILES:.el=.elc} $(test_module_dir)/*.o
217 .PHONY: ${TESTS}
219 define test_template
220 ## A test FOO-tests depends on the source file with the similar
221 ## name, unless FOO itself contains the string '-tests/'.
222 ## The similar name is FOO.c if FOO begins with '{lib-,}src/', FOO.el
223 ## otherwise. Although this heuristic does not identify all the
224 ## dependencies, it is better than nothing.
225 ifeq (,$(patsubst %-tests,,$(1))$(findstring -tests/,$(1)))
226 $(1).log: $(patsubst %-tests,$(srcdir)/../%,$(1))$(if \
227 $(patsubst src/%,,$(patsubst lib-src/%,,$(1))),.el,.c)
228 endif
230 ## Short aliases that always re-run the tests, with no logging.
231 ## Define both with and without the directory name for ease of use.
232 .PHONY: $(1) $(notdir $(1))
233 $(1):
234 @test ! -f $(1).log || mv $(1).log $(1).log~
235 @$(MAKE) $(1).log WRITE_LOG=
236 $(notdir $(1)): $(1)
237 endef
239 $(foreach test,${TESTS},$(eval $(call test_template,${test})))
241 ifeq (@HAVE_MODULES@, yes)
242 # -fPIC is a no-op on Windows, but causes a compiler warning
243 ifeq ($(SO),.dll)
244 FPIC_CFLAGS =
245 else
246 FPIC_CFLAGS = -fPIC
247 endif
249 # Note: emacs-module.h is generated from emacs-module.h.in, hence we
250 # look in ../src, not $(srcdir)/../src.
251 MODULE_CFLAGS = -I../src $(FPIC_CFLAGS) $(PROFILING_CFLAGS) \
252 $(WARN_CFLAGS) $(WERROR_CFLAGS) $(CFLAGS)
254 test_module = $(test_module_dir)/mod-test${SO}
255 src/emacs-module-tests.log: $(test_module)
256 $(test_module): $(test_module:${SO}=.c) ../src/emacs-module.h
257 $(AM_V_at)${MKDIR_P} $(dir $@)
258 $(AM_V_CCLD)$(CC) -shared $(CPPFLAGS) $(MODULE_CFLAGS) $(LDFLAGS) \
259 -o $@ $<
260 endif
262 ## Check that there is no 'automated' subdirectory, which would
263 ## indicate an incomplete merge from an older version of Emacs where
264 ## the tests were arranged differently.
265 .PHONY: check-no-automated-subdir
266 check-no-automated-subdir:
267 ${AM_V_at}test ! -d $(srcdir)/automated
269 ## Rerun all default tests.
270 check: mostlyclean check-no-automated-subdir
271 @${MAKE} check-doit SELECTOR="${SELECTOR_ACTUAL}"
273 ## Rerun all default and expensive tests.
274 .PHONY: check-expensive
275 check-expensive: mostlyclean check-no-automated-subdir
276 @${MAKE} check-doit SELECTOR="${SELECTOR_EXPENSIVE}"
278 ## Run all tests, regardless of tag.
279 .PHONY: check-all
280 check-all: mostlyclean check-no-automated-subdir
281 @${MAKE} check-doit SELECTOR="${SELECTOR_ALL}"
283 ## Re-run all tests which are outdated. A test is outdated if its
284 ## logfile is out-of-date with either the test file, or the source
285 ## files that the tests depend on. See test_template.
286 .PHONY: check-maybe
287 check-maybe: check-no-automated-subdir
288 @${MAKE} check-doit SELECTOR="${SELECTOR_ACTUAL}"
290 ## Run the tests.
291 .PHONY: check-doit
292 ## We can't put LOGFILES as prerequisites, because that would stop the
293 ## summarizing step from running when there is an error.
294 check-doit:
295 ifeq ($(TEST_INTERACTIVE), yes)
296 HOME=$(TEST_HOME) $(emacs) \
297 -l ert ${ert_opts} \
298 $(patsubst %,-l %,$(if $(findstring $(TEST_LOAD_EL),yes),$ELFILES,$(ELFILES:.el=))) \
299 $(TEST_RUN_ERT)
300 else
301 -@${MAKE} -k ${LOGFILES}
302 @$(emacs) --batch -l ert --eval \
303 "(ert-summarize-tests-batch-and-exit ${SUMMARIZE_TESTS})" ${LOGFILES}
304 endif
306 .PHONY: mostlyclean clean bootstrap-clean distclean maintainer-clean
308 mostlyclean:
309 -@for f in ${LOGFILES}; do test ! -f $$f || mv $$f $$f~; done
310 rm -f ./*.tmp
312 clean:
313 find . '(' -name '*.log' -o -name '*.log~' ')' $(FIND_DELETE)
314 rm -f $(test_module_dir)/*.o $(test_module_dir)/*.so \
315 $(test_module_dir)/*.dll
317 bootstrap-clean: clean
318 find $(srcdir) -name '*.elc' $(FIND_DELETE)
320 distclean: clean
321 rm -f Makefile
323 maintainer-clean: distclean bootstrap-clean
325 .PHONY: check-declare
327 check-declare:
328 $(emacs) -l check-declare \
329 --eval '(check-declare-directory "$(srcdir)")'