Add an optional testfn parameter to assoc
[emacs.git] / test / Makefile.in
blob414eca905648d1aaf45375b61272204a661b3509
1 ### @configure_input@
3 # Copyright (C) 2010-2017 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 <http://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 VPATH = $(srcdir)
36 FIND_DELETE = @FIND_DELETE@
37 MKDIR_P = @MKDIR_P@
38 CC = @CC@
39 CFLAGS = @CFLAGS@
40 PROFILING_CFLAGS = @PROFILING_CFLAGS@
41 WARN_CFLAGS = @WARN_CFLAGS@
42 WERROR_CFLAGS = @WERROR_CFLAGS@
43 CPPFLAGS = @CPPFLAGS@
44 SO = @MODULES_SUFFIX@
46 SEPCHAR = @SEPCHAR@
49 # 'make' verbosity.
50 AM_DEFAULT_VERBOSITY = @AM_DEFAULT_VERBOSITY@
52 AM_V_CCLD = $(am__v_CCLD_@AM_V@)
53 am__v_CCLD_ = $(am__v_CCLD_@AM_DEFAULT_V@)
54 am__v_CCLD_0 = @echo " CCLD " $@;
55 am__v_CCLD_1 =
57 AM_V_ELC = $(am__v_ELC_@AM_V@)
58 am__v_ELC_ = $(am__v_ELC_@AM_DEFAULT_V@)
59 am__v_ELC_0 = @echo " ELC " $@;
60 am__v_ELC_1 =
62 AM_V_GEN = $(am__v_GEN_@AM_V@)
63 am__v_GEN_ = $(am__v_GEN_@AM_DEFAULT_V@)
64 am__v_GEN_0 = @echo " GEN " $@;
65 am__v_GEN_1 =
67 AM_V_at = $(am__v_at_@AM_V@)
68 am__v_at_ = $(am__v_at_@AM_DEFAULT_V@)
69 am__v_at_0 = @
70 am__v_at_1 =
73 # We never change directory before running Emacs, so a relative file
74 # name is fine, and makes life easier. If we need to change
75 # directory, we can use emacs --chdir.
76 EMACS = ../src/emacs
78 EMACS_EXTRAOPT=
80 # Command line flags for Emacs.
81 # Apparently MSYS bash would convert "-L :" to "-L ;" anyway,
82 # but we might as well be explicit.
83 EMACSOPT = -batch --no-site-file --no-site-lisp -L "$(SEPCHAR)$(srcdir)" $(EMACS_EXTRAOPT)
85 # Prevent any settings in the user environment causing problems.
86 unexport EMACSDATA EMACSDOC EMACSPATH GREP_OPTIONS
88 ## To run tests under a debugger, set this to eg: "gdb --args".
89 GDB =
91 # The locale to run tests under. Tests should work if this is set to
92 # any supported locale. Use the C locale by default, as it should be
93 # supported everywhere.
94 TEST_LOCALE = C
96 # Whether to run tests from .el files in preference to .elc, we do
97 # this by default since it gives nicer stacktraces.
98 TEST_LOAD_EL ?= yes
100 ifeq (@HAVE_MODULES@, yes)
101 MODULES_EMACSOPT := --module-assertions
102 else
103 MODULES_EMACSOPT :=
104 endif
106 # The actual Emacs command run in the targets below.
107 # Prevent any setting of EMACSLOADPATH in user environment causing problems.
108 emacs = EMACSLOADPATH= LC_ALL=$(TEST_LOCALE) \
109 EMACS_TEST_DIRECTORY=$(abspath $(srcdir)) \
110 $(GDB) "$(EMACS)" $(MODULES_EMACSOPT) $(EMACSOPT)
112 test_module_dir := $(srcdir)/data/emacs-module
114 .PHONY: all check
116 all: check
118 SELECTOR_DEFAULT = (quote (not (tag :expensive-test)))
119 SELECTOR_EXPENSIVE = nil
120 ifdef SELECTOR
121 SELECTOR_ACTUAL=$(SELECTOR)
122 else ifndef MAKECMDGOALS
123 SELECTOR_ACTUAL=$(SELECTOR_DEFAULT)
124 else ifeq ($(MAKECMDGOALS),all)
125 SELECTOR_ACTUAL=$(SELECTOR_DEFAULT)
126 else ifeq ($(MAKECMDGOALS),check)
127 SELECTOR_ACTUAL=$(SELECTOR_DEFAULT)
128 else ifeq ($(MAKECMDGOALS),check-maybe)
129 SELECTOR_ACTUAL=$(SELECTOR_DEFAULT)
130 else
131 SELECTOR_ACTUAL=$(SELECTOR_EXPENSIVE)
132 endif
134 ## Byte-compile all test files to test for errors.
135 %.elc: %.el
136 $(AM_V_ELC)$(emacs) -f batch-byte-compile $<
138 ## Save logs, and show logs for failed tests.
139 WRITE_LOG = > $@ 2>&1 || { STAT=$$?; cat $@; exit $$STAT; }
141 ifeq ($(TEST_LOAD_EL), yes)
142 testloadfile = $*.el
143 else
144 testloadfile = $*
145 endif
147 %.log: %.elc
148 $(AM_V_at)${MKDIR_P} $(dir $@)
149 $(AM_V_GEN)HOME=/nonexistent $(emacs) -l ert -l $(testloadfile) \
150 --eval "(ert-run-tests-batch-and-exit ${SELECTOR_ACTUAL})" ${WRITE_LOG}
152 ifeq (@HAVE_MODULES@, yes)
153 maybe_exclude_module_tests :=
154 else
155 maybe_exclude_module_tests := -name emacs-module-tests.el -prune -o
156 endif
158 ELFILES := $(shell find ${srcdir} -path "${srcdir}/manual" -prune -o \
159 -path "${srcdir}/data" -prune -o \
160 -name "*resources" -prune -o \
161 ${maybe_exclude_module_tests} \
162 -name "*.el" ! -name ".*" -print)
163 ## .log files may be in a different directory for out of source builds
164 LOGFILES := $(patsubst %.el,%.log, \
165 $(patsubst $(srcdir)/%,%,$(ELFILES)))
166 TESTS := $(LOGFILES:.log=)
168 ## If we have to interrupt a hanging test, preserve the log so we can
169 ## see what the problem was.
170 .PRECIOUS: %.log
172 ## Stop make deleting these as intermediate files.
173 .SECONDARY: ${ELFILES:.el=.elc} $(test_module_dir)/*.o
175 .PHONY: ${TESTS}
177 define test_template
178 ## A test FOO-tests depends on the source file with the similar
179 ## name, unless FOO itself contains the string '-tests/'.
180 ## The similar name is FOO.c if FOO begins with 'src/', FOO.el
181 ## otherwise. Although this heuristic does not identify all the
182 ## dependencies, it is better than nothing.
183 ifeq (,$(patsubst %-tests,,$(1))$(findstring -tests/,$(1)))
184 $(1).log: $(patsubst %-tests,$(srcdir)/../%,$(1))$(if \
185 $(patsubst src/%,,$(1)),.el,.c)
186 endif
188 ## Short aliases that always re-run the tests, with no logging.
189 ## Define both with and without the directory name for ease of use.
190 .PHONY: $(1) $(notdir $(1))
191 $(1):
192 @test ! -f $(1).log || mv $(1).log $(1).log~
193 @$(MAKE) $(1).log WRITE_LOG=
194 $(notdir $(1)): $(1)
195 endef
197 $(foreach test,${TESTS},$(eval $(call test_template,${test})))
199 ifeq (@HAVE_MODULES@, yes)
200 # -fPIC is a no-op on Windows, but causes a compiler warning
201 ifeq ($(SO),.dll)
202 FPIC_CFLAGS =
203 else
204 FPIC_CFLAGS = -fPIC
205 endif
207 MODULE_CFLAGS = -I$(srcdir)/../src $(FPIC_CFLAGS) $(PROFILING_CFLAGS) \
208 $(WARN_CFLAGS) $(WERROR_CFLAGS) $(CFLAGS)
210 test_module = $(test_module_dir)/mod-test${SO}
211 src/emacs-module-tests.log: $(test_module)
212 $(test_module): $(test_module:${SO}=.c) $(srcdir)/../src/emacs-module.h
213 $(AM_V_CCLD)$(CC) -shared $(CPPFLAGS) $(MODULE_CFLAGS) $(LDFLAGS) \
214 -o $@ $<
215 endif
217 ## Check that there is no 'automated' subdirectory, which would
218 ## indicate an incomplete merge from an older version of Emacs where
219 ## the tests were arranged differently.
220 .PHONY: check-no-automated-subdir
221 check-no-automated-subdir:
222 test ! -d $(srcdir)/automated
224 ## Rerun all default tests.
225 check: mostlyclean check-no-automated-subdir
226 @${MAKE} check-doit SELECTOR="${SELECTOR_ACTUAL}"
228 ## Rerun all default and expensive tests.
229 .PHONY: check-expensive
230 check-expensive: mostlyclean check-no-automated-subdir
231 @${MAKE} check-doit SELECTOR="${SELECTOR_EXPENSIVE}"
233 ## Re-run all tests which are outdated. A test is outdated if its
234 ## logfile is out-of-date with either the test file, or the source
235 ## files that the tests depend on. See test_template.
236 .PHONY: check-maybe
237 check-maybe: check-no-automated-subdir
238 @${MAKE} check-doit SELECTOR="${SELECTOR_ACTUAL}"
240 ## Run the tests.
241 .PHONY: check-doit
242 ## We can't put LOGFILES as prerequisites, because that would stop the
243 ## summarizing step from running when there is an error.
244 check-doit:
245 -@${MAKE} -k ${LOGFILES}
246 @$(emacs) -l ert -f ert-summarize-tests-batch-and-exit ${LOGFILES}
248 .PHONY: mostlyclean clean bootstrap-clean distclean maintainer-clean
250 mostlyclean:
251 -@for f in ${LOGFILES}; do test ! -f $$f || mv $$f $$f~; done
252 rm -f *.tmp
254 clean:
255 find . '(' -name '*.log' -o -name '*.log~' ')' $(FIND_DELETE)
256 rm -f $(test_module_dir)/*.o $(test_module_dir)/*.so \
257 $(test_module_dir)/*.dll
259 bootstrap-clean: clean
260 find $(srcdir) -name '*.elc' $(FIND_DELETE)
262 distclean: clean
263 rm -f Makefile
265 maintainer-clean: distclean bootstrap-clean