Mercurial > hg > xemacs-beta
annotate tests/automated/test-harness.el @ 4323:94509abd0ef0
Commit a forgotten chunk of 4d0f773d5e21.
This is the change to the file tests/automated/test-harness.el. See the
tests/ChangeLog of that commit,
http://mid.gmane.org/E1J1MtP-0000bo-Vw@alioth.debian.org for the details.
author | Aidan Kehoe <kehoea@parhasard.net> |
---|---|
date | Tue, 11 Dec 2007 21:41:54 +0100 |
parents | 3660d327399f |
children | 7b628daa39d4 |
rev | line source |
---|---|
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)) | |
4323
94509abd0ef0
Commit a forgotten chunk of 4d0f773d5e21.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4199
diff
changeset
|
206 |
94509abd0ef0
Commit a forgotten chunk of 4d0f773d5e21.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4199
diff
changeset
|
207 (defmacro Known-Bug-Expect-Error (expected-error &rest body) |
94509abd0ef0
Commit a forgotten chunk of 4d0f773d5e21.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4199
diff
changeset
|
208 (let ((quoted-body (if (= 1 (length body)) |
94509abd0ef0
Commit a forgotten chunk of 4d0f773d5e21.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4199
diff
changeset
|
209 `(quote ,(car body)) `(quote (progn ,@body))))) |
94509abd0ef0
Commit a forgotten chunk of 4d0f773d5e21.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4199
diff
changeset
|
210 `(let ((test-harness-failure-tag "KNOWN BUG") |
94509abd0ef0
Commit a forgotten chunk of 4d0f773d5e21.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4199
diff
changeset
|
211 (test-harness-success-tag "PASS (FAILURE EXPECTED)")) |
94509abd0ef0
Commit a forgotten chunk of 4d0f773d5e21.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4199
diff
changeset
|
212 (condition-case error-info |
94509abd0ef0
Commit a forgotten chunk of 4d0f773d5e21.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4199
diff
changeset
|
213 (progn |
94509abd0ef0
Commit a forgotten chunk of 4d0f773d5e21.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4199
diff
changeset
|
214 (setq trick-optimizer (progn ,@body)) |
94509abd0ef0
Commit a forgotten chunk of 4d0f773d5e21.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4199
diff
changeset
|
215 (Print-Pass |
94509abd0ef0
Commit a forgotten chunk of 4d0f773d5e21.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4199
diff
changeset
|
216 "%S executed successfully, but expected error %S" |
94509abd0ef0
Commit a forgotten chunk of 4d0f773d5e21.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4199
diff
changeset
|
217 ,quoted-body |
94509abd0ef0
Commit a forgotten chunk of 4d0f773d5e21.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4199
diff
changeset
|
218 ',expected-error) |
94509abd0ef0
Commit a forgotten chunk of 4d0f773d5e21.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4199
diff
changeset
|
219 (incf passes)) |
94509abd0ef0
Commit a forgotten chunk of 4d0f773d5e21.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4199
diff
changeset
|
220 (,expected-error |
94509abd0ef0
Commit a forgotten chunk of 4d0f773d5e21.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4199
diff
changeset
|
221 (Print-Failure "%S ==> error %S, as expected" |
94509abd0ef0
Commit a forgotten chunk of 4d0f773d5e21.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4199
diff
changeset
|
222 ,quoted-body ',expected-error) |
94509abd0ef0
Commit a forgotten chunk of 4d0f773d5e21.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4199
diff
changeset
|
223 (incf no-error-failures)) |
94509abd0ef0
Commit a forgotten chunk of 4d0f773d5e21.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4199
diff
changeset
|
224 (error |
94509abd0ef0
Commit a forgotten chunk of 4d0f773d5e21.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4199
diff
changeset
|
225 (Print-Failure "%S ==> expected error %S, got error %S instead" |
94509abd0ef0
Commit a forgotten chunk of 4d0f773d5e21.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4199
diff
changeset
|
226 ,quoted-body ',expected-error error-info) |
94509abd0ef0
Commit a forgotten chunk of 4d0f773d5e21.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4199
diff
changeset
|
227 (incf wrong-error-failures)))))) |
94509abd0ef0
Commit a forgotten chunk of 4d0f773d5e21.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4199
diff
changeset
|
228 |
1413 | 229 (defmacro Implementation-Incomplete-Expect-Failure (&rest body) |
230 `(let ((test-harness-failure-tag "IMPLEMENTATION INCOMPLETE") | |
231 (test-harness-success-tag "PASS (FAILURE EXPECTED)")) | |
232 ,@body)) | |
826 | 233 |
234 (defun Print-Failure (fmt &rest args) | |
1413 | 235 (setq fmt (format "%s: %s" test-harness-failure-tag fmt)) |
826 | 236 (if (noninteractive) (apply #'message fmt args)) |
237 (princ (concat (apply #'format fmt args) "\n"))) | |
238 | |
239 (defun Print-Pass (fmt &rest args) | |
1413 | 240 (setq fmt (format "%s: %s" test-harness-success-tag fmt)) |
826 | 241 (and test-harness-verbose |
242 (princ (concat (apply #'format fmt args) "\n")))) | |
243 | |
973 | 244 (defun Print-Skip (test reason &optional fmt &rest args) |
1095 | 245 (setq fmt (concat "SKIP: %S BECAUSE %S" fmt)) |
973 | 246 (princ (concat (apply #'format fmt test reason args) "\n"))) |
247 | |
1095 | 248 (defmacro Skip-Test-Unless (condition reason description &rest body) |
249 "Unless CONDITION is satisfied, skip test BODY. | |
250 REASON is a description of the condition failure, and must be unique (it | |
251 is used as a hash key). DESCRIPTION describes the tests that were skipped. | |
252 BODY is a sequence of expressions and may contain several tests." | |
253 `(if (not ,condition) | |
254 (let ((count (gethash ,reason skipped-test-reasons))) | |
255 (puthash ,reason (if (null count) 1 (1+ count)) | |
256 skipped-test-reasons) | |
257 (Print-Skip ,description ,reason)) | |
258 ,@body)) | |
428 | 259 |
2056 | 260 (defmacro Assert (assertion &optional failing-case) |
428 | 261 `(condition-case error-info |
2056 | 262 (progn |
263 (assert ,assertion) | |
264 (Print-Pass "%S" (quote ,assertion)) | |
265 (incf passes)) | |
266 (cl-assertion-failed | |
267 (Print-Failure (if ,failing-case | |
268 "Assertion failed: %S; failing case = %S" | |
269 "Assertion failed: %S") | |
270 (quote ,assertion) ,failing-case) | |
271 (incf assertion-failures)) | |
272 (t (Print-Failure (if ,failing-case | |
273 "%S ==> error: %S; failing case = %S" | |
274 "%S ==> error: %S") | |
275 (quote ,assertion) error-info ,failing-case) | |
276 (incf other-failures) | |
277 ))) | |
278 | |
428 | 279 |
280 (defmacro Check-Error (expected-error &rest body) | |
281 (let ((quoted-body (if (= 1 (length body)) | |
282 `(quote ,(car body)) `(quote (progn ,@body))))) | |
283 `(condition-case error-info | |
284 (progn | |
285 (setq trick-optimizer (progn ,@body)) | |
826 | 286 (Print-Failure "%S executed successfully, but expected error %S" |
428 | 287 ,quoted-body |
826 | 288 ',expected-error) |
428 | 289 (incf no-error-failures)) |
290 (,expected-error | |
826 | 291 (Print-Pass "%S ==> error %S, as expected" |
292 ,quoted-body ',expected-error) | |
428 | 293 (incf passes)) |
294 (error | |
826 | 295 (Print-Failure "%S ==> expected error %S, got error %S instead" |
296 ,quoted-body ',expected-error error-info) | |
428 | 297 (incf wrong-error-failures))))) |
298 | |
826 | 299 (defmacro Check-Error-Message (expected-error expected-error-regexp |
300 &rest body) | |
428 | 301 (let ((quoted-body (if (= 1 (length body)) |
302 `(quote ,(car body)) `(quote (progn ,@body))))) | |
303 `(condition-case error-info | |
304 (progn | |
305 (setq trick-optimizer (progn ,@body)) | |
826 | 306 (Print-Failure "%S executed successfully, but expected error %S" |
307 ,quoted-body ',expected-error) | |
428 | 308 (incf no-error-failures)) |
309 (,expected-error | |
4199 | 310 ;; #### Damn, this binding doesn't capture frobs, eg, for |
311 ;; invalid_argument() ... you only get the REASON. And for | |
312 ;; wrong_type_argument(), there's no reason only FROBs. | |
313 ;; If this gets fixed, fix tests in regexp-tests.el. | |
428 | 314 (let ((error-message (second error-info))) |
315 (if (string-match ,expected-error-regexp error-message) | |
316 (progn | |
826 | 317 (Print-Pass "%S ==> error %S %S, as expected" |
318 ,quoted-body error-message ',expected-error) | |
428 | 319 (incf passes)) |
826 | 320 (Print-Failure "%S ==> got error %S as expected, but error message %S did not match regexp %S" |
321 ,quoted-body ',expected-error error-message ,expected-error-regexp) | |
428 | 322 (incf wrong-error-failures)))) |
323 (error | |
826 | 324 (Print-Failure "%S ==> expected error %S, got error %S instead" |
325 ,quoted-body ',expected-error error-info) | |
428 | 326 (incf wrong-error-failures))))) |
327 | |
3472 | 328 ;; Do not use this with Silence-Message. |
428 | 329 (defmacro Check-Message (expected-message-regexp &rest body) |
1095 | 330 (Skip-Test-Unless (fboundp 'defadvice) |
331 "can't defadvice" | |
332 expected-message-regexp | |
973 | 333 (let ((quoted-body (if (= 1 (length body)) |
334 `(quote ,(car body)) | |
335 `(quote (progn ,@body))))) | |
336 `(let ((messages "")) | |
337 (defadvice message (around collect activate) | |
338 (defvar messages) | |
339 (let ((msg-string (apply 'format (ad-get-args 0)))) | |
340 (setq messages (concat messages msg-string)) | |
341 msg-string)) | |
342 (condition-case error-info | |
343 (progn | |
344 (setq trick-optimizer (progn ,@body)) | |
345 (if (string-match ,expected-message-regexp messages) | |
346 (progn | |
347 (Print-Pass "%S ==> value %S, message %S, matching %S, as expected" | |
348 ,quoted-body trick-optimizer messages ',expected-message-regexp) | |
349 (incf passes)) | |
350 (Print-Failure "%S ==> value %S, message %S, NOT matching expected %S" | |
351 ,quoted-body trick-optimizer messages | |
352 ',expected-message-regexp) | |
353 (incf missing-message-failures))) | |
354 (error | |
355 (Print-Failure "%S ==> unexpected error %S" | |
356 ,quoted-body error-info) | |
357 (incf other-failures))) | |
358 (ad-unadvise 'message))))) | |
428 | 359 |
3472 | 360 ;; #### Perhaps this should override `message' itself, too? |
361 (defmacro Silence-Message (&rest body) | |
4323
94509abd0ef0
Commit a forgotten chunk of 4d0f773d5e21.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4199
diff
changeset
|
362 `(flet ((append-message (&rest args) ()) |
94509abd0ef0
Commit a forgotten chunk of 4d0f773d5e21.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4199
diff
changeset
|
363 (clear-message (&rest args) ())) |
94509abd0ef0
Commit a forgotten chunk of 4d0f773d5e21.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4199
diff
changeset
|
364 ,@body)) |
3472 | 365 |
428 | 366 (defmacro Ignore-Ebola (&rest body) |
367 `(let ((debug-issue-ebola-notices -42)) ,@body)) | |
368 | |
369 (defun Int-to-Marker (pos) | |
370 (save-excursion | |
371 (set-buffer standard-output) | |
372 (save-excursion | |
373 (goto-char pos) | |
374 (point-marker)))) | |
375 | |
376 (princ "Testing Interpreted Lisp\n\n") | |
377 (condition-case error-info | |
378 (funcall (test-harness-read-from-buffer inbuffer)) | |
379 (error | |
3471 | 380 (incf unexpected-test-file-failures) |
428 | 381 (princ (format "Unexpected error %S while executing interpreted code\n" |
382 error-info)) | |
383 (message "Unexpected error %S while executing interpreted code." error-info) | |
384 (message "Test suite execution aborted." error-info) | |
385 )) | |
386 (princ "\nTesting Compiled Lisp\n\n") | |
1758 | 387 (let (code |
388 (test-harness-test-compiled t)) | |
428 | 389 (condition-case error-info |
446 | 390 (setq code |
391 ;; our lisp code is often intentionally dubious, | |
392 ;; so throw away _all_ the byte compiler warnings. | |
393 (letf (((symbol-function 'byte-compile-warn) 'ignore)) | |
394 (byte-compile (test-harness-read-from-buffer inbuffer)))) | |
428 | 395 (error |
396 (princ (format "Unexpected error %S while byte-compiling code\n" | |
397 error-info)))) | |
398 (condition-case error-info | |
399 (if code (funcall code)) | |
400 (error | |
3471 | 401 (incf unexpected-test-file-failures) |
428 | 402 (princ (format "Unexpected error %S while executing byte-compiled code\n" |
403 error-info)) | |
404 (message "Unexpected error %S while executing byte-compiled code." error-info) | |
405 (message "Test suite execution aborted." error-info) | |
406 ))) | |
826 | 407 (princ (format "\nSUMMARY for %s:\n" filename)) |
428 | 408 (princ (format "\t%5d passes\n" passes)) |
409 (princ (format "\t%5d assertion failures\n" assertion-failures)) | |
410 (princ (format "\t%5d errors that should have been generated, but weren't\n" no-error-failures)) | |
411 (princ (format "\t%5d wrong-error failures\n" wrong-error-failures)) | |
412 (princ (format "\t%5d missing-message failures\n" missing-message-failures)) | |
413 (princ (format "\t%5d other failures\n" other-failures)) | |
414 (let* ((total (+ passes | |
415 assertion-failures | |
416 no-error-failures | |
417 wrong-error-failures | |
418 missing-message-failures | |
419 other-failures)) | |
420 (basename (file-name-nondirectory filename)) | |
421 (summary-msg | |
422 (if (> total 0) | |
1751 | 423 (format test-harness-file-summary-template |
424 (concat basename ":") | |
425 passes total (/ (* 100 passes) total)) | |
426 (format test-harness-null-summary-template | |
427 (concat basename ":")))) | |
973 | 428 (reasons "")) |
429 (maphash (lambda (key value) | |
430 (setq reasons | |
431 (concat reasons | |
1095 | 432 (format "\n %d tests skipped because %s." |
973 | 433 value key)))) |
434 skipped-test-reasons) | |
435 (when (> (length reasons) 1) | |
436 (setq summary-msg (concat summary-msg reasons " | |
437 Probably XEmacs cannot find your installed packages. Set EMACSPACKAGEPATH | |
438 to the package hierarchy root or configure with --package-path to enable | |
439 the skipped tests."))) | |
1719 | 440 (setq test-harness-file-results-alist |
441 (cons (list filename passes total) | |
442 test-harness-file-results-alist)) | |
428 | 443 (message "%s" summary-msg)) |
3471 | 444 (when (> unexpected-test-file-failures 0) |
445 (setq unexpected-test-suite-failure-files | |
446 (cons filename unexpected-test-suite-failure-files)) | |
447 (setq unexpected-test-suite-failures | |
448 (+ unexpected-test-suite-failures unexpected-test-file-failures)) | |
428 | 449 (message "Test suite execution failed unexpectedly.")) |
450 (fmakunbound 'Assert) | |
451 (fmakunbound 'Check-Error) | |
863 | 452 (fmakunbound 'Check-Message) |
453 (fmakunbound 'Check-Error-Message) | |
428 | 454 (fmakunbound 'Ignore-Ebola) |
455 (fmakunbound 'Int-to-Marker) | |
1719 | 456 (and noninteractive |
457 (message "%s" (buffer-substring-no-properties | |
1751 | 458 nil nil "*Test-Log*"))) |
459 ))) | |
428 | 460 |
461 (defvar test-harness-results-point-max nil) | |
462 (defmacro displaying-emacs-test-results (&rest body) | |
463 `(let ((test-harness-results-point-max test-harness-results-point-max)) | |
464 ;; Log the file name. | |
465 (test-harness-log-file) | |
466 ;; Record how much is logged now. | |
467 ;; We will display the log buffer if anything more is logged | |
468 ;; before the end of BODY. | |
469 (or test-harness-results-point-max | |
470 (save-excursion | |
471 (set-buffer (get-buffer-create "*Test-Log*")) | |
472 (setq test-harness-results-point-max (point-max)))) | |
473 (unwind-protect | |
474 (condition-case error-info | |
475 (progn ,@body) | |
476 (error | |
477 (test-harness-report-error error-info))) | |
478 (save-excursion | |
479 ;; If there were compilation warnings, display them. | |
480 (set-buffer "*Test-Log*") | |
481 (if (= test-harness-results-point-max (point-max)) | |
482 nil | |
483 (if temp-buffer-show-function | |
484 (let ((show-buffer (get-buffer-create "*Test-Log-Show*"))) | |
485 (save-excursion | |
486 (set-buffer show-buffer) | |
487 (setq buffer-read-only nil) | |
488 (erase-buffer)) | |
489 (copy-to-buffer show-buffer | |
490 (save-excursion | |
491 (goto-char test-harness-results-point-max) | |
492 (forward-line -1) | |
493 (point)) | |
494 (point-max)) | |
495 (funcall temp-buffer-show-function show-buffer)) | |
496 (select-window | |
497 (prog1 (selected-window) | |
498 (select-window (display-buffer (current-buffer))) | |
499 (goto-char test-harness-results-point-max) | |
500 (recenter 1))))))))) | |
501 | |
502 (defun batch-test-emacs-1 (file) | |
503 (condition-case error-info | |
504 (progn (test-emacs-test-file file) t) | |
505 (error | |
506 (princ ">>Error occurred processing ") | |
507 (princ file) | |
508 (princ ": ") | |
509 (display-error error-info nil) | |
510 (terpri) | |
511 nil))) | |
512 | |
513 (defun batch-test-emacs () | |
514 "Run `test-harness' on the files remaining on the command line. | |
515 Use this from the command line, with `-batch'; | |
516 it won't work in an interactive Emacs. | |
517 Each file is processed even if an error occurred previously. | |
518 For example, invoke \"xemacs -batch -f batch-test-emacs tests/*.el\"" | |
519 ;; command-line-args-left is what is left of the command line (from | |
520 ;; startup.el) | |
521 (defvar command-line-args-left) ;Avoid 'free variable' warning | |
522 (defvar debug-issue-ebola-notices) | |
523 (if (not noninteractive) | |
524 (error "`batch-test-emacs' is to be used only with -batch")) | |
525 (let ((error nil)) | |
526 (dolist (file command-line-args-left) | |
527 (if (file-directory-p file) | |
528 (dolist (file-in-dir (directory-files file t)) | |
529 (when (and (string-match emacs-lisp-file-regexp file-in-dir) | |
530 (not (or (auto-save-file-name-p file-in-dir) | |
531 (backup-file-name-p file-in-dir) | |
532 (equal (file-name-nondirectory file-in-dir) | |
533 "test-harness.el")))) | |
534 (or (batch-test-emacs-1 file-in-dir) | |
535 (setq error t)))) | |
536 (or (batch-test-emacs-1 file) | |
537 (setq error t)))) | |
1719 | 538 (let ((namelen 0) |
539 (succlen 0) | |
540 (testlen 0) | |
541 (results test-harness-file-results-alist)) | |
542 ;; compute maximum lengths of variable components of report | |
543 ;; probably should just use (length "byte-compiler-tests.el") | |
544 ;; and 5-place sizes -- this will also work for the file-by-file | |
545 ;; printing when Adrian's kludge gets reverted | |
546 (flet ((print-width (i) | |
547 (let ((x 10) (y 1)) | |
548 (while (>= i x) | |
549 (setq x (* 10 x) y (1+ y))) | |
550 y))) | |
551 (while results | |
552 (let* ((head (car results)) | |
553 (nn (length (file-name-nondirectory (first head)))) | |
554 (ss (print-width (second head))) | |
555 (tt (print-width (third head)))) | |
556 (when (> nn namelen) (setq namelen nn)) | |
557 (when (> ss succlen) (setq succlen ss)) | |
558 (when (> tt testlen) (setq testlen tt))) | |
559 (setq results (cdr results)))) | |
560 ;; create format and print | |
1751 | 561 (let ((results (reverse test-harness-file-results-alist))) |
1719 | 562 (while results |
563 (let* ((head (car results)) | |
1751 | 564 (basename (file-name-nondirectory (first head))) |
1719 | 565 (nsucc (second head)) |
566 (ntest (third head))) | |
1722 | 567 (if (> ntest 0) |
1751 | 568 (message test-harness-file-summary-template |
569 (concat basename ":") | |
1722 | 570 nsucc |
571 ntest | |
572 (/ (* 100 nsucc) ntest)) | |
1751 | 573 (message test-harness-null-summary-template |
574 (concat basename ":"))) | |
3471 | 575 (setq results (cdr results))))) |
576 (when (> unexpected-test-suite-failures 0) | |
577 (message "\n***** There %s %d unexpected test suite %s in %s:" | |
578 (if (= unexpected-test-suite-failures 1) "was" "were") | |
579 unexpected-test-suite-failures | |
580 (if (= unexpected-test-suite-failures 1) "failure" "failures") | |
581 (if (= (length unexpected-test-suite-failure-files) 1) | |
582 "file" | |
583 "files")) | |
584 (while unexpected-test-suite-failure-files | |
585 (let ((line (pop unexpected-test-suite-failure-files))) | |
586 (while (and (< (length line) 61) | |
587 unexpected-test-suite-failure-files) | |
588 (setq line | |
589 (concat line " " | |
590 (pop unexpected-test-suite-failure-files)))) | |
591 (message line))))) | |
1719 | 592 (message "\nDone") |
428 | 593 (kill-emacs (if error 1 0)))) |
594 | |
595 (provide 'test-harness) | |
596 | |
597 ;;; test-harness.el ends here |