Update authors.el
[emacs.git] / test / Makefile.in
blob17ab36f5af54826697b65e031e6d0d6a947de09d
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 <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 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 # Maximum length of lines in ert backtraces; nil for no limit.
101 # (if empty, use the default ert-batch-backtrace-right-margin).
102 TEST_BACKTRACE_LINE_LENGTH =
104 ifeq (${TEST_BACKTRACE_LINE_LENGTH},)
105 ert_opts =
106 else
107 ert_opts = --eval '(setq ert-batch-backtrace-right-margin ${TEST_BACKTRACE_LINE_LENGTH})'
108 endif
110 ifeq (@HAVE_MODULES@, yes)
111 MODULES_EMACSOPT := --module-assertions
112 else
113 MODULES_EMACSOPT :=
114 endif
116 # The actual Emacs command run in the targets below.
117 # Prevent any setting of EMACSLOADPATH in user environment causing problems.
118 emacs = EMACSLOADPATH= LC_ALL=$(TEST_LOCALE) \
119 EMACS_TEST_DIRECTORY=$(abspath $(srcdir)) \
120 $(GDB) "$(EMACS)" $(MODULES_EMACSOPT) $(EMACSOPT)
122 test_module_dir := $(srcdir)/data/emacs-module
124 .PHONY: all check
126 all: check
128 SELECTOR_DEFAULT = (quote (not (tag :expensive-test)))
129 SELECTOR_EXPENSIVE = nil
130 ifdef SELECTOR
131 SELECTOR_ACTUAL=$(SELECTOR)
132 else ifndef MAKECMDGOALS
133 SELECTOR_ACTUAL=$(SELECTOR_DEFAULT)
134 else ifeq ($(MAKECMDGOALS),all)
135 SELECTOR_ACTUAL=$(SELECTOR_DEFAULT)
136 else ifeq ($(MAKECMDGOALS),check)
137 SELECTOR_ACTUAL=$(SELECTOR_DEFAULT)
138 else ifeq ($(MAKECMDGOALS),check-maybe)
139 SELECTOR_ACTUAL=$(SELECTOR_DEFAULT)
140 else
141 SELECTOR_ACTUAL=$(SELECTOR_EXPENSIVE)
142 endif
144 ## Byte-compile all test files to test for errors.
145 %.elc: %.el
146 $(AM_V_ELC)$(emacs) -f batch-byte-compile $<
148 ## Save logs, and show logs for failed tests.
149 WRITE_LOG = $(if $(and ${EMACS_HYDRA_CI}, $(findstring tramp, $@)), |& tee $@, > $@ 2>&1) \
150 || { STAT=$$?; cat $@; exit $$STAT; }
152 ifeq ($(TEST_LOAD_EL), yes)
153 testloadfile = $*.el
154 else
155 testloadfile = $*
156 endif
158 %.log: %.elc
159 $(AM_V_at)${MKDIR_P} $(dir $@)
160 $(AM_V_GEN)HOME=/nonexistent $(emacs) \
161 -l ert ${ert_opts} -l $(testloadfile) \
162 --eval "(ert-run-tests-batch-and-exit ${SELECTOR_ACTUAL})" ${WRITE_LOG}
164 ifeq (@HAVE_MODULES@, yes)
165 maybe_exclude_module_tests :=
166 else
167 maybe_exclude_module_tests := -name emacs-module-tests.el -prune -o
168 endif
170 ELFILES := $(sort $(shell find ${srcdir} -path "${srcdir}/manual" -prune -o \
171 -path "${srcdir}/data" -prune -o \
172 -name "*resources" -prune -o \
173 ${maybe_exclude_module_tests} \
174 -name "*.el" ! -name ".*" -print))
175 ## .log files may be in a different directory for out of source builds
176 LOGFILES := $(patsubst %.el,%.log, \
177 $(patsubst $(srcdir)/%,%,$(ELFILES)))
178 TESTS := $(LOGFILES:.log=)
180 ## If we have to interrupt a hanging test, preserve the log so we can
181 ## see what the problem was.
182 .PRECIOUS: %.log
184 ## Stop make deleting these as intermediate files.
185 .SECONDARY: ${ELFILES:.el=.elc} $(test_module_dir)/*.o
187 .PHONY: ${TESTS}
189 define test_template
190 ## A test FOO-tests depends on the source file with the similar
191 ## name, unless FOO itself contains the string '-tests/'.
192 ## The similar name is FOO.c if FOO begins with '{lib-,}src/', FOO.el
193 ## otherwise. Although this heuristic does not identify all the
194 ## dependencies, it is better than nothing.
195 ifeq (,$(patsubst %-tests,,$(1))$(findstring -tests/,$(1)))
196 $(1).log: $(patsubst %-tests,$(srcdir)/../%,$(1))$(if \
197 $(patsubst src/%,,$(patsubst lib-src/%,,$(1))),.el,.c)
198 endif
200 ## Short aliases that always re-run the tests, with no logging.
201 ## Define both with and without the directory name for ease of use.
202 .PHONY: $(1) $(notdir $(1))
203 $(1):
204 @test ! -f $(1).log || mv $(1).log $(1).log~
205 @$(MAKE) $(1).log WRITE_LOG=
206 $(notdir $(1)): $(1)
207 endef
209 $(foreach test,${TESTS},$(eval $(call test_template,${test})))
211 ifeq (@HAVE_MODULES@, yes)
212 # -fPIC is a no-op on Windows, but causes a compiler warning
213 ifeq ($(SO),.dll)
214 FPIC_CFLAGS =
215 else
216 FPIC_CFLAGS = -fPIC
217 endif
219 MODULE_CFLAGS = -I$(srcdir)/../src $(FPIC_CFLAGS) $(PROFILING_CFLAGS) \
220 $(WARN_CFLAGS) $(WERROR_CFLAGS) $(CFLAGS)
222 test_module = $(test_module_dir)/mod-test${SO}
223 src/emacs-module-tests.log: $(test_module)
224 $(test_module): $(test_module:${SO}=.c) $(srcdir)/../src/emacs-module.h
225 $(AM_V_CCLD)$(CC) -shared $(CPPFLAGS) $(MODULE_CFLAGS) $(LDFLAGS) \
226 -o $@ $<
227 endif
229 ## Check that there is no 'automated' subdirectory, which would
230 ## indicate an incomplete merge from an older version of Emacs where
231 ## the tests were arranged differently.
232 .PHONY: check-no-automated-subdir
233 check-no-automated-subdir:
234 ${AM_V_at}test ! -d $(srcdir)/automated
236 ## Rerun all default tests.
237 check: mostlyclean check-no-automated-subdir
238 @${MAKE} check-doit SELECTOR="${SELECTOR_ACTUAL}"
240 ## Rerun all default and expensive tests.
241 .PHONY: check-expensive
242 check-expensive: mostlyclean check-no-automated-subdir
243 @${MAKE} check-doit SELECTOR="${SELECTOR_EXPENSIVE}"
245 ## Re-run all tests which are outdated. A test is outdated if its
246 ## logfile is out-of-date with either the test file, or the source
247 ## files that the tests depend on. See test_template.
248 .PHONY: check-maybe
249 check-maybe: check-no-automated-subdir
250 @${MAKE} check-doit SELECTOR="${SELECTOR_ACTUAL}"
252 ## Run the tests.
253 .PHONY: check-doit
254 ## We can't put LOGFILES as prerequisites, because that would stop the
255 ## summarizing step from running when there is an error.
256 check-doit:
257 -@${MAKE} -k ${LOGFILES}
258 @$(emacs) -l ert -f ert-summarize-tests-batch-and-exit ${LOGFILES}
260 .PHONY: mostlyclean clean bootstrap-clean distclean maintainer-clean
262 mostlyclean:
263 -@for f in ${LOGFILES}; do test ! -f $$f || mv $$f $$f~; done
264 rm -f *.tmp
266 clean:
267 find . '(' -name '*.log' -o -name '*.log~' ')' $(FIND_DELETE)
268 rm -f $(test_module_dir)/*.o $(test_module_dir)/*.so \
269 $(test_module_dir)/*.dll
271 bootstrap-clean: clean
272 find $(srcdir) -name '*.elc' $(FIND_DELETE)
274 distclean: clean
275 rm -f Makefile
277 maintainer-clean: distclean bootstrap-clean