428
|
1 ;; test-harness.el --- Run Emacs Lisp test suites.
|
|
2
|
1751
|
3 ;;; Copyright (C) 1998, 2002, 2003 Free Software Foundation, Inc.
|
826
|
4 ;;; Copyright (C) 2002 Ben Wing.
|
428
|
5
|
|
6 ;; Author: Martin Buchholz
|
1761
|
7 ;; Maintainer: Stephen J. Turnbull <stephen@xemacs.org>
|
428
|
8 ;; Keywords: testing
|
|
9
|
|
10 ;; This file is part of XEmacs.
|
|
11
|
|
12 ;; XEmacs is free software; you can redistribute it and/or modify it
|
|
13 ;; under the terms of the GNU General Public License as published by
|
|
14 ;; the Free Software Foundation; either version 2, or (at your option)
|
|
15 ;; any later version.
|
|
16
|
|
17 ;; XEmacs is distributed in the hope that it will be useful, but
|
|
18 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
20 ;; General Public License for more details.
|
|
21
|
|
22 ;; You should have received a copy of the GNU General Public License
|
|
23 ;; along with XEmacs; see the file COPYING. If not, write to the
|
|
24 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
25 ;; Boston, MA 02111-1307, USA.
|
|
26
|
|
27 ;;; Synched up with: Not in FSF.
|
|
28
|
|
29 ;;; Commentary:
|
|
30
|
|
31 ;;; A test suite harness for testing XEmacs.
|
|
32 ;;; The actual tests are in other files in this directory.
|
|
33 ;;; Basically you just create files of emacs-lisp, and use the
|
1095
|
34 ;;; Assert, Check-Error, Check-Message, and Check-Error-Message functions
|
|
35 ;;; to create tests. See `test-harness-from-buffer' below.
|
|
36 ;;; Don't suppress tests just because they're due to known bugs not yet
|
1413
|
37 ;;; fixed -- use the Known-Bug-Expect-Failure and
|
|
38 ;;; Implementation-Incomplete-Expect-Failure wrapper macros to mark them.
|
1095
|
39 ;;; A lot of the tests we run push limits; suppress Ebola message with the
|
|
40 ;;; Ignore-Ebola wrapper macro.
|
3472
|
41 ;;; Some noisy code will call `message'. Output from `message' can be
|
|
42 ;;; suppressed with the Silence-Message macro. Functions that are known to
|
|
43 ;;; issue messages include `write-region', `find-tag', `tag-loop-continue',
|
|
44 ;;; `insert', and `mark-whole-buffer'. N.B. The Silence-Message macro
|
|
45 ;;; currently does not suppress the newlines printed by `message'.
|
|
46 ;;; Definitely do not use Silence-Message with Check-Message.
|
|
47 ;;; In general it should probably only be used on code that prepares for a
|
|
48 ;;; test, not on tests.
|
1095
|
49 ;;;
|
428
|
50 ;;; You run the tests using M-x test-emacs-test-file,
|
|
51 ;;; or $(EMACS) -batch -l .../test-harness.el -f batch-test-emacs file ...
|
|
52 ;;; which is run for you by the `make check' target in the top-level Makefile.
|
|
53
|
|
54 (require 'bytecomp)
|
|
55
|
3471
|
56 (defvar unexpected-test-suite-failures 0
|
|
57 "Cumulative number of unexpected failures since test-harness was loaded.
|
|
58
|
|
59 \"Unexpected failures\" are those caught by a generic handler established
|
|
60 outside of the test context. As such they involve an abort of the test
|
|
61 suite for the file being tested.
|
|
62
|
|
63 They often occur during preparation of a test or recording of the results.
|
|
64 For example, an executable used to generate test data might not be present
|
|
65 on the system, or a system error might occur while reading a data file.")
|
|
66
|
|
67 (defvar unexpected-test-suite-failure-files nil
|
|
68 "List of test files causing unexpected failures.")
|
|
69
|
|
70 ;; Declared for dynamic scope; _do not_ initialize here.
|
|
71 (defvar unexpected-test-file-failures)
|
|
72
|
1758
|
73 (defvar test-harness-test-compiled nil
|
|
74 "Non-nil means the test code was compiled before execution.")
|
|
75
|
428
|
76 (defvar test-harness-verbose
|
|
77 (and (not noninteractive) (> (device-baud-rate) search-slow-speed))
|
|
78 "*Non-nil means print messages describing progress of emacs-tester.")
|
|
79
|
1719
|
80 (defvar test-harness-file-results-alist nil
|
|
81 "Each element is a list (FILE SUCCESSES TESTS).
|
|
82 The order is the reverse of the order in which tests are run.
|
|
83
|
|
84 FILE is a string naming the test file.
|
|
85 SUCCESSES is a non-negative integer, the number of successes.
|
|
86 TESTS is a non-negative integer, the number of tests run.")
|
|
87
|
1425
|
88 (defvar test-harness-risk-infloops nil
|
|
89 "*Non-nil to run tests that may loop infinitely in buggy implementations.")
|
|
90
|
428
|
91 (defvar test-harness-current-file nil)
|
|
92
|
|
93 (defvar emacs-lisp-file-regexp (purecopy "\\.el\\'")
|
|
94 "*Regexp which matches Emacs Lisp source files.")
|
|
95
|
1751
|
96 (defconst test-harness-file-summary-template
|
|
97 (format "%%-%ds %%%dd of %%%dd tests successful (%%3d%%%%)."
|
|
98 (length "byte-compiler-tests.el:") ; use the longest file name
|
|
99 5
|
|
100 5)
|
|
101 "Format for summary lines printed after each file is run.")
|
|
102
|
|
103 (defconst test-harness-null-summary-template
|
|
104 (format "%%-%ds No tests run."
|
|
105 (length "byte-compiler-tests.el:")) ; use the longest file name
|
|
106 "Format for \"No tests\" lines printed after a file is run.")
|
|
107
|
428
|
108 ;;;###autoload
|
|
109 (defun test-emacs-test-file (filename)
|
|
110 "Test a file of Lisp code named FILENAME.
|
|
111 The output file's name is made by appending `c' to the end of FILENAME."
|
|
112 (interactive
|
|
113 (let ((file buffer-file-name)
|
|
114 (file-name nil)
|
|
115 (file-dir nil))
|
|
116 (and file
|
|
117 (eq (cdr (assq 'major-mode (buffer-local-variables)))
|
|
118 'emacs-lisp-mode)
|
|
119 (setq file-name (file-name-nondirectory file)
|
|
120 file-dir (file-name-directory file)))
|
|
121 (list (read-file-name "Test file: " file-dir nil nil file-name))))
|
|
122 ;; Expand now so we get the current buffer's defaults
|
|
123 (setq filename (expand-file-name filename))
|
|
124
|
|
125 ;; If we're testing a file that's in a buffer and is modified, offer
|
|
126 ;; to save it first.
|
|
127 (or noninteractive
|
|
128 (let ((b (get-file-buffer (expand-file-name filename))))
|
|
129 (if (and b (buffer-modified-p b)
|
|
130 (y-or-n-p (format "save buffer %s first? " (buffer-name b))))
|
|
131 (save-excursion (set-buffer b) (save-buffer)))))
|
|
132
|
|
133 (if (or noninteractive test-harness-verbose)
|
|
134 (message "Testing %s..." filename))
|
|
135 (let ((test-harness-current-file filename)
|
|
136 input-buffer)
|
|
137 (save-excursion
|
|
138 (setq input-buffer (get-buffer-create " *Test Input*"))
|
|
139 (set-buffer input-buffer)
|
|
140 (erase-buffer)
|
|
141 (insert-file-contents filename)
|
|
142 ;; Run hooks including the uncompression hook.
|
|
143 ;; If they change the file name, then change it for the output also.
|
|
144 (let ((buffer-file-name filename)
|
|
145 (default-major-mode 'emacs-lisp-mode)
|
|
146 (enable-local-eval nil))
|
|
147 (normal-mode)
|
|
148 (setq filename buffer-file-name)))
|
|
149 (test-harness-from-buffer input-buffer filename)
|
|
150 (kill-buffer input-buffer)
|
|
151 ))
|
|
152
|
|
153 (defun test-harness-read-from-buffer (buffer)
|
|
154 "Read forms from BUFFER, and turn it into a lambda test form."
|
|
155 (let ((body nil))
|
|
156 (goto-char (point-min) buffer)
|
|
157 (condition-case error-info
|
|
158 (while t
|
|
159 (setq body (cons (read buffer) body)))
|
|
160 (end-of-file nil)
|
|
161 (error
|
3471
|
162 (incf unexpected-test-file-failures)
|
1751
|
163 (princ (format "Unexpected error %S reading forms from buffer\n"
|
|
164 error-info))))
|
428
|
165 `(lambda ()
|
|
166 (defvar passes)
|
|
167 (defvar assertion-failures)
|
|
168 (defvar no-error-failures)
|
|
169 (defvar wrong-error-failures)
|
|
170 (defvar missing-message-failures)
|
|
171 (defvar other-failures)
|
|
172
|
|
173 (defvar trick-optimizer)
|
|
174
|
|
175 ,@(nreverse body))))
|
|
176
|
|
177 (defun test-harness-from-buffer (inbuffer filename)
|
|
178 "Run tests in buffer INBUFFER, visiting FILENAME."
|
|
179 (defvar trick-optimizer)
|
|
180 (let ((passes 0)
|
|
181 (assertion-failures 0)
|
|
182 (no-error-failures 0)
|
|
183 (wrong-error-failures 0)
|
|
184 (missing-message-failures 0)
|
|
185 (other-failures 0)
|
3471
|
186 (unexpected-test-file-failures 0)
|
428
|
187
|
973
|
188 ;; #### perhaps this should be a defvar, and output at the very end
|
|
189 ;; OTOH, this way AC types can use a null EMACSPACKAGEPATH to find
|
|
190 ;; what stuff is needed, and ways to avoid using them
|
|
191 (skipped-test-reasons (make-hash-table :test 'equal))
|
|
192
|
428
|
193 (trick-optimizer nil)
|
826
|
194 (debug-on-error t)
|
|
195 (pass-stream nil))
|
428
|
196 (with-output-to-temp-buffer "*Test-Log*"
|
826
|
197 (princ (format "Testing %s...\n\n" filename))
|
1095
|
198
|
1413
|
199 (defconst test-harness-failure-tag "FAIL")
|
|
200 (defconst test-harness-success-tag "PASS")
|
1095
|
201
|
|
202 (defmacro Known-Bug-Expect-Failure (&rest body)
|
1413
|
203 `(let ((test-harness-failure-tag "KNOWN BUG")
|
|
204 (test-harness-success-tag "PASS (FAILURE EXPECTED)"))
|
|
205 ,@body))
|
|
206
|
|
207 (defmacro Implementation-Incomplete-Expect-Failure (&rest body)
|
|
208 `(let ((test-harness-failure-tag "IMPLEMENTATION INCOMPLETE")
|
|
209 (test-harness-success-tag "PASS (FAILURE EXPECTED)"))
|
|
210 ,@body))
|
826
|
211
|
|
212 (defun Print-Failure (fmt &rest args)
|
1413
|
213 (setq fmt (format "%s: %s" test-harness-failure-tag fmt))
|
826
|
214 (if (noninteractive) (apply #'message fmt args))
|
|
215 (princ (concat (apply #'format fmt args) "\n")))
|
|
216
|
|
217 (defun Print-Pass (fmt &rest args)
|
1413
|
218 (setq fmt (format "%s: %s" test-harness-success-tag fmt))
|
826
|
219 (and test-harness-verbose
|
|
220 (princ (concat (apply #'format fmt args) "\n"))))
|
|
221
|
973
|
222 (defun Print-Skip (test reason &optional fmt &rest args)
|
1095
|
223 (setq fmt (concat "SKIP: %S BECAUSE %S" fmt))
|
973
|
224 (princ (concat (apply #'format fmt test reason args) "\n")))
|
|
225
|
1095
|
226 (defmacro Skip-Test-Unless (condition reason description &rest body)
|
|
227 "Unless CONDITION is satisfied, skip test BODY.
|
|
228 REASON is a description of the condition failure, and must be unique (it
|
|
229 is used as a hash key). DESCRIPTION describes the tests that were skipped.
|
|
230 BODY is a sequence of expressions and may contain several tests."
|
|
231 `(if (not ,condition)
|
|
232 (let ((count (gethash ,reason skipped-test-reasons)))
|
|
233 (puthash ,reason (if (null count) 1 (1+ count))
|
|
234 skipped-test-reasons)
|
|
235 (Print-Skip ,description ,reason))
|
|
236 ,@body))
|
428
|
237
|
2056
|
238 (defmacro Assert (assertion &optional failing-case)
|
428
|
239 `(condition-case error-info
|
2056
|
240 (progn
|
|
241 (assert ,assertion)
|
|
242 (Print-Pass "%S" (quote ,assertion))
|
|
243 (incf passes))
|
|
244 (cl-assertion-failed
|
|
245 (Print-Failure (if ,failing-case
|
|
246 "Assertion failed: %S; failing case = %S"
|
|
247 "Assertion failed: %S")
|
|
248 (quote ,assertion) ,failing-case)
|
|
249 (incf assertion-failures))
|
|
250 (t (Print-Failure (if ,failing-case
|
|
251 "%S ==> error: %S; failing case = %S"
|
|
252 "%S ==> error: %S")
|
|
253 (quote ,assertion) error-info ,failing-case)
|
|
254 (incf other-failures)
|
|
255 )))
|
|
256
|
428
|
257
|
|
258 (defmacro Check-Error (expected-error &rest body)
|
|
259 (let ((quoted-body (if (= 1 (length body))
|
|
260 `(quote ,(car body)) `(quote (progn ,@body)))))
|
|
261 `(condition-case error-info
|
|
262 (progn
|
|
263 (setq trick-optimizer (progn ,@body))
|
826
|
264 (Print-Failure "%S executed successfully, but expected error %S"
|
428
|
265 ,quoted-body
|
826
|
266 ',expected-error)
|
428
|
267 (incf no-error-failures))
|
|
268 (,expected-error
|
826
|
269 (Print-Pass "%S ==> error %S, as expected"
|
|
270 ,quoted-body ',expected-error)
|
428
|
271 (incf passes))
|
|
272 (error
|
826
|
273 (Print-Failure "%S ==> expected error %S, got error %S instead"
|
|
274 ,quoted-body ',expected-error error-info)
|
428
|
275 (incf wrong-error-failures)))))
|
|
276
|
826
|
277 (defmacro Check-Error-Message (expected-error expected-error-regexp
|
|
278 &rest body)
|
428
|
279 (let ((quoted-body (if (= 1 (length body))
|
|
280 `(quote ,(car body)) `(quote (progn ,@body)))))
|
|
281 `(condition-case error-info
|
|
282 (progn
|
|
283 (setq trick-optimizer (progn ,@body))
|
826
|
284 (Print-Failure "%S executed successfully, but expected error %S"
|
|
285 ,quoted-body ',expected-error)
|
428
|
286 (incf no-error-failures))
|
|
287 (,expected-error
|
|
288 (let ((error-message (second error-info)))
|
|
289 (if (string-match ,expected-error-regexp error-message)
|
|
290 (progn
|
826
|
291 (Print-Pass "%S ==> error %S %S, as expected"
|
|
292 ,quoted-body error-message ',expected-error)
|
428
|
293 (incf passes))
|
826
|
294 (Print-Failure "%S ==> got error %S as expected, but error message %S did not match regexp %S"
|
|
295 ,quoted-body ',expected-error error-message ,expected-error-regexp)
|
428
|
296 (incf wrong-error-failures))))
|
|
297 (error
|
826
|
298 (Print-Failure "%S ==> expected error %S, got error %S instead"
|
|
299 ,quoted-body ',expected-error error-info)
|
428
|
300 (incf wrong-error-failures)))))
|
|
301
|
3472
|
302 ;; Do not use this with Silence-Message.
|
428
|
303 (defmacro Check-Message (expected-message-regexp &rest body)
|
1095
|
304 (Skip-Test-Unless (fboundp 'defadvice)
|
|
305 "can't defadvice"
|
|
306 expected-message-regexp
|
973
|
307 (let ((quoted-body (if (= 1 (length body))
|
|
308 `(quote ,(car body))
|
|
309 `(quote (progn ,@body)))))
|
|
310 `(let ((messages ""))
|
|
311 (defadvice message (around collect activate)
|
|
312 (defvar messages)
|
|
313 (let ((msg-string (apply 'format (ad-get-args 0))))
|
|
314 (setq messages (concat messages msg-string))
|
|
315 msg-string))
|
|
316 (condition-case error-info
|
|
317 (progn
|
|
318 (setq trick-optimizer (progn ,@body))
|
|
319 (if (string-match ,expected-message-regexp messages)
|
|
320 (progn
|
|
321 (Print-Pass "%S ==> value %S, message %S, matching %S, as expected"
|
|
322 ,quoted-body trick-optimizer messages ',expected-message-regexp)
|
|
323 (incf passes))
|
|
324 (Print-Failure "%S ==> value %S, message %S, NOT matching expected %S"
|
|
325 ,quoted-body trick-optimizer messages
|
|
326 ',expected-message-regexp)
|
|
327 (incf missing-message-failures)))
|
|
328 (error
|
|
329 (Print-Failure "%S ==> unexpected error %S"
|
|
330 ,quoted-body error-info)
|
|
331 (incf other-failures)))
|
|
332 (ad-unadvise 'message)))))
|
428
|
333
|
3472
|
334 ;; #### Perhaps this should override `message' itself, too?
|
|
335 (defmacro Silence-Message (&rest body)
|
|
336 `(flet ((append-message (&rest args) ())) ,@body))
|
|
337
|
428
|
338 (defmacro Ignore-Ebola (&rest body)
|
|
339 `(let ((debug-issue-ebola-notices -42)) ,@body))
|
|
340
|
|
341 (defun Int-to-Marker (pos)
|
|
342 (save-excursion
|
|
343 (set-buffer standard-output)
|
|
344 (save-excursion
|
|
345 (goto-char pos)
|
|
346 (point-marker))))
|
|
347
|
|
348 (princ "Testing Interpreted Lisp\n\n")
|
|
349 (condition-case error-info
|
|
350 (funcall (test-harness-read-from-buffer inbuffer))
|
|
351 (error
|
3471
|
352 (incf unexpected-test-file-failures)
|
428
|
353 (princ (format "Unexpected error %S while executing interpreted code\n"
|
|
354 error-info))
|
|
355 (message "Unexpected error %S while executing interpreted code." error-info)
|
|
356 (message "Test suite execution aborted." error-info)
|
|
357 ))
|
|
358 (princ "\nTesting Compiled Lisp\n\n")
|
1758
|
359 (let (code
|
|
360 (test-harness-test-compiled t))
|
428
|
361 (condition-case error-info
|
446
|
362 (setq code
|
|
363 ;; our lisp code is often intentionally dubious,
|
|
364 ;; so throw away _all_ the byte compiler warnings.
|
|
365 (letf (((symbol-function 'byte-compile-warn) 'ignore))
|
|
366 (byte-compile (test-harness-read-from-buffer inbuffer))))
|
428
|
367 (error
|
|
368 (princ (format "Unexpected error %S while byte-compiling code\n"
|
|
369 error-info))))
|
|
370 (condition-case error-info
|
|
371 (if code (funcall code))
|
|
372 (error
|
3471
|
373 (incf unexpected-test-file-failures)
|
428
|
374 (princ (format "Unexpected error %S while executing byte-compiled code\n"
|
|
375 error-info))
|
|
376 (message "Unexpected error %S while executing byte-compiled code." error-info)
|
|
377 (message "Test suite execution aborted." error-info)
|
|
378 )))
|
826
|
379 (princ (format "\nSUMMARY for %s:\n" filename))
|
428
|
380 (princ (format "\t%5d passes\n" passes))
|
|
381 (princ (format "\t%5d assertion failures\n" assertion-failures))
|
|
382 (princ (format "\t%5d errors that should have been generated, but weren't\n" no-error-failures))
|
|
383 (princ (format "\t%5d wrong-error failures\n" wrong-error-failures))
|
|
384 (princ (format "\t%5d missing-message failures\n" missing-message-failures))
|
|
385 (princ (format "\t%5d other failures\n" other-failures))
|
|
386 (let* ((total (+ passes
|
|
387 assertion-failures
|
|
388 no-error-failures
|
|
389 wrong-error-failures
|
|
390 missing-message-failures
|
|
391 other-failures))
|
|
392 (basename (file-name-nondirectory filename))
|
|
393 (summary-msg
|
|
394 (if (> total 0)
|
1751
|
395 (format test-harness-file-summary-template
|
|
396 (concat basename ":")
|
|
397 passes total (/ (* 100 passes) total))
|
|
398 (format test-harness-null-summary-template
|
|
399 (concat basename ":"))))
|
973
|
400 (reasons ""))
|
|
401 (maphash (lambda (key value)
|
|
402 (setq reasons
|
|
403 (concat reasons
|
1095
|
404 (format "\n %d tests skipped because %s."
|
973
|
405 value key))))
|
|
406 skipped-test-reasons)
|
|
407 (when (> (length reasons) 1)
|
|
408 (setq summary-msg (concat summary-msg reasons "
|
|
409 Probably XEmacs cannot find your installed packages. Set EMACSPACKAGEPATH
|
|
410 to the package hierarchy root or configure with --package-path to enable
|
|
411 the skipped tests.")))
|
1719
|
412 (setq test-harness-file-results-alist
|
|
413 (cons (list filename passes total)
|
|
414 test-harness-file-results-alist))
|
428
|
415 (message "%s" summary-msg))
|
3471
|
416 (when (> unexpected-test-file-failures 0)
|
|
417 (setq unexpected-test-suite-failure-files
|
|
418 (cons filename unexpected-test-suite-failure-files))
|
|
419 (setq unexpected-test-suite-failures
|
|
420 (+ unexpected-test-suite-failures unexpected-test-file-failures))
|
428
|
421 (message "Test suite execution failed unexpectedly."))
|
|
422 (fmakunbound 'Assert)
|
|
423 (fmakunbound 'Check-Error)
|
863
|
424 (fmakunbound 'Check-Message)
|
|
425 (fmakunbound 'Check-Error-Message)
|
428
|
426 (fmakunbound 'Ignore-Ebola)
|
|
427 (fmakunbound 'Int-to-Marker)
|
1719
|
428 (and noninteractive
|
|
429 (message "%s" (buffer-substring-no-properties
|
1751
|
430 nil nil "*Test-Log*")))
|
|
431 )))
|
428
|
432
|
|
433 (defvar test-harness-results-point-max nil)
|
|
434 (defmacro displaying-emacs-test-results (&rest body)
|
|
435 `(let ((test-harness-results-point-max test-harness-results-point-max))
|
|
436 ;; Log the file name.
|
|
437 (test-harness-log-file)
|
|
438 ;; Record how much is logged now.
|
|
439 ;; We will display the log buffer if anything more is logged
|
|
440 ;; before the end of BODY.
|
|
441 (or test-harness-results-point-max
|
|
442 (save-excursion
|
|
443 (set-buffer (get-buffer-create "*Test-Log*"))
|
|
444 (setq test-harness-results-point-max (point-max))))
|
|
445 (unwind-protect
|
|
446 (condition-case error-info
|
|
447 (progn ,@body)
|
|
448 (error
|
|
449 (test-harness-report-error error-info)))
|
|
450 (save-excursion
|
|
451 ;; If there were compilation warnings, display them.
|
|
452 (set-buffer "*Test-Log*")
|
|
453 (if (= test-harness-results-point-max (point-max))
|
|
454 nil
|
|
455 (if temp-buffer-show-function
|
|
456 (let ((show-buffer (get-buffer-create "*Test-Log-Show*")))
|
|
457 (save-excursion
|
|
458 (set-buffer show-buffer)
|
|
459 (setq buffer-read-only nil)
|
|
460 (erase-buffer))
|
|
461 (copy-to-buffer show-buffer
|
|
462 (save-excursion
|
|
463 (goto-char test-harness-results-point-max)
|
|
464 (forward-line -1)
|
|
465 (point))
|
|
466 (point-max))
|
|
467 (funcall temp-buffer-show-function show-buffer))
|
|
468 (select-window
|
|
469 (prog1 (selected-window)
|
|
470 (select-window (display-buffer (current-buffer)))
|
|
471 (goto-char test-harness-results-point-max)
|
|
472 (recenter 1)))))))))
|
|
473
|
|
474 (defun batch-test-emacs-1 (file)
|
|
475 (condition-case error-info
|
|
476 (progn (test-emacs-test-file file) t)
|
|
477 (error
|
|
478 (princ ">>Error occurred processing ")
|
|
479 (princ file)
|
|
480 (princ ": ")
|
|
481 (display-error error-info nil)
|
|
482 (terpri)
|
|
483 nil)))
|
|
484
|
|
485 (defun batch-test-emacs ()
|
|
486 "Run `test-harness' on the files remaining on the command line.
|
|
487 Use this from the command line, with `-batch';
|
|
488 it won't work in an interactive Emacs.
|
|
489 Each file is processed even if an error occurred previously.
|
|
490 For example, invoke \"xemacs -batch -f batch-test-emacs tests/*.el\""
|
|
491 ;; command-line-args-left is what is left of the command line (from
|
|
492 ;; startup.el)
|
|
493 (defvar command-line-args-left) ;Avoid 'free variable' warning
|
|
494 (defvar debug-issue-ebola-notices)
|
|
495 (if (not noninteractive)
|
|
496 (error "`batch-test-emacs' is to be used only with -batch"))
|
|
497 (let ((error nil))
|
|
498 (dolist (file command-line-args-left)
|
|
499 (if (file-directory-p file)
|
|
500 (dolist (file-in-dir (directory-files file t))
|
|
501 (when (and (string-match emacs-lisp-file-regexp file-in-dir)
|
|
502 (not (or (auto-save-file-name-p file-in-dir)
|
|
503 (backup-file-name-p file-in-dir)
|
|
504 (equal (file-name-nondirectory file-in-dir)
|
|
505 "test-harness.el"))))
|
|
506 (or (batch-test-emacs-1 file-in-dir)
|
|
507 (setq error t))))
|
|
508 (or (batch-test-emacs-1 file)
|
|
509 (setq error t))))
|
1719
|
510 (let ((namelen 0)
|
|
511 (succlen 0)
|
|
512 (testlen 0)
|
|
513 (results test-harness-file-results-alist))
|
|
514 ;; compute maximum lengths of variable components of report
|
|
515 ;; probably should just use (length "byte-compiler-tests.el")
|
|
516 ;; and 5-place sizes -- this will also work for the file-by-file
|
|
517 ;; printing when Adrian's kludge gets reverted
|
|
518 (flet ((print-width (i)
|
|
519 (let ((x 10) (y 1))
|
|
520 (while (>= i x)
|
|
521 (setq x (* 10 x) y (1+ y)))
|
|
522 y)))
|
|
523 (while results
|
|
524 (let* ((head (car results))
|
|
525 (nn (length (file-name-nondirectory (first head))))
|
|
526 (ss (print-width (second head)))
|
|
527 (tt (print-width (third head))))
|
|
528 (when (> nn namelen) (setq namelen nn))
|
|
529 (when (> ss succlen) (setq succlen ss))
|
|
530 (when (> tt testlen) (setq testlen tt)))
|
|
531 (setq results (cdr results))))
|
|
532 ;; create format and print
|
1751
|
533 (let ((results (reverse test-harness-file-results-alist)))
|
1719
|
534 (while results
|
|
535 (let* ((head (car results))
|
1751
|
536 (basename (file-name-nondirectory (first head)))
|
1719
|
537 (nsucc (second head))
|
|
538 (ntest (third head)))
|
1722
|
539 (if (> ntest 0)
|
1751
|
540 (message test-harness-file-summary-template
|
|
541 (concat basename ":")
|
1722
|
542 nsucc
|
|
543 ntest
|
|
544 (/ (* 100 nsucc) ntest))
|
1751
|
545 (message test-harness-null-summary-template
|
|
546 (concat basename ":")))
|
3471
|
547 (setq results (cdr results)))))
|
|
548 (when (> unexpected-test-suite-failures 0)
|
|
549 (message "\n***** There %s %d unexpected test suite %s in %s:"
|
|
550 (if (= unexpected-test-suite-failures 1) "was" "were")
|
|
551 unexpected-test-suite-failures
|
|
552 (if (= unexpected-test-suite-failures 1) "failure" "failures")
|
|
553 (if (= (length unexpected-test-suite-failure-files) 1)
|
|
554 "file"
|
|
555 "files"))
|
|
556 (while unexpected-test-suite-failure-files
|
|
557 (let ((line (pop unexpected-test-suite-failure-files)))
|
|
558 (while (and (< (length line) 61)
|
|
559 unexpected-test-suite-failure-files)
|
|
560 (setq line
|
|
561 (concat line " "
|
|
562 (pop unexpected-test-suite-failure-files))))
|
|
563 (message line)))))
|
1719
|
564 (message "\nDone")
|
428
|
565 (kill-emacs (if error 1 0))))
|
|
566
|
|
567 (provide 'test-harness)
|
|
568
|
|
569 ;;; test-harness.el ends here
|