Merge branch 'master' of git.sv.gnu.org:/srv/git/emacs
[emacs.git] / test / Makefile.in
blobba823ec7e328a12b8dbff15c6338f13141ebda73
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 = $(if $(and ${EMACS_HYDRA_CI}, $(findstring tramp, $@)), |& tee $@, > $@ 2>&1) \
140 || { STAT=$$?; cat $@; exit $$STAT; }
142 ifeq ($(TEST_LOAD_EL), yes)
143 testloadfile = $*.el
144 else
145 testloadfile = $*
146 endif
148 %.log: %.elc
149 $(AM_V_at)${MKDIR_P} $(dir $@)
150 $(AM_V_GEN)HOME=/nonexistent $(emacs) -l ert -l $(testloadfile) \
151 --eval "(ert-run-tests-batch-and-exit ${SELECTOR_ACTUAL})" ${WRITE_LOG}
153 ifeq (@HAVE_MODULES@, yes)
154 maybe_exclude_module_tests :=
155 else
156 maybe_exclude_module_tests := -name emacs-module-tests.el -prune -o
157 endif
159 ELFILES := $(shell find ${srcdir} -path "${srcdir}/manual" -prune -o \
160 -path "${srcdir}/data" -prune -o \
161 -name "*resources" -prune -o \
162 ${maybe_exclude_module_tests} \
163 -name "*.el" ! -name ".*" -print)
164 ## .log files may be in a different directory for out of source builds
165 LOGFILES := $(patsubst %.el,%.log, \
166 $(patsubst $(srcdir)/%,%,$(ELFILES)))
167 TESTS := $(LOGFILES:.log=)
169 ## If we have to interrupt a hanging test, preserve the log so we can
170 ## see what the problem was.
171 .PRECIOUS: %.log
173 ## Stop make deleting these as intermediate files.
174 .SECONDARY: ${ELFILES:.el=.elc} $(test_module_dir)/*.o
176 .PHONY: ${TESTS}
178 define test_template
179 ## A test FOO-tests depends on the source file with the similar
180 ## name, unless FOO itself contains the string '-tests/'.
181 ## The similar name is FOO.c if FOO begins with 'src/', FOO.el
182 ## otherwise. Although this heuristic does not identify all the
183 ## dependencies, it is better than nothing.
184 ifeq (,$(patsubst %-tests,,$(1))$(findstring -tests/,$(1)))
185 $(1).log: $(patsubst %-tests,$(srcdir)/../%,$(1))$(if \
186 $(patsubst src/%,,$(1)),.el,.c)
187 endif
189 ## Short aliases that always re-run the tests, with no logging.
190 ## Define both with and without the directory name for ease of use.
191 .PHONY: $(1) $(notdir $(1))
192 $(1):
193 @test ! -f $(1).log || mv $(1).log $(1).log~
194 @$(MAKE) $(1).log WRITE_LOG=
195 $(notdir $(1)): $(1)
196 endef
198 $(foreach test,${TESTS},$(eval $(call test_template,${test})))
200 ifeq (@HAVE_MODULES@, yes)
201 # -fPIC is a no-op on Windows, but causes a compiler warning
202 ifeq ($(SO),.dll)
203 FPIC_CFLAGS =
204 else
205 FPIC_CFLAGS = -fPIC
206 endif
208 MODULE_CFLAGS = -I$(srcdir)/../src $(FPIC_CFLAGS) $(PROFILING_CFLAGS) \
209 $(WARN_CFLAGS) $(WERROR_CFLAGS) $(CFLAGS)
211 test_module = $(test_module_dir)/mod-test${SO}
212 src/emacs-module-tests.log: $(test_module)
213 $(test_module): $(test_module:${SO}=.c) $(srcdir)/../src/emacs-module.h
214 $(AM_V_CCLD)$(CC) -shared $(CPPFLAGS) $(MODULE_CFLAGS) $(LDFLAGS) \
215 -o $@ $<
216 endif
218 ## Check that there is no 'automated' subdirectory, which would
219 ## indicate an incomplete merge from an older version of Emacs where
220 ## the tests were arranged differently.
221 .PHONY: check-no-automated-subdir
222 check-no-automated-subdir:
223 test ! -d $(srcdir)/automated
225 ## Rerun all default tests.
226 check: mostlyclean check-no-automated-subdir
227 @${MAKE} check-doit SELECTOR="${SELECTOR_ACTUAL}"
229 ## Rerun all default and expensive tests.
230 .PHONY: check-expensive
231 check-expensive: mostlyclean check-no-automated-subdir
232 @${MAKE} check-doit SELECTOR="${SELECTOR_EXPENSIVE}"
234 ## Re-run all tests which are outdated. A test is outdated if its
235 ## logfile is out-of-date with either the test file, or the source
236 ## files that the tests depend on. See test_template.
237 .PHONY: check-maybe
238 check-maybe: check-no-automated-subdir
239 @${MAKE} check-doit SELECTOR="${SELECTOR_ACTUAL}"
241 ## Run the tests.
242 .PHONY: check-doit
243 ## We can't put LOGFILES as prerequisites, because that would stop the
244 ## summarizing step from running when there is an error.
245 check-doit:
246 -@${MAKE} -k ${LOGFILES}
247 @$(emacs) -l ert -f ert-summarize-tests-batch-and-exit ${LOGFILES}
249 .PHONY: mostlyclean clean bootstrap-clean distclean maintainer-clean
251 mostlyclean:
252 -@for f in ${LOGFILES}; do test ! -f $$f || mv $$f $$f~; done
253 rm -f *.tmp
255 clean:
256 find . '(' -name '*.log' -o -name '*.log~' ')' $(FIND_DELETE)
257 rm -f $(test_module_dir)/*.o $(test_module_dir)/*.so \
258 $(test_module_dir)/*.dll
260 bootstrap-clean: clean
261 find $(srcdir) -name '*.elc' $(FIND_DELETE)
263 distclean: clean
264 rm -f Makefile
266 maintainer-clean: distclean bootstrap-clean