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/>.
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
34 abs_top_srcdir
=@abs_top_srcdir@
37 FIND_DELETE
= @FIND_DELETE@
41 PROFILING_CFLAGS
= @PROFILING_CFLAGS@
42 WARN_CFLAGS
= @WARN_CFLAGS@
43 WERROR_CFLAGS
= @WERROR_CFLAGS@
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 " $@
;
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 " $@
;
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 " $@
;
68 AM_V_at
= $(am__v_at_@AM_V@
)
69 am__v_at_
= $(am__v_at_@AM_DEFAULT_V@
)
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.
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".
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.
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}))'
103 TEST_RUN_ERT
= --batch
--eval
'(ert-run-tests-batch-and-exit (quote ${SELECTOR_ACTUAL}))' ${WRITE_LOG}
106 # Whether to run tests from .el files in preference to .elc, we do
107 # this by default since it gives nicer stacktraces.
110 # Maximum length of lines in ert backtraces; nil for no limit.
111 # (if empty, use the default ert-batch-backtrace-right-margin).
112 TEST_BACKTRACE_LINE_LENGTH
=
114 ifeq (${TEST_BACKTRACE_LINE_LENGTH},)
117 ert_opts
= --eval
'(setq ert-batch-backtrace-right-margin ${TEST_BACKTRACE_LINE_LENGTH})'
120 ifeq (@HAVE_MODULES@
, yes
)
121 MODULES_EMACSOPT
:= --module-assertions
126 # The actual Emacs command run in the targets below.
127 # Prevent any setting of EMACSLOADPATH in user environment causing problems.
128 emacs
= EMACSLOADPATH
= LC_ALL
=$(TEST_LOCALE
) \
129 EMACS_TEST_DIRECTORY
=$(abspath
$(srcdir)) \
130 $(GDB
) "$(EMACS)" $(MODULES_EMACSOPT
) $(EMACSOPT
)
132 # Set HOME to a nonexistent directory to prevent tests from accessing
133 # it accidentally (e.g., popping up a gnupg dialog if ~/.authinfo.gpg
134 # exists, or writing to ~/.bzr.log when running bzr commands).
135 TEST_HOME
= /nonexistent
137 test_module_dir
:= $(srcdir)/data
/emacs-module
143 SELECTOR_DEFAULT
= (not
(or
(tag
:expensive-test
) (tag
:unstable
)))
144 SELECTOR_EXPENSIVE
= (not
(tag
:unstable
))
147 SELECTOR_ACTUAL
=$(SELECTOR
)
148 else ifndef MAKECMDGOALS
149 SELECTOR_ACTUAL
=$(SELECTOR_DEFAULT
)
150 else ifeq ($(MAKECMDGOALS
),all)
151 SELECTOR_ACTUAL
=$(SELECTOR_DEFAULT
)
152 else ifeq ($(MAKECMDGOALS
),check)
153 SELECTOR_ACTUAL
=$(SELECTOR_DEFAULT
)
154 else ifeq ($(MAKECMDGOALS
),check-maybe
)
155 SELECTOR_ACTUAL
=$(SELECTOR_DEFAULT
)
157 SELECTOR_ACTUAL
=$(SELECTOR_EXPENSIVE
)
160 ## Byte-compile all test files to test for errors.
162 $(AM_V_ELC
)$(emacs
) --batch
-f batch-byte-compile
$<
164 ## Save logs, and show logs for failed tests.
165 WRITE_LOG
= > $@
2>&1 ||
{ STAT
=$$?
; cat
$@
; exit
$$STAT; }
167 ifeq ($(TEST_LOAD_EL
), yes
)
174 $(AM_V_at
)${MKDIR_P} $(dir $@
)
175 $(AM_V_GEN
)HOME
=$(TEST_HOME
) $(emacs
) \
176 -l ert
${ert_opts} -l
$(testloadfile
) \
179 ifeq (@HAVE_MODULES@
, yes
)
180 maybe_exclude_module_tests
:=
182 maybe_exclude_module_tests
:= -name emacs-module-tests.el
-prune
-o
185 ELFILES
:= $(sort $(shell find
${srcdir} -path
"${srcdir}/manual" -prune
-o \
186 -path
"${srcdir}/data" -prune
-o \
187 -name
"*resources" -prune
-o \
188 ${maybe_exclude_module_tests} \
189 -name
"*.el" ! -name
".*" -print))
190 ## .log files may be in a different directory for out of source builds
191 LOGFILES
:= $(patsubst %.el
,%.log
, \
192 $(patsubst $(srcdir)/%,%,$(ELFILES
)))
193 TESTS
:= $(LOGFILES
:.log
=)
195 ## If we have to interrupt a hanging test, preserve the log so we can
196 ## see what the problem was.
199 ## Stop make deleting these as intermediate files.
200 .SECONDARY
: ${ELFILES
:.el
=.elc
} $(test_module_dir
)/*.o
205 ## A test FOO-tests depends on the source file with the similar
206 ## name, unless FOO itself contains the string '-tests/'.
207 ## The similar name is FOO.c if FOO begins with '{lib-,}src/', FOO.el
208 ## otherwise. Although this heuristic does not identify all the
209 ## dependencies, it is better than nothing.
210 ifeq (,$(patsubst %-tests
,,$(1))$(findstring -tests
/,$(1)))
211 $(1).log
: $(patsubst %-tests
,$(srcdir)/..
/%,$(1))$(if \
212 $(patsubst src
/%,,$(patsubst lib-src
/%,,$(1))),.el
,.c
)
215 ## Short aliases that always re-run the tests, with no logging.
216 ## Define both with and without the directory name for ease of use.
217 .PHONY
: $(1) $(notdir $(1))
219 @
test ! -f
$(1).log || mv
$(1).log
$(1).log~
220 @
$(MAKE
) $(1).log WRITE_LOG
=
224 $(foreach test,${TESTS},$(eval
$(call test_template
,${test})))
226 ifeq (@HAVE_MODULES@
, yes
)
227 # -fPIC is a no-op on Windows, but causes a compiler warning
234 MODULE_CFLAGS
= -I
$(srcdir)/..
/src
$(FPIC_CFLAGS
) $(PROFILING_CFLAGS
) \
235 $(WARN_CFLAGS
) $(WERROR_CFLAGS
) $(CFLAGS
)
237 test_module
= $(test_module_dir
)/mod-test
${SO}
238 src
/emacs-module-tests.log
: $(test_module
)
239 $(test_module
): $(test_module
:${SO}=.c
) $(srcdir)/..
/src
/emacs-module.h
240 $(AM_V_CCLD
)$(CC
) -shared
$(CPPFLAGS
) $(MODULE_CFLAGS
) $(LDFLAGS
) \
244 ## Check that there is no 'automated' subdirectory, which would
245 ## indicate an incomplete merge from an older version of Emacs where
246 ## the tests were arranged differently.
247 .PHONY
: check-no-automated-subdir
248 check-no-automated-subdir
:
249 ${AM_V_at}test ! -d
$(srcdir)/automated
251 ## Rerun all default tests.
252 check: mostlyclean check-no-automated-subdir
253 @
${MAKE} check-doit SELECTOR
="${SELECTOR_ACTUAL}"
255 ## Rerun all default and expensive tests.
256 .PHONY
: check-expensive
257 check-expensive
: mostlyclean check-no-automated-subdir
258 @
${MAKE} check-doit SELECTOR
="${SELECTOR_EXPENSIVE}"
260 ## Run all tests, regardless of tag.
262 check-all
: mostlyclean check-no-automated-subdir
263 @
${MAKE} check-doit SELECTOR
="${SELECTOR_ALL}"
265 ## Re-run all tests which are outdated. A test is outdated if its
266 ## logfile is out-of-date with either the test file, or the source
267 ## files that the tests depend on. See test_template.
269 check-maybe
: check-no-automated-subdir
270 @
${MAKE} check-doit SELECTOR
="${SELECTOR_ACTUAL}"
274 ## We can't put LOGFILES as prerequisites, because that would stop the
275 ## summarizing step from running when there is an error.
277 ifeq ($(TEST_INTERACTIVE
), yes
)
278 HOME
=$(TEST_HOME
) $(emacs
) \
280 $(patsubst %,-l
%,$(if
$(findstring $(TEST_LOAD_EL
),yes
),$ELFILES,$(ELFILES
:.el
=))) \
283 -@
${MAKE} -k
${LOGFILES}
284 @
$(emacs
) --batch
-l ert
-f ert-summarize-tests-batch-and-exit
${LOGFILES}
287 .PHONY
: mostlyclean clean bootstrap-clean
distclean maintainer-clean
290 -@for f in
${LOGFILES}; do
test ! -f
$$f || mv
$$f $$f~
; done
294 find .
'(' -name
'*.log' -o
-name
'*.log~' ')' $(FIND_DELETE
)
295 rm -f
$(test_module_dir
)/*.o
$(test_module_dir
)/*.so \
296 $(test_module_dir
)/*.dll
298 bootstrap-clean
: clean
299 find
$(srcdir) -name
'*.elc' $(FIND_DELETE
)
304 maintainer-clean
: distclean bootstrap-clean