]> code.delx.au - gnu-emacs/blob - test/Makefile.in
; Improve documentation in test Makefile
[gnu-emacs] / test / Makefile.in
1 ### @configure_input@
2
3 # Copyright (C) 2010-2016 Free Software Foundation, Inc.
4
5 # This file is part of GNU Emacs.
6
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.
11
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.
16
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/>.
19
20 ### Commentary:
21
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
28
29 ### Code:
30
31 SHELL = @SHELL@
32
33 srcdir = @srcdir@
34 VPATH = $(srcdir)
35
36 SEPCHAR = @SEPCHAR@
37
38 # We never change directory before running Emacs, so a relative file
39 # name is fine, and makes life easier. If we need to change
40 # directory, we can use emacs --chdir.
41 EMACS = ../src/emacs
42
43 EMACS_EXTRAOPT=
44
45 # Command line flags for Emacs.
46 # Apparently MSYS bash would convert "-L :" to "-L ;" anyway,
47 # but we might as well be explicit.
48 EMACSOPT = -batch --no-site-file --no-site-lisp -L "$(SEPCHAR)$(srcdir)" $(EMACS_EXTRAOPT)
49
50 # Prevent any settings in the user environment causing problems.
51 unexport EMACSDATA EMACSDOC EMACSPATH GREP_OPTIONS
52
53 ## To run tests under a debugger, set this to eg: "gdb --args".
54 GDB =
55
56 # The locale to run tests under. Tests should work if this is set to
57 # any supported locale. Use the C locale by default, as it should be
58 # supported everywhere.
59 TEST_LOCALE = C
60
61 # The actual Emacs command run in the targets below.
62 # Prevent any setting of EMACSLOADPATH in user environment causing problems.
63 emacs = EMACSLOADPATH= LC_ALL=$(TEST_LOCALE) EMACS_TEST_DIRECTORY=$(srcdir) \
64 $(GDB) "$(EMACS)" $(EMACSOPT)
65
66 .PHONY: all check
67
68 all: check
69
70 %.elc: %.el
71 @echo Compiling $<
72 @$(emacs) -f batch-byte-compile $<
73
74 ## Ignore any test errors so we can continue to test other files.
75 ## But compilation errors are always fatal.
76 WRITE_LOG = > $@ 2>&1 || { stat=ERROR; cat $@; }; echo $$stat: $@
77
78 ## I'd prefer to use -emacs -f ert-run-tests-batch-and-exit rather
79 ## than || true, since the former makes problems more obvious.
80 ## I'd also prefer to @-hide the grep part and not the
81 ## ert-run-tests-batch-and-exit part.
82 ##
83 ## We need to use $loadfile because:
84 ## i) -L :$srcdir -l basename does not work, because we have files whose
85 ## basename duplicates a file in lisp/ (eg eshell.el).
86 ## ii) Although -l basename will automatically load .el or .elc,
87 ## -l ./basename treats basename as a literal file (it would be nice
88 ## to change this; bug#17848 - if that gets done, this can be simplified).
89 ##
90 ## Beware: it approximates 'no-byte-compile', so watch out for false-positives!
91 SELECTOR_DEFAULT = (quote (not (tag :expensive-test)))
92 SELECTOR_EXPENSIVE = nil
93 ifdef SELECTOR
94 SELECTOR_ACTUAL=$(SELECTOR)
95 else ifeq ($(MAKECMDGOALS),check)
96 SELECTOR_ACTUAL=$(SELECTOR_DEFAULT)
97 else ifeq ($(MAKECMDGOALS),check-maybe)
98 SELECTOR_ACTUAL=$(SELECTOR_DEFAULT)
99 else
100 SELECTOR_ACTUAL=$(SELECTOR_EXPENSIVE)
101 endif
102
103
104 %.log: %.el
105 @if grep '^;.*no-byte-compile: t' $< > /dev/null; then \
106 loadfile=$<; \
107 else \
108 loadfile=$<c; \
109 ${MAKE} $$loadfile; \
110 fi; \
111 echo Testing $$loadfile; \
112 stat=OK ; \
113 mkdir --parents $(dir $@) ; \
114 $(emacs) -l ert -l $$loadfile \
115 --eval "(ert-run-tests-batch-and-exit ${SELECTOR_ACTUAL})" ${WRITE_LOG}
116
117 ELFILES = $(shell find ${srcdir} -path "${srcdir}/manual" -prune -o \
118 -path "*resources" -prune -o -name "*el" -print)
119 ## .elc files may be in a different directory for out of source builds
120 ELCFILES = $(patsubst %.el,%.elc, \
121 $(patsubst $(srcdir)%,.%,$(ELFILES)))
122 LOGFILES = $(patsubst %.elc,%.log,${ELCFILES})
123 LOGSAVEFILES = $(patsubst %.elc,%.log~,${ELCFILES})
124 TESTS = $(subst ${srcdir}/,,$(LOGFILES:.log=))
125
126 ## If we have to interrupt a hanging test, preserve the log so we can
127 ## see what the problem was.
128 .PRECIOUS: %.log
129
130 .PHONY: ${TESTS}
131
132 ## The short aliases that always re-run the tests, with no logging.
133 ## Define an alias both with and without the directory name for ease
134 ## of use.
135 define test_template
136 $(1):
137 @test ! -f ./$(1).log || mv ./$(1).log ./$(1).log~
138 @${MAKE} ./$(1).log WRITE_LOG=
139
140 $(notdir $(1)): $(1)
141 endef
142
143 $(foreach test,${TESTS},$(eval $(call test_template,${test})))
144
145 ## Include dependencies between test files and the files they test.
146 ## We could do this without the file and eval directly, but then we
147 ## would have to run Emacs for every make invocation, and it might not
148 ## be available during clean.
149 -include make-test-deps.mk
150 ## Rerun all default tests.
151 check: mostlyclean
152 @${MAKE} check-doit SELECTOR="${SELECTOR_ACTUAL}"
153
154 ## Rerun all default and expensive tests.
155 .PHONY: check-expensive
156 check-expensive: mostlyclean
157 @${MAKE} check-doit SELECTOR="${SELECTOR_EXPENSIVE}"
158
159 ## Re-run all tests which are outdated. A test is outdated if its
160 ## logfile is out-of-date with either the test file, or the source
161 ## files that the tests depend on. The source file dependencies are
162 ## determined by a heuristic and does not identify the full dependency
163 ## graph. See make-test-deps.emacs-lisp for details.
164 .PHONY: check-maybe
165 check-maybe:
166 @${MAKE} check-doit SELECTOR="${SELECTOR_ACTUAL}"
167
168 ## Run the tests.
169 .PHONY: check-doit
170 check-doit: ${LOGFILES}
171 $(emacs) -l ert -f ert-summarize-tests-batch-and-exit $^
172
173 .PHONY: mostlyclean clean bootstrap-clean distclean maintainer-clean
174
175 mostlyclean:
176 -@for f in ${LOGFILES}; do test ! -f $$f || mv $$f $$f~; done
177
178 clean:
179 -rm -f ${LOGFILES} ${LOGSAVEFILES}
180 -rm make-test-deps.mk
181
182 bootstrap-clean: clean
183 -rm -f ${ELCFILES}
184
185 distclean: clean
186 rm -f Makefile
187
188 maintainer-clean: distclean bootstrap-clean
189
190 make-test-deps.mk: $(ELFILES) make-test-deps.emacs-lisp
191 $(EMACS) --batch -l $(srcdir)/make-test-deps.emacs-lisp \
192 --eval "(make-test-deps \"$(srcdir)\")" \
193 2> $@
194 # Makefile ends here.