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
= -batch
--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 # Whether to run tests from .el files in preference to .elc, we do
98 # this by default since it gives nicer stacktraces.
99 # If you just want a pass/fail, setting this to no is much faster.
100 export TEST_LOAD_EL ?
= \
101 $(if
$(findstring $(MAKECMDGOALS
), all check check-maybe
),no
,yes
)
103 # Additional settings for ert.
106 # Maximum length of lines in ert backtraces; nil for no limit.
107 # (if empty, use the default ert-batch-backtrace-right-margin).
108 TEST_BACKTRACE_LINE_LENGTH
=
110 ifneq (${TEST_BACKTRACE_LINE_LENGTH},)
111 ert_opts
+= --eval
'(setq ert-batch-backtrace-right-margin ${TEST_BACKTRACE_LINE_LENGTH})'
114 ifeq (@HAVE_MODULES@
, yes
)
115 MODULES_EMACSOPT
:= --module-assertions
120 # The actual Emacs command run in the targets below.
121 # Prevent any setting of EMACSLOADPATH in user environment causing problems.
122 emacs
= EMACSLOADPATH
= LC_ALL
=$(TEST_LOCALE
) \
123 EMACS_TEST_DIRECTORY
=$(abspath
$(srcdir)) \
124 $(GDB
) "$(EMACS)" $(MODULES_EMACSOPT
) $(EMACSOPT
)
126 test_module_dir
:= data
/emacs-module
132 SELECTOR_DEFAULT
= (quote
(not
(or
(tag
:expensive-test
) (tag
:unstable
))))
133 SELECTOR_EXPENSIVE
= (quote
(not
(tag
:unstable
)))
136 SELECTOR_ACTUAL
=$(SELECTOR
)
137 else ifndef MAKECMDGOALS
138 SELECTOR_ACTUAL
=$(SELECTOR_DEFAULT
)
139 else ifeq ($(MAKECMDGOALS
),all)
140 SELECTOR_ACTUAL
=$(SELECTOR_DEFAULT
)
141 else ifeq ($(MAKECMDGOALS
),check)
142 SELECTOR_ACTUAL
=$(SELECTOR_DEFAULT
)
143 else ifeq ($(MAKECMDGOALS
),check-maybe
)
144 SELECTOR_ACTUAL
=$(SELECTOR_DEFAULT
)
146 SELECTOR_ACTUAL
=$(SELECTOR_EXPENSIVE
)
149 ## Byte-compile all test files to test for errors.
151 $(AM_V_ELC
)$(emacs
) -f batch-byte-compile
$<
153 ## Save logs, and show logs for failed tests.
154 WRITE_LOG
= > $@
2>&1 ||
{ STAT
=$$?
; cat
$@
; exit
$$STAT; }
156 ## On Hydra, always show logs for certain problematic tests.
157 lisp
/net
/tramp-tests.log \
158 : WRITE_LOG
= 2>&1 | tee
$@
161 ifeq ($(TEST_LOAD_EL
), yes
)
168 $(AM_V_at
)${MKDIR_P} $(dir $@
)
169 $(AM_V_GEN
)HOME
=/nonexistent
$(emacs
) \
170 -l ert
${ert_opts} -l
$(testloadfile
) \
171 --eval
"(ert-run-tests-batch-and-exit ${SELECTOR_ACTUAL})" ${WRITE_LOG}
173 ifeq (@HAVE_MODULES@
, yes
)
174 maybe_exclude_module_tests
:=
176 maybe_exclude_module_tests
:= -name emacs-module-tests.el
-prune
-o
179 ## To speed up parallel builds, put these slow test files (which can
180 ## take longer than all the rest combined) at the start of the list.
181 SLOW_TESTS
= ${srcdir}/lisp
/net
/tramp-tests.el
183 ELFILES
:= $(sort $(shell find
${srcdir} -path
"${srcdir}/manual" -prune
-o \
184 -path
"${srcdir}/data" -prune
-o \
185 -name
"*resources" -prune
-o \
186 ${maybe_exclude_module_tests} \
187 -name
"*.el" ! -name
".*" -print))
189 $(foreach slow
,${SLOW_TESTS},$(eval ELFILES
:= ${slow} $(filter-out ${slow},${ELFILES})))
191 ## .log files may be in a different directory for out of source builds
192 LOGFILES
:= $(patsubst %.el
,%.log
, \
193 $(patsubst $(srcdir)/%,%,$(ELFILES
)))
194 TESTS
:= $(LOGFILES
:.log
=)
196 ## If we have to interrupt a hanging test, preserve the log so we can
197 ## see what the problem was.
200 ## Stop make deleting these as intermediate files.
201 .SECONDARY
: ${ELFILES
:.el
=.elc
} $(test_module_dir
)/*.o
206 ## A test FOO-tests depends on the source file with the similar
207 ## name, unless FOO itself contains the string '-tests/'.
208 ## The similar name is FOO.c if FOO begins with '{lib-,}src/', FOO.el
209 ## otherwise. Although this heuristic does not identify all the
210 ## dependencies, it is better than nothing.
211 ifeq (,$(patsubst %-tests
,,$(1))$(findstring -tests
/,$(1)))
212 $(1).log
: $(patsubst %-tests
,$(srcdir)/..
/%,$(1))$(if \
213 $(patsubst src
/%,,$(patsubst lib-src
/%,,$(1))),.el
,.c
)
216 ## Short aliases that always re-run the tests, with no logging.
217 ## Define both with and without the directory name for ease of use.
218 .PHONY
: $(1) $(notdir $(1))
220 @
test ! -f
$(1).log || mv
$(1).log
$(1).log~
221 @
$(MAKE
) $(1).log WRITE_LOG
=
225 $(foreach test,${TESTS},$(eval
$(call test_template
,${test})))
227 ifeq (@HAVE_MODULES@
, yes
)
228 # -fPIC is a no-op on Windows, but causes a compiler warning
235 MODULE_CFLAGS
= -I..
/src
$(FPIC_CFLAGS
) $(PROFILING_CFLAGS
) \
236 $(WARN_CFLAGS
) $(WERROR_CFLAGS
) $(CFLAGS
)
238 test_module
= $(test_module_dir
)/mod-test
${SO}
239 src
/emacs-module-tests.log
: $(test_module
)
240 $(test_module
): $(test_module
:${SO}=.c
) $(srcdir)/..
/src
/emacs-module.h
241 $(AM_V_at
)${MKDIR_P} $(dir $@
)
242 $(AM_V_CCLD
)$(CC
) -shared
$(CPPFLAGS
) $(MODULE_CFLAGS
) $(LDFLAGS
) \
246 ## Check that there is no 'automated' subdirectory, which would
247 ## indicate an incomplete merge from an older version of Emacs where
248 ## the tests were arranged differently.
249 .PHONY
: check-no-automated-subdir
250 check-no-automated-subdir
:
251 ${AM_V_at}test ! -d
$(srcdir)/automated
253 ## Rerun all default tests.
254 check: mostlyclean check-no-automated-subdir
255 @
${MAKE} check-doit SELECTOR
="${SELECTOR_ACTUAL}"
257 ## Rerun all default and expensive tests.
258 .PHONY
: check-expensive
259 check-expensive
: mostlyclean check-no-automated-subdir
260 @
${MAKE} check-doit SELECTOR
="${SELECTOR_EXPENSIVE}"
262 ## Run all tests, regardless of tag.
264 check-all
: mostlyclean check-no-automated-subdir
265 @
${MAKE} check-doit SELECTOR
="${SELECTOR_ALL}"
267 ## Re-run all tests which are outdated. A test is outdated if its
268 ## logfile is out-of-date with either the test file, or the source
269 ## files that the tests depend on. See test_template.
271 check-maybe
: check-no-automated-subdir
272 @
${MAKE} check-doit SELECTOR
="${SELECTOR_ACTUAL}"
276 ## We can't put LOGFILES as prerequisites, because that would stop the
277 ## summarizing step from running when there is an error.
279 -@
${MAKE} -k
${LOGFILES}
280 @
$(emacs
) -l ert
--eval \
281 "(ert-summarize-tests-batch-and-exit ${SUMMARIZE_TESTS})" ${LOGFILES}
283 .PHONY
: mostlyclean clean bootstrap-clean
distclean maintainer-clean
286 -@for f in
${LOGFILES}; do
test ! -f
$$f || mv
$$f $$f~
; done
290 find .
'(' -name
'*.log' -o
-name
'*.log~' ')' $(FIND_DELETE
)
291 rm -f
$(test_module_dir
)/*.o
$(test_module_dir
)/*.so \
292 $(test_module_dir
)/*.dll
294 bootstrap-clean
: clean
295 find
$(srcdir) -name
'*.elc' $(FIND_DELETE
)
300 maintainer-clean
: distclean bootstrap-clean
302 .PHONY
: check-declare
305 $(emacs
) -l check-declare \
306 --eval
'(check-declare-directory "$(srcdir)")'