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/>.
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
36 FIND_DELETE
= @FIND_DELETE@
40 PROFILING_CFLAGS
= @PROFILING_CFLAGS@
41 WARN_CFLAGS
= @WARN_CFLAGS@
42 WERROR_CFLAGS
= @WERROR_CFLAGS@
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 " $@
;
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 " $@
;
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 " $@
;
67 AM_V_at
= $(am__v_at_@AM_V@
)
68 am__v_at_
= $(am__v_at_@AM_DEFAULT_V@
)
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.
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".
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.
96 # Whether to run tests from .el files in preference to .elc, we do
97 # this by default since it gives nicer stacktraces.
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},)
107 ert_opts
= --eval
'(setq ert-batch-backtrace-right-margin ${TEST_BACKTRACE_LINE_LENGTH})'
110 ifeq (@HAVE_MODULES@
, yes
)
111 MODULES_EMACSOPT
:= --module-assertions
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
128 SELECTOR_DEFAULT
= (quote
(not
(tag
:expensive-test
)))
129 SELECTOR_EXPENSIVE
= nil
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
)
141 SELECTOR_ACTUAL
=$(SELECTOR_EXPENSIVE
)
144 ## Byte-compile all test files to test for errors.
146 $(AM_V_ELC
)$(emacs
) -f batch-byte-compile
$<
148 ## Save logs, and show logs for failed tests.
149 WRITE_LOG
= > $@
2>&1 ||
{ STAT
=$$?
; cat
$@
; exit
$$STAT; }
151 ifeq ($(TEST_LOAD_EL
), yes
)
158 $(AM_V_at
)${MKDIR_P} $(dir $@
)
159 $(AM_V_GEN
)HOME
=/nonexistent
$(emacs
) \
160 -l ert
${ert_opts} -l
$(testloadfile
) \
161 --eval
"(ert-run-tests-batch-and-exit ${SELECTOR_ACTUAL})" ${WRITE_LOG}
163 ifeq (@HAVE_MODULES@
, yes
)
164 maybe_exclude_module_tests
:=
166 maybe_exclude_module_tests
:= -name emacs-module-tests.el
-prune
-o
169 ELFILES
:= $(sort $(shell find
${srcdir} -path
"${srcdir}/manual" -prune
-o \
170 -path
"${srcdir}/data" -prune
-o \
171 -name
"*resources" -prune
-o \
172 ${maybe_exclude_module_tests} \
173 -name
"*.el" ! -name
".*" -print))
174 ## .log files may be in a different directory for out of source builds
175 LOGFILES
:= $(patsubst %.el
,%.log
, \
176 $(patsubst $(srcdir)/%,%,$(ELFILES
)))
177 TESTS
:= $(LOGFILES
:.log
=)
179 ## If we have to interrupt a hanging test, preserve the log so we can
180 ## see what the problem was.
183 ## Stop make deleting these as intermediate files.
184 .SECONDARY
: ${ELFILES
:.el
=.elc
} $(test_module_dir
)/*.o
189 ## A test FOO-tests depends on the source file with the similar
190 ## name, unless FOO itself contains the string '-tests/'.
191 ## The similar name is FOO.c if FOO begins with '{lib-,}src/', FOO.el
192 ## otherwise. Although this heuristic does not identify all the
193 ## dependencies, it is better than nothing.
194 ifeq (,$(patsubst %-tests
,,$(1))$(findstring -tests
/,$(1)))
195 $(1).log
: $(patsubst %-tests
,$(srcdir)/..
/%,$(1))$(if \
196 $(patsubst src
/%,,$(patsubst lib-src
/%,,$(1))),.el
,.c
)
199 ## Short aliases that always re-run the tests, with no logging.
200 ## Define both with and without the directory name for ease of use.
201 .PHONY
: $(1) $(notdir $(1))
203 @
test ! -f
$(1).log || mv
$(1).log
$(1).log~
204 @
$(MAKE
) $(1).log WRITE_LOG
=
208 $(foreach test,${TESTS},$(eval
$(call test_template
,${test})))
210 ifeq (@HAVE_MODULES@
, yes
)
211 # -fPIC is a no-op on Windows, but causes a compiler warning
218 MODULE_CFLAGS
= -I
$(srcdir)/..
/src
$(FPIC_CFLAGS
) $(PROFILING_CFLAGS
) \
219 $(WARN_CFLAGS
) $(WERROR_CFLAGS
) $(CFLAGS
)
221 test_module
= $(test_module_dir
)/mod-test
${SO}
222 src
/emacs-module-tests.log
: $(test_module
)
223 $(test_module
): $(test_module
:${SO}=.c
) $(srcdir)/..
/src
/emacs-module.h
224 $(AM_V_CCLD
)$(CC
) -shared
$(CPPFLAGS
) $(MODULE_CFLAGS
) $(LDFLAGS
) \
228 ## Check that there is no 'automated' subdirectory, which would
229 ## indicate an incomplete merge from an older version of Emacs where
230 ## the tests were arranged differently.
231 .PHONY
: check-no-automated-subdir
232 check-no-automated-subdir
:
233 ${AM_V_at}test ! -d
$(srcdir)/automated
235 ## Rerun all default tests.
236 check: mostlyclean check-no-automated-subdir
237 @
${MAKE} check-doit SELECTOR
="${SELECTOR_ACTUAL}"
239 ## Rerun all default and expensive tests.
240 .PHONY
: check-expensive
241 check-expensive
: mostlyclean check-no-automated-subdir
242 @
${MAKE} check-doit SELECTOR
="${SELECTOR_EXPENSIVE}"
244 ## Re-run all tests which are outdated. A test is outdated if its
245 ## logfile is out-of-date with either the test file, or the source
246 ## files that the tests depend on. See test_template.
248 check-maybe
: check-no-automated-subdir
249 @
${MAKE} check-doit SELECTOR
="${SELECTOR_ACTUAL}"
253 ## We can't put LOGFILES as prerequisites, because that would stop the
254 ## summarizing step from running when there is an error.
256 -@
${MAKE} -k
${LOGFILES}
257 @
$(emacs
) -l ert
-f ert-summarize-tests-batch-and-exit
${LOGFILES}
259 .PHONY
: mostlyclean clean bootstrap-clean
distclean maintainer-clean
262 -@for f in
${LOGFILES}; do
test ! -f
$$f || mv
$$f $$f~
; done
266 find .
'(' -name
'*.log' -o
-name
'*.log~' ')' $(FIND_DELETE
)
267 rm -f
$(test_module_dir
)/*.o
$(test_module_dir
)/*.so \
268 $(test_module_dir
)/*.dll
270 bootstrap-clean
: clean
271 find
$(srcdir) -name
'*.elc' $(FIND_DELETE
)
276 maintainer-clean
: distclean bootstrap-clean