Mercurial > hg > xemacs-beta
annotate tests/automated/test-harness.el @ 4856:9bf09492cff7
Clean up macro Assert
author | Ben Wing <ben@xemacs.org> |
---|---|
date | Thu, 14 Jan 2010 02:29:13 -0600 |
parents | 189fb67ca31a |
children | 732c35cdded8 8b230c53075b |
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. |
4856 | 4 ;;; Copyright (C) 2002, 2010 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 |
4366
7b628daa39d4
Move debugging code to usage example.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4323
diff
changeset
|
74 "Non-nil means the test code was compiled before execution. |
7b628daa39d4
Move debugging code to usage example.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4323
diff
changeset
|
75 |
7b628daa39d4
Move debugging code to usage example.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4323
diff
changeset
|
76 You probably should not make tests depend on compilation. |
7b628daa39d4
Move debugging code to usage example.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4323
diff
changeset
|
77 However, it can be useful to conditionally change messages based on whether |
7b628daa39d4
Move debugging code to usage example.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4323
diff
changeset
|
78 the code was compiled or not. For example, the case that motivated the |
7b628daa39d4
Move debugging code to usage example.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4323
diff
changeset
|
79 implementation of this variable: |
7b628daa39d4
Move debugging code to usage example.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4323
diff
changeset
|
80 |
7b628daa39d4
Move debugging code to usage example.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4323
diff
changeset
|
81 \(when test-harness-test-compiled |
7b628daa39d4
Move debugging code to usage example.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4323
diff
changeset
|
82 ;; this ha-a-ack depends on the failing compiled test coming last |
7b628daa39d4
Move debugging code to usage example.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4323
diff
changeset
|
83 \(setq test-harness-failure-tag |
7b628daa39d4
Move debugging code to usage example.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4323
diff
changeset
|
84 \"KNOWN BUG - fix reverted; after 2003-10-31 notify stephen\n\"))") |
1758 | 85 |
428 | 86 (defvar test-harness-verbose |
87 (and (not noninteractive) (> (device-baud-rate) search-slow-speed)) | |
88 "*Non-nil means print messages describing progress of emacs-tester.") | |
89 | |
1719 | 90 (defvar test-harness-file-results-alist nil |
91 "Each element is a list (FILE SUCCESSES TESTS). | |
92 The order is the reverse of the order in which tests are run. | |
93 | |
94 FILE is a string naming the test file. | |
95 SUCCESSES is a non-negative integer, the number of successes. | |
96 TESTS is a non-negative integer, the number of tests run.") | |
97 | |
1425 | 98 (defvar test-harness-risk-infloops nil |
99 "*Non-nil to run tests that may loop infinitely in buggy implementations.") | |
100 | |
428 | 101 (defvar test-harness-current-file nil) |
102 | |
103 (defvar emacs-lisp-file-regexp (purecopy "\\.el\\'") | |
104 "*Regexp which matches Emacs Lisp source files.") | |
105 | |
1751 | 106 (defconst test-harness-file-summary-template |
107 (format "%%-%ds %%%dd of %%%dd tests successful (%%3d%%%%)." | |
108 (length "byte-compiler-tests.el:") ; use the longest file name | |
109 5 | |
110 5) | |
111 "Format for summary lines printed after each file is run.") | |
112 | |
113 (defconst test-harness-null-summary-template | |
114 (format "%%-%ds No tests run." | |
115 (length "byte-compiler-tests.el:")) ; use the longest file name | |
116 "Format for \"No tests\" lines printed after a file is run.") | |
117 | |
428 | 118 ;;;###autoload |
119 (defun test-emacs-test-file (filename) | |
120 "Test a file of Lisp code named FILENAME. | |
121 The output file's name is made by appending `c' to the end of FILENAME." | |
122 (interactive | |
123 (let ((file buffer-file-name) | |
124 (file-name nil) | |
125 (file-dir nil)) | |
126 (and file | |
127 (eq (cdr (assq 'major-mode (buffer-local-variables))) | |
128 'emacs-lisp-mode) | |
129 (setq file-name (file-name-nondirectory file) | |
130 file-dir (file-name-directory file))) | |
131 (list (read-file-name "Test file: " file-dir nil nil file-name)))) | |
132 ;; Expand now so we get the current buffer's defaults | |
133 (setq filename (expand-file-name filename)) | |
134 | |
135 ;; If we're testing a file that's in a buffer and is modified, offer | |
136 ;; to save it first. | |
137 (or noninteractive | |
138 (let ((b (get-file-buffer (expand-file-name filename)))) | |
139 (if (and b (buffer-modified-p b) | |
140 (y-or-n-p (format "save buffer %s first? " (buffer-name b)))) | |
141 (save-excursion (set-buffer b) (save-buffer))))) | |
142 | |
143 (if (or noninteractive test-harness-verbose) | |
144 (message "Testing %s..." filename)) | |
145 (let ((test-harness-current-file filename) | |
146 input-buffer) | |
147 (save-excursion | |
148 (setq input-buffer (get-buffer-create " *Test Input*")) | |
149 (set-buffer input-buffer) | |
150 (erase-buffer) | |
151 (insert-file-contents filename) | |
152 ;; Run hooks including the uncompression hook. | |
153 ;; If they change the file name, then change it for the output also. | |
154 (let ((buffer-file-name filename) | |
155 (default-major-mode 'emacs-lisp-mode) | |
156 (enable-local-eval nil)) | |
157 (normal-mode) | |
158 (setq filename buffer-file-name))) | |
159 (test-harness-from-buffer input-buffer filename) | |
160 (kill-buffer input-buffer) | |
161 )) | |
162 | |
163 (defun test-harness-read-from-buffer (buffer) | |
164 "Read forms from BUFFER, and turn it into a lambda test form." | |
165 (let ((body nil)) | |
166 (goto-char (point-min) buffer) | |
167 (condition-case error-info | |
168 (while t | |
169 (setq body (cons (read buffer) body))) | |
170 (end-of-file nil) | |
171 (error | |
3471 | 172 (incf unexpected-test-file-failures) |
1751 | 173 (princ (format "Unexpected error %S reading forms from buffer\n" |
174 error-info)))) | |
428 | 175 `(lambda () |
176 (defvar passes) | |
177 (defvar assertion-failures) | |
178 (defvar no-error-failures) | |
179 (defvar wrong-error-failures) | |
180 (defvar missing-message-failures) | |
181 (defvar other-failures) | |
182 | |
183 (defvar trick-optimizer) | |
184 | |
185 ,@(nreverse body)))) | |
186 | |
187 (defun test-harness-from-buffer (inbuffer filename) | |
188 "Run tests in buffer INBUFFER, visiting FILENAME." | |
189 (defvar trick-optimizer) | |
190 (let ((passes 0) | |
191 (assertion-failures 0) | |
192 (no-error-failures 0) | |
193 (wrong-error-failures 0) | |
194 (missing-message-failures 0) | |
195 (other-failures 0) | |
3471 | 196 (unexpected-test-file-failures 0) |
428 | 197 |
973 | 198 ;; #### perhaps this should be a defvar, and output at the very end |
199 ;; OTOH, this way AC types can use a null EMACSPACKAGEPATH to find | |
200 ;; what stuff is needed, and ways to avoid using them | |
201 (skipped-test-reasons (make-hash-table :test 'equal)) | |
202 | |
428 | 203 (trick-optimizer nil) |
826 | 204 (debug-on-error t) |
205 (pass-stream nil)) | |
428 | 206 (with-output-to-temp-buffer "*Test-Log*" |
826 | 207 (princ (format "Testing %s...\n\n" filename)) |
1095 | 208 |
1413 | 209 (defconst test-harness-failure-tag "FAIL") |
210 (defconst test-harness-success-tag "PASS") | |
1095 | 211 |
212 (defmacro Known-Bug-Expect-Failure (&rest body) | |
1413 | 213 `(let ((test-harness-failure-tag "KNOWN BUG") |
214 (test-harness-success-tag "PASS (FAILURE EXPECTED)")) | |
215 ,@body)) | |
4323
94509abd0ef0
Commit a forgotten chunk of 4d0f773d5e21.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4199
diff
changeset
|
216 |
94509abd0ef0
Commit a forgotten chunk of 4d0f773d5e21.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4199
diff
changeset
|
217 (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
|
218 (let ((quoted-body (if (= 1 (length body)) |
94509abd0ef0
Commit a forgotten chunk of 4d0f773d5e21.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4199
diff
changeset
|
219 `(quote ,(car body)) `(quote (progn ,@body))))) |
94509abd0ef0
Commit a forgotten chunk of 4d0f773d5e21.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4199
diff
changeset
|
220 `(let ((test-harness-failure-tag "KNOWN BUG") |
94509abd0ef0
Commit a forgotten chunk of 4d0f773d5e21.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4199
diff
changeset
|
221 (test-harness-success-tag "PASS (FAILURE EXPECTED)")) |
94509abd0ef0
Commit a forgotten chunk of 4d0f773d5e21.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4199
diff
changeset
|
222 (condition-case error-info |
94509abd0ef0
Commit a forgotten chunk of 4d0f773d5e21.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4199
diff
changeset
|
223 (progn |
94509abd0ef0
Commit a forgotten chunk of 4d0f773d5e21.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4199
diff
changeset
|
224 (setq trick-optimizer (progn ,@body)) |
94509abd0ef0
Commit a forgotten chunk of 4d0f773d5e21.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4199
diff
changeset
|
225 (Print-Pass |
94509abd0ef0
Commit a forgotten chunk of 4d0f773d5e21.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4199
diff
changeset
|
226 "%S executed successfully, but expected error %S" |
94509abd0ef0
Commit a forgotten chunk of 4d0f773d5e21.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4199
diff
changeset
|
227 ,quoted-body |
94509abd0ef0
Commit a forgotten chunk of 4d0f773d5e21.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4199
diff
changeset
|
228 ',expected-error) |
94509abd0ef0
Commit a forgotten chunk of 4d0f773d5e21.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4199
diff
changeset
|
229 (incf passes)) |
94509abd0ef0
Commit a forgotten chunk of 4d0f773d5e21.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4199
diff
changeset
|
230 (,expected-error |
94509abd0ef0
Commit a forgotten chunk of 4d0f773d5e21.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4199
diff
changeset
|
231 (Print-Failure "%S ==> error %S, as expected" |
94509abd0ef0
Commit a forgotten chunk of 4d0f773d5e21.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4199
diff
changeset
|
232 ,quoted-body ',expected-error) |
94509abd0ef0
Commit a forgotten chunk of 4d0f773d5e21.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4199
diff
changeset
|
233 (incf no-error-failures)) |
94509abd0ef0
Commit a forgotten chunk of 4d0f773d5e21.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4199
diff
changeset
|
234 (error |
94509abd0ef0
Commit a forgotten chunk of 4d0f773d5e21.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4199
diff
changeset
|
235 (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
|
236 ,quoted-body ',expected-error error-info) |
94509abd0ef0
Commit a forgotten chunk of 4d0f773d5e21.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4199
diff
changeset
|
237 (incf wrong-error-failures)))))) |
94509abd0ef0
Commit a forgotten chunk of 4d0f773d5e21.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4199
diff
changeset
|
238 |
1413 | 239 (defmacro Implementation-Incomplete-Expect-Failure (&rest body) |
240 `(let ((test-harness-failure-tag "IMPLEMENTATION INCOMPLETE") | |
241 (test-harness-success-tag "PASS (FAILURE EXPECTED)")) | |
242 ,@body)) | |
826 | 243 |
244 (defun Print-Failure (fmt &rest args) | |
1413 | 245 (setq fmt (format "%s: %s" test-harness-failure-tag fmt)) |
826 | 246 (if (noninteractive) (apply #'message fmt args)) |
247 (princ (concat (apply #'format fmt args) "\n"))) | |
248 | |
249 (defun Print-Pass (fmt &rest args) | |
1413 | 250 (setq fmt (format "%s: %s" test-harness-success-tag fmt)) |
826 | 251 (and test-harness-verbose |
252 (princ (concat (apply #'format fmt args) "\n")))) | |
253 | |
973 | 254 (defun Print-Skip (test reason &optional fmt &rest args) |
1095 | 255 (setq fmt (concat "SKIP: %S BECAUSE %S" fmt)) |
973 | 256 (princ (concat (apply #'format fmt test reason args) "\n"))) |
257 | |
1095 | 258 (defmacro Skip-Test-Unless (condition reason description &rest body) |
259 "Unless CONDITION is satisfied, skip test BODY. | |
260 REASON is a description of the condition failure, and must be unique (it | |
261 is used as a hash key). DESCRIPTION describes the tests that were skipped. | |
262 BODY is a sequence of expressions and may contain several tests." | |
263 `(if (not ,condition) | |
264 (let ((count (gethash ,reason skipped-test-reasons))) | |
265 (puthash ,reason (if (null count) 1 (1+ count)) | |
266 skipped-test-reasons) | |
267 (Print-Skip ,description ,reason)) | |
268 ,@body)) | |
428 | 269 |
4747
294a86d29f99
Eliminate C asserts from c-tests.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4415
diff
changeset
|
270 (defmacro Assert (assertion &optional failing-case description) |
294a86d29f99
Eliminate C asserts from c-tests.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4415
diff
changeset
|
271 "Test passes if ASSERTION is true. |
4856 | 272 Optional FAILING-CASE describes the particular failure. Optional |
273 DESCRIPTION describes the assertion; by default, the unevalated assertion | |
274 expression is given. FAILING-CASE and DESCRIPTION are useful when Assert | |
275 is used in a loop." | |
276 (let ((description | |
277 (or description `(quote ,assertion)))) | |
278 `(condition-case error-info | |
279 (progn | |
280 (assert ,assertion) | |
281 (Print-Pass "%S" ,description) | |
282 (incf passes)) | |
283 (cl-assertion-failed | |
284 (Print-Failure (if ,failing-case | |
285 "Assertion failed: %S; failing case = %S" | |
286 "Assertion failed: %S") | |
287 ,description ,failing-case) | |
288 (incf assertion-failures)) | |
289 (t (Print-Failure (if ,failing-case | |
290 "%S ==> error: %S; failing case = %S" | |
291 "%S ==> error: %S") | |
292 ,description error-info ,failing-case) | |
293 (incf other-failures) | |
294 )))) | |
2056 | 295 |
4855
189fb67ca31a
Create Assert-eq, Assert-equal, etc.
Ben Wing <ben@xemacs.org>
parents:
4845
diff
changeset
|
296 (defmacro Assert-test (test testval expected &optional failing-case |
189fb67ca31a
Create Assert-eq, Assert-equal, etc.
Ben Wing <ben@xemacs.org>
parents:
4845
diff
changeset
|
297 description) |
189fb67ca31a
Create Assert-eq, Assert-equal, etc.
Ben Wing <ben@xemacs.org>
parents:
4845
diff
changeset
|
298 "Test passes if TESTVAL is equal to EXPECTED, using TEST as comparator. |
189fb67ca31a
Create Assert-eq, Assert-equal, etc.
Ben Wing <ben@xemacs.org>
parents:
4845
diff
changeset
|
299 TEST should be a function such as `eq', `equal', `equalp', `=', `<=', etc. |
189fb67ca31a
Create Assert-eq, Assert-equal, etc.
Ben Wing <ben@xemacs.org>
parents:
4845
diff
changeset
|
300 Optional FAILING-CASE describes the particular failure; any value given |
189fb67ca31a
Create Assert-eq, Assert-equal, etc.
Ben Wing <ben@xemacs.org>
parents:
4845
diff
changeset
|
301 here will be concatenated with a phrase describing the expected and actual |
189fb67ca31a
Create Assert-eq, Assert-equal, etc.
Ben Wing <ben@xemacs.org>
parents:
4845
diff
changeset
|
302 values of the comparison. Optional DESCRIPTION describes the assertion; by |
189fb67ca31a
Create Assert-eq, Assert-equal, etc.
Ben Wing <ben@xemacs.org>
parents:
4845
diff
changeset
|
303 default, the unevalated comparison expressions are given. FAILING-CASE and |
189fb67ca31a
Create Assert-eq, Assert-equal, etc.
Ben Wing <ben@xemacs.org>
parents:
4845
diff
changeset
|
304 DESCRIPTION are useful when Assert is used in a loop." |
189fb67ca31a
Create Assert-eq, Assert-equal, etc.
Ben Wing <ben@xemacs.org>
parents:
4845
diff
changeset
|
305 (let* ((assertion `(,test ,testval ,expected)) |
189fb67ca31a
Create Assert-eq, Assert-equal, etc.
Ben Wing <ben@xemacs.org>
parents:
4845
diff
changeset
|
306 (failmsg `(format "expected %S, got %S" ,expected ,testval)) |
189fb67ca31a
Create Assert-eq, Assert-equal, etc.
Ben Wing <ben@xemacs.org>
parents:
4845
diff
changeset
|
307 (failmsg2 (if failing-case `(concat |
189fb67ca31a
Create Assert-eq, Assert-equal, etc.
Ben Wing <ben@xemacs.org>
parents:
4845
diff
changeset
|
308 (format "%S, " ,failing-case) |
189fb67ca31a
Create Assert-eq, Assert-equal, etc.
Ben Wing <ben@xemacs.org>
parents:
4845
diff
changeset
|
309 ,failmsg) |
189fb67ca31a
Create Assert-eq, Assert-equal, etc.
Ben Wing <ben@xemacs.org>
parents:
4845
diff
changeset
|
310 failmsg))) |
189fb67ca31a
Create Assert-eq, Assert-equal, etc.
Ben Wing <ben@xemacs.org>
parents:
4845
diff
changeset
|
311 `(Assert ,assertion ,failmsg2 ,description))) |
189fb67ca31a
Create Assert-eq, Assert-equal, etc.
Ben Wing <ben@xemacs.org>
parents:
4845
diff
changeset
|
312 |
189fb67ca31a
Create Assert-eq, Assert-equal, etc.
Ben Wing <ben@xemacs.org>
parents:
4845
diff
changeset
|
313 (defmacro Assert-eq (testval expected &optional failing-case description) |
189fb67ca31a
Create Assert-eq, Assert-equal, etc.
Ben Wing <ben@xemacs.org>
parents:
4845
diff
changeset
|
314 "Test passes if TESTVAL is 'eq' to EXPECTED. |
189fb67ca31a
Create Assert-eq, Assert-equal, etc.
Ben Wing <ben@xemacs.org>
parents:
4845
diff
changeset
|
315 Optional FAILING-CASE describes the particular failure; any value given |
189fb67ca31a
Create Assert-eq, Assert-equal, etc.
Ben Wing <ben@xemacs.org>
parents:
4845
diff
changeset
|
316 here will be concatenated with a phrase describing the expected and actual |
189fb67ca31a
Create Assert-eq, Assert-equal, etc.
Ben Wing <ben@xemacs.org>
parents:
4845
diff
changeset
|
317 values of the comparison. Optional DESCRIPTION describes the assertion; by |
189fb67ca31a
Create Assert-eq, Assert-equal, etc.
Ben Wing <ben@xemacs.org>
parents:
4845
diff
changeset
|
318 default, the unevalated comparison expressions are given. FAILING-CASE and |
189fb67ca31a
Create Assert-eq, Assert-equal, etc.
Ben Wing <ben@xemacs.org>
parents:
4845
diff
changeset
|
319 DESCRIPTION are useful when Assert is used in a loop." |
189fb67ca31a
Create Assert-eq, Assert-equal, etc.
Ben Wing <ben@xemacs.org>
parents:
4845
diff
changeset
|
320 `(Assert-test eq ,testval ,expected ,failing-case ,description)) |
189fb67ca31a
Create Assert-eq, Assert-equal, etc.
Ben Wing <ben@xemacs.org>
parents:
4845
diff
changeset
|
321 |
189fb67ca31a
Create Assert-eq, Assert-equal, etc.
Ben Wing <ben@xemacs.org>
parents:
4845
diff
changeset
|
322 (defmacro Assert-eql (testval expected &optional failing-case description) |
189fb67ca31a
Create Assert-eq, Assert-equal, etc.
Ben Wing <ben@xemacs.org>
parents:
4845
diff
changeset
|
323 "Test passes if TESTVAL is 'eql' to EXPECTED. |
189fb67ca31a
Create Assert-eq, Assert-equal, etc.
Ben Wing <ben@xemacs.org>
parents:
4845
diff
changeset
|
324 Optional FAILING-CASE describes the particular failure; any value given |
189fb67ca31a
Create Assert-eq, Assert-equal, etc.
Ben Wing <ben@xemacs.org>
parents:
4845
diff
changeset
|
325 here will be concatenated with a phrase describing the expected and actual |
189fb67ca31a
Create Assert-eq, Assert-equal, etc.
Ben Wing <ben@xemacs.org>
parents:
4845
diff
changeset
|
326 values of the comparison. Optional DESCRIPTION describes the assertion; by |
189fb67ca31a
Create Assert-eq, Assert-equal, etc.
Ben Wing <ben@xemacs.org>
parents:
4845
diff
changeset
|
327 default, the unevalated comparison expressions are given. FAILING-CASE and |
189fb67ca31a
Create Assert-eq, Assert-equal, etc.
Ben Wing <ben@xemacs.org>
parents:
4845
diff
changeset
|
328 DESCRIPTION are useful when Assert is used in a loop." |
189fb67ca31a
Create Assert-eq, Assert-equal, etc.
Ben Wing <ben@xemacs.org>
parents:
4845
diff
changeset
|
329 `(Assert-test eql ,testval ,expected ,failing-case ,description)) |
189fb67ca31a
Create Assert-eq, Assert-equal, etc.
Ben Wing <ben@xemacs.org>
parents:
4845
diff
changeset
|
330 |
189fb67ca31a
Create Assert-eq, Assert-equal, etc.
Ben Wing <ben@xemacs.org>
parents:
4845
diff
changeset
|
331 (defmacro Assert-equal (testval expected &optional failing-case |
189fb67ca31a
Create Assert-eq, Assert-equal, etc.
Ben Wing <ben@xemacs.org>
parents:
4845
diff
changeset
|
332 description) |
189fb67ca31a
Create Assert-eq, Assert-equal, etc.
Ben Wing <ben@xemacs.org>
parents:
4845
diff
changeset
|
333 "Test passes if TESTVAL is 'equal' to EXPECTED. |
189fb67ca31a
Create Assert-eq, Assert-equal, etc.
Ben Wing <ben@xemacs.org>
parents:
4845
diff
changeset
|
334 Optional FAILING-CASE describes the particular failure; any value given |
189fb67ca31a
Create Assert-eq, Assert-equal, etc.
Ben Wing <ben@xemacs.org>
parents:
4845
diff
changeset
|
335 here will be concatenated with a phrase describing the expected and actual |
189fb67ca31a
Create Assert-eq, Assert-equal, etc.
Ben Wing <ben@xemacs.org>
parents:
4845
diff
changeset
|
336 values of the comparison. Optional DESCRIPTION describes the assertion; by |
189fb67ca31a
Create Assert-eq, Assert-equal, etc.
Ben Wing <ben@xemacs.org>
parents:
4845
diff
changeset
|
337 default, the unevalated comparison expressions are given. FAILING-CASE and |
189fb67ca31a
Create Assert-eq, Assert-equal, etc.
Ben Wing <ben@xemacs.org>
parents:
4845
diff
changeset
|
338 DESCRIPTION are useful when Assert is used in a loop." |
189fb67ca31a
Create Assert-eq, Assert-equal, etc.
Ben Wing <ben@xemacs.org>
parents:
4845
diff
changeset
|
339 `(Assert-test equal ,testval ,expected ,failing-case ,description)) |
189fb67ca31a
Create Assert-eq, Assert-equal, etc.
Ben Wing <ben@xemacs.org>
parents:
4845
diff
changeset
|
340 |
189fb67ca31a
Create Assert-eq, Assert-equal, etc.
Ben Wing <ben@xemacs.org>
parents:
4845
diff
changeset
|
341 (defmacro Assert-equalp (testval expected &optional failing-case |
189fb67ca31a
Create Assert-eq, Assert-equal, etc.
Ben Wing <ben@xemacs.org>
parents:
4845
diff
changeset
|
342 description) |
189fb67ca31a
Create Assert-eq, Assert-equal, etc.
Ben Wing <ben@xemacs.org>
parents:
4845
diff
changeset
|
343 "Test passes if TESTVAL is 'equalp' to EXPECTED. |
189fb67ca31a
Create Assert-eq, Assert-equal, etc.
Ben Wing <ben@xemacs.org>
parents:
4845
diff
changeset
|
344 Optional FAILING-CASE describes the particular failure; any value given |
189fb67ca31a
Create Assert-eq, Assert-equal, etc.
Ben Wing <ben@xemacs.org>
parents:
4845
diff
changeset
|
345 here will be concatenated with a phrase describing the expected and actual |
189fb67ca31a
Create Assert-eq, Assert-equal, etc.
Ben Wing <ben@xemacs.org>
parents:
4845
diff
changeset
|
346 values of the comparison. Optional DESCRIPTION describes the assertion; by |
189fb67ca31a
Create Assert-eq, Assert-equal, etc.
Ben Wing <ben@xemacs.org>
parents:
4845
diff
changeset
|
347 default, the unevalated comparison expressions are given. FAILING-CASE and |
189fb67ca31a
Create Assert-eq, Assert-equal, etc.
Ben Wing <ben@xemacs.org>
parents:
4845
diff
changeset
|
348 DESCRIPTION are useful when Assert is used in a loop." |
189fb67ca31a
Create Assert-eq, Assert-equal, etc.
Ben Wing <ben@xemacs.org>
parents:
4845
diff
changeset
|
349 `(Assert-test equalp ,testval ,expected ,failing-case ,description)) |
189fb67ca31a
Create Assert-eq, Assert-equal, etc.
Ben Wing <ben@xemacs.org>
parents:
4845
diff
changeset
|
350 |
189fb67ca31a
Create Assert-eq, Assert-equal, etc.
Ben Wing <ben@xemacs.org>
parents:
4845
diff
changeset
|
351 (defmacro Assert-string= (testval expected &optional failing-case |
189fb67ca31a
Create Assert-eq, Assert-equal, etc.
Ben Wing <ben@xemacs.org>
parents:
4845
diff
changeset
|
352 description) |
189fb67ca31a
Create Assert-eq, Assert-equal, etc.
Ben Wing <ben@xemacs.org>
parents:
4845
diff
changeset
|
353 "Test passes if TESTVAL is 'string=' to EXPECTED. |
189fb67ca31a
Create Assert-eq, Assert-equal, etc.
Ben Wing <ben@xemacs.org>
parents:
4845
diff
changeset
|
354 Optional FAILING-CASE describes the particular failure; any value given |
189fb67ca31a
Create Assert-eq, Assert-equal, etc.
Ben Wing <ben@xemacs.org>
parents:
4845
diff
changeset
|
355 here will be concatenated with a phrase describing the expected and actual |
189fb67ca31a
Create Assert-eq, Assert-equal, etc.
Ben Wing <ben@xemacs.org>
parents:
4845
diff
changeset
|
356 values of the comparison. Optional DESCRIPTION describes the assertion; by |
189fb67ca31a
Create Assert-eq, Assert-equal, etc.
Ben Wing <ben@xemacs.org>
parents:
4845
diff
changeset
|
357 default, the unevalated comparison expressions are given. FAILING-CASE and |
189fb67ca31a
Create Assert-eq, Assert-equal, etc.
Ben Wing <ben@xemacs.org>
parents:
4845
diff
changeset
|
358 DESCRIPTION are useful when Assert is used in a loop." |
189fb67ca31a
Create Assert-eq, Assert-equal, etc.
Ben Wing <ben@xemacs.org>
parents:
4845
diff
changeset
|
359 `(Assert-test string= ,testval ,expected ,failing-case ,description)) |
189fb67ca31a
Create Assert-eq, Assert-equal, etc.
Ben Wing <ben@xemacs.org>
parents:
4845
diff
changeset
|
360 |
189fb67ca31a
Create Assert-eq, Assert-equal, etc.
Ben Wing <ben@xemacs.org>
parents:
4845
diff
changeset
|
361 (defmacro Assert= (testval expected &optional failing-case description) |
189fb67ca31a
Create Assert-eq, Assert-equal, etc.
Ben Wing <ben@xemacs.org>
parents:
4845
diff
changeset
|
362 "Test passes if TESTVAL is '=' to EXPECTED. |
189fb67ca31a
Create Assert-eq, Assert-equal, etc.
Ben Wing <ben@xemacs.org>
parents:
4845
diff
changeset
|
363 Optional FAILING-CASE describes the particular failure; any value given |
189fb67ca31a
Create Assert-eq, Assert-equal, etc.
Ben Wing <ben@xemacs.org>
parents:
4845
diff
changeset
|
364 here will be concatenated with a phrase describing the expected and actual |
189fb67ca31a
Create Assert-eq, Assert-equal, etc.
Ben Wing <ben@xemacs.org>
parents:
4845
diff
changeset
|
365 values of the comparison. Optional DESCRIPTION describes the assertion; by |
189fb67ca31a
Create Assert-eq, Assert-equal, etc.
Ben Wing <ben@xemacs.org>
parents:
4845
diff
changeset
|
366 default, the unevalated comparison expressions are given. FAILING-CASE and |
189fb67ca31a
Create Assert-eq, Assert-equal, etc.
Ben Wing <ben@xemacs.org>
parents:
4845
diff
changeset
|
367 DESCRIPTION are useful when Assert is used in a loop." |
189fb67ca31a
Create Assert-eq, Assert-equal, etc.
Ben Wing <ben@xemacs.org>
parents:
4845
diff
changeset
|
368 `(Assert-test = ,testval ,expected ,failing-case ,description)) |
189fb67ca31a
Create Assert-eq, Assert-equal, etc.
Ben Wing <ben@xemacs.org>
parents:
4845
diff
changeset
|
369 |
189fb67ca31a
Create Assert-eq, Assert-equal, etc.
Ben Wing <ben@xemacs.org>
parents:
4845
diff
changeset
|
370 (defmacro Assert<= (testval expected &optional failing-case description) |
189fb67ca31a
Create Assert-eq, Assert-equal, etc.
Ben Wing <ben@xemacs.org>
parents:
4845
diff
changeset
|
371 "Test passes if TESTVAL is '<=' to EXPECTED. |
189fb67ca31a
Create Assert-eq, Assert-equal, etc.
Ben Wing <ben@xemacs.org>
parents:
4845
diff
changeset
|
372 Optional FAILING-CASE describes the particular failure; any value given |
189fb67ca31a
Create Assert-eq, Assert-equal, etc.
Ben Wing <ben@xemacs.org>
parents:
4845
diff
changeset
|
373 here will be concatenated with a phrase describing the expected and actual |
189fb67ca31a
Create Assert-eq, Assert-equal, etc.
Ben Wing <ben@xemacs.org>
parents:
4845
diff
changeset
|
374 values of the comparison. Optional DESCRIPTION describes the assertion; by |
189fb67ca31a
Create Assert-eq, Assert-equal, etc.
Ben Wing <ben@xemacs.org>
parents:
4845
diff
changeset
|
375 default, the unevalated comparison expressions are given. FAILING-CASE and |
189fb67ca31a
Create Assert-eq, Assert-equal, etc.
Ben Wing <ben@xemacs.org>
parents:
4845
diff
changeset
|
376 DESCRIPTION are useful when Assert is used in a loop." |
189fb67ca31a
Create Assert-eq, Assert-equal, etc.
Ben Wing <ben@xemacs.org>
parents:
4845
diff
changeset
|
377 `(Assert-test <= ,testval ,expected ,failing-case ,description)) |
428 | 378 |
379 (defmacro Check-Error (expected-error &rest body) | |
380 (let ((quoted-body (if (= 1 (length body)) | |
381 `(quote ,(car body)) `(quote (progn ,@body))))) | |
382 `(condition-case error-info | |
383 (progn | |
384 (setq trick-optimizer (progn ,@body)) | |
826 | 385 (Print-Failure "%S executed successfully, but expected error %S" |
428 | 386 ,quoted-body |
826 | 387 ',expected-error) |
428 | 388 (incf no-error-failures)) |
389 (,expected-error | |
826 | 390 (Print-Pass "%S ==> error %S, as expected" |
391 ,quoted-body ',expected-error) | |
428 | 392 (incf passes)) |
393 (error | |
826 | 394 (Print-Failure "%S ==> expected error %S, got error %S instead" |
395 ,quoted-body ',expected-error error-info) | |
428 | 396 (incf wrong-error-failures))))) |
397 | |
826 | 398 (defmacro Check-Error-Message (expected-error expected-error-regexp |
399 &rest body) | |
428 | 400 (let ((quoted-body (if (= 1 (length body)) |
401 `(quote ,(car body)) `(quote (progn ,@body))))) | |
402 `(condition-case error-info | |
403 (progn | |
404 (setq trick-optimizer (progn ,@body)) | |
826 | 405 (Print-Failure "%S executed successfully, but expected error %S" |
406 ,quoted-body ',expected-error) | |
428 | 407 (incf no-error-failures)) |
408 (,expected-error | |
4199 | 409 ;; #### Damn, this binding doesn't capture frobs, eg, for |
410 ;; invalid_argument() ... you only get the REASON. And for | |
411 ;; wrong_type_argument(), there's no reason only FROBs. | |
412 ;; If this gets fixed, fix tests in regexp-tests.el. | |
428 | 413 (let ((error-message (second error-info))) |
414 (if (string-match ,expected-error-regexp error-message) | |
415 (progn | |
826 | 416 (Print-Pass "%S ==> error %S %S, as expected" |
417 ,quoted-body error-message ',expected-error) | |
428 | 418 (incf passes)) |
826 | 419 (Print-Failure "%S ==> got error %S as expected, but error message %S did not match regexp %S" |
420 ,quoted-body ',expected-error error-message ,expected-error-regexp) | |
428 | 421 (incf wrong-error-failures)))) |
422 (error | |
826 | 423 (Print-Failure "%S ==> expected error %S, got error %S instead" |
424 ,quoted-body ',expected-error error-info) | |
428 | 425 (incf wrong-error-failures))))) |
426 | |
3472 | 427 ;; Do not use this with Silence-Message. |
428 | 428 (defmacro Check-Message (expected-message-regexp &rest body) |
1095 | 429 (Skip-Test-Unless (fboundp 'defadvice) |
430 "can't defadvice" | |
431 expected-message-regexp | |
973 | 432 (let ((quoted-body (if (= 1 (length body)) |
433 `(quote ,(car body)) | |
434 `(quote (progn ,@body))))) | |
435 `(let ((messages "")) | |
436 (defadvice message (around collect activate) | |
437 (defvar messages) | |
438 (let ((msg-string (apply 'format (ad-get-args 0)))) | |
439 (setq messages (concat messages msg-string)) | |
440 msg-string)) | |
441 (condition-case error-info | |
442 (progn | |
443 (setq trick-optimizer (progn ,@body)) | |
444 (if (string-match ,expected-message-regexp messages) | |
445 (progn | |
446 (Print-Pass "%S ==> value %S, message %S, matching %S, as expected" | |
447 ,quoted-body trick-optimizer messages ',expected-message-regexp) | |
448 (incf passes)) | |
449 (Print-Failure "%S ==> value %S, message %S, NOT matching expected %S" | |
450 ,quoted-body trick-optimizer messages | |
451 ',expected-message-regexp) | |
452 (incf missing-message-failures))) | |
453 (error | |
454 (Print-Failure "%S ==> unexpected error %S" | |
455 ,quoted-body error-info) | |
456 (incf other-failures))) | |
457 (ad-unadvise 'message))))) | |
428 | 458 |
3472 | 459 ;; #### Perhaps this should override `message' itself, too? |
460 (defmacro Silence-Message (&rest body) | |
4323
94509abd0ef0
Commit a forgotten chunk of 4d0f773d5e21.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4199
diff
changeset
|
461 `(flet ((append-message (&rest args) ()) |
94509abd0ef0
Commit a forgotten chunk of 4d0f773d5e21.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4199
diff
changeset
|
462 (clear-message (&rest args) ())) |
94509abd0ef0
Commit a forgotten chunk of 4d0f773d5e21.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4199
diff
changeset
|
463 ,@body)) |
3472 | 464 |
428 | 465 (defmacro Ignore-Ebola (&rest body) |
466 `(let ((debug-issue-ebola-notices -42)) ,@body)) | |
467 | |
468 (defun Int-to-Marker (pos) | |
469 (save-excursion | |
470 (set-buffer standard-output) | |
471 (save-excursion | |
472 (goto-char pos) | |
473 (point-marker)))) | |
474 | |
475 (princ "Testing Interpreted Lisp\n\n") | |
476 (condition-case error-info | |
477 (funcall (test-harness-read-from-buffer inbuffer)) | |
478 (error | |
3471 | 479 (incf unexpected-test-file-failures) |
428 | 480 (princ (format "Unexpected error %S while executing interpreted code\n" |
481 error-info)) | |
482 (message "Unexpected error %S while executing interpreted code." error-info) | |
483 (message "Test suite execution aborted." error-info) | |
484 )) | |
485 (princ "\nTesting Compiled Lisp\n\n") | |
1758 | 486 (let (code |
487 (test-harness-test-compiled t)) | |
428 | 488 (condition-case error-info |
446 | 489 (setq code |
490 ;; our lisp code is often intentionally dubious, | |
491 ;; so throw away _all_ the byte compiler warnings. | |
492 (letf (((symbol-function 'byte-compile-warn) 'ignore)) | |
493 (byte-compile (test-harness-read-from-buffer inbuffer)))) | |
428 | 494 (error |
495 (princ (format "Unexpected error %S while byte-compiling code\n" | |
496 error-info)))) | |
497 (condition-case error-info | |
498 (if code (funcall code)) | |
499 (error | |
3471 | 500 (incf unexpected-test-file-failures) |
428 | 501 (princ (format "Unexpected error %S while executing byte-compiled code\n" |
502 error-info)) | |
503 (message "Unexpected error %S while executing byte-compiled code." error-info) | |
504 (message "Test suite execution aborted." error-info) | |
505 ))) | |
826 | 506 (princ (format "\nSUMMARY for %s:\n" filename)) |
428 | 507 (princ (format "\t%5d passes\n" passes)) |
508 (princ (format "\t%5d assertion failures\n" assertion-failures)) | |
509 (princ (format "\t%5d errors that should have been generated, but weren't\n" no-error-failures)) | |
510 (princ (format "\t%5d wrong-error failures\n" wrong-error-failures)) | |
511 (princ (format "\t%5d missing-message failures\n" missing-message-failures)) | |
512 (princ (format "\t%5d other failures\n" other-failures)) | |
513 (let* ((total (+ passes | |
514 assertion-failures | |
515 no-error-failures | |
516 wrong-error-failures | |
517 missing-message-failures | |
518 other-failures)) | |
519 (basename (file-name-nondirectory filename)) | |
520 (summary-msg | |
521 (if (> total 0) | |
1751 | 522 (format test-harness-file-summary-template |
523 (concat basename ":") | |
524 passes total (/ (* 100 passes) total)) | |
525 (format test-harness-null-summary-template | |
526 (concat basename ":")))) | |
973 | 527 (reasons "")) |
528 (maphash (lambda (key value) | |
529 (setq reasons | |
530 (concat reasons | |
1095 | 531 (format "\n %d tests skipped because %s." |
973 | 532 value key)))) |
533 skipped-test-reasons) | |
534 (when (> (length reasons) 1) | |
535 (setq summary-msg (concat summary-msg reasons " | |
4415
bceb3e285ae7
case-tests.el: fix it on non-DEBUG_XEMACS; save standard-case-table, use it
Aidan Kehoe <kehoea@parhasard.net>
parents:
4366
diff
changeset
|
536 It may be that XEmacs cannot find your installed packages. Set |
bceb3e285ae7
case-tests.el: fix it on non-DEBUG_XEMACS; save standard-case-table, use it
Aidan Kehoe <kehoea@parhasard.net>
parents:
4366
diff
changeset
|
537 EMACSPACKAGEPATH to the package hierarchy root or configure with |
bceb3e285ae7
case-tests.el: fix it on non-DEBUG_XEMACS; save standard-case-table, use it
Aidan Kehoe <kehoea@parhasard.net>
parents:
4366
diff
changeset
|
538 --package-path to enable the skipped tests."))) |
1719 | 539 (setq test-harness-file-results-alist |
540 (cons (list filename passes total) | |
541 test-harness-file-results-alist)) | |
428 | 542 (message "%s" summary-msg)) |
3471 | 543 (when (> unexpected-test-file-failures 0) |
544 (setq unexpected-test-suite-failure-files | |
545 (cons filename unexpected-test-suite-failure-files)) | |
546 (setq unexpected-test-suite-failures | |
547 (+ unexpected-test-suite-failures unexpected-test-file-failures)) | |
428 | 548 (message "Test suite execution failed unexpectedly.")) |
549 (fmakunbound 'Assert) | |
550 (fmakunbound 'Check-Error) | |
863 | 551 (fmakunbound 'Check-Message) |
552 (fmakunbound 'Check-Error-Message) | |
428 | 553 (fmakunbound 'Ignore-Ebola) |
554 (fmakunbound 'Int-to-Marker) | |
1719 | 555 (and noninteractive |
556 (message "%s" (buffer-substring-no-properties | |
1751 | 557 nil nil "*Test-Log*"))) |
558 ))) | |
428 | 559 |
560 (defvar test-harness-results-point-max nil) | |
561 (defmacro displaying-emacs-test-results (&rest body) | |
562 `(let ((test-harness-results-point-max test-harness-results-point-max)) | |
563 ;; Log the file name. | |
564 (test-harness-log-file) | |
565 ;; Record how much is logged now. | |
566 ;; We will display the log buffer if anything more is logged | |
567 ;; before the end of BODY. | |
568 (or test-harness-results-point-max | |
569 (save-excursion | |
570 (set-buffer (get-buffer-create "*Test-Log*")) | |
571 (setq test-harness-results-point-max (point-max)))) | |
572 (unwind-protect | |
573 (condition-case error-info | |
574 (progn ,@body) | |
575 (error | |
576 (test-harness-report-error error-info))) | |
577 (save-excursion | |
578 ;; If there were compilation warnings, display them. | |
579 (set-buffer "*Test-Log*") | |
580 (if (= test-harness-results-point-max (point-max)) | |
581 nil | |
582 (if temp-buffer-show-function | |
583 (let ((show-buffer (get-buffer-create "*Test-Log-Show*"))) | |
584 (save-excursion | |
585 (set-buffer show-buffer) | |
586 (setq buffer-read-only nil) | |
587 (erase-buffer)) | |
588 (copy-to-buffer show-buffer | |
589 (save-excursion | |
590 (goto-char test-harness-results-point-max) | |
591 (forward-line -1) | |
592 (point)) | |
593 (point-max)) | |
594 (funcall temp-buffer-show-function show-buffer)) | |
595 (select-window | |
596 (prog1 (selected-window) | |
597 (select-window (display-buffer (current-buffer))) | |
598 (goto-char test-harness-results-point-max) | |
599 (recenter 1))))))))) | |
600 | |
601 (defun batch-test-emacs-1 (file) | |
602 (condition-case error-info | |
603 (progn (test-emacs-test-file file) t) | |
604 (error | |
605 (princ ">>Error occurred processing ") | |
606 (princ file) | |
607 (princ ": ") | |
608 (display-error error-info nil) | |
609 (terpri) | |
610 nil))) | |
611 | |
612 (defun batch-test-emacs () | |
613 "Run `test-harness' on the files remaining on the command line. | |
614 Use this from the command line, with `-batch'; | |
615 it won't work in an interactive Emacs. | |
616 Each file is processed even if an error occurred previously. | |
617 For example, invoke \"xemacs -batch -f batch-test-emacs tests/*.el\"" | |
618 ;; command-line-args-left is what is left of the command line (from | |
619 ;; startup.el) | |
620 (defvar command-line-args-left) ;Avoid 'free variable' warning | |
621 (defvar debug-issue-ebola-notices) | |
622 (if (not noninteractive) | |
623 (error "`batch-test-emacs' is to be used only with -batch")) | |
624 (let ((error nil)) | |
625 (dolist (file command-line-args-left) | |
626 (if (file-directory-p file) | |
627 (dolist (file-in-dir (directory-files file t)) | |
628 (when (and (string-match emacs-lisp-file-regexp file-in-dir) | |
629 (not (or (auto-save-file-name-p file-in-dir) | |
630 (backup-file-name-p file-in-dir) | |
631 (equal (file-name-nondirectory file-in-dir) | |
632 "test-harness.el")))) | |
633 (or (batch-test-emacs-1 file-in-dir) | |
634 (setq error t)))) | |
635 (or (batch-test-emacs-1 file) | |
636 (setq error t)))) | |
1719 | 637 (let ((namelen 0) |
638 (succlen 0) | |
639 (testlen 0) | |
640 (results test-harness-file-results-alist)) | |
641 ;; compute maximum lengths of variable components of report | |
642 ;; probably should just use (length "byte-compiler-tests.el") | |
643 ;; and 5-place sizes -- this will also work for the file-by-file | |
644 ;; printing when Adrian's kludge gets reverted | |
645 (flet ((print-width (i) | |
646 (let ((x 10) (y 1)) | |
647 (while (>= i x) | |
648 (setq x (* 10 x) y (1+ y))) | |
649 y))) | |
650 (while results | |
651 (let* ((head (car results)) | |
652 (nn (length (file-name-nondirectory (first head)))) | |
653 (ss (print-width (second head))) | |
654 (tt (print-width (third head)))) | |
655 (when (> nn namelen) (setq namelen nn)) | |
656 (when (> ss succlen) (setq succlen ss)) | |
657 (when (> tt testlen) (setq testlen tt))) | |
658 (setq results (cdr results)))) | |
659 ;; create format and print | |
1751 | 660 (let ((results (reverse test-harness-file-results-alist))) |
1719 | 661 (while results |
662 (let* ((head (car results)) | |
1751 | 663 (basename (file-name-nondirectory (first head))) |
1719 | 664 (nsucc (second head)) |
665 (ntest (third head))) | |
1722 | 666 (if (> ntest 0) |
1751 | 667 (message test-harness-file-summary-template |
668 (concat basename ":") | |
1722 | 669 nsucc |
670 ntest | |
671 (/ (* 100 nsucc) ntest)) | |
1751 | 672 (message test-harness-null-summary-template |
673 (concat basename ":"))) | |
3471 | 674 (setq results (cdr results))))) |
675 (when (> unexpected-test-suite-failures 0) | |
676 (message "\n***** There %s %d unexpected test suite %s in %s:" | |
677 (if (= unexpected-test-suite-failures 1) "was" "were") | |
678 unexpected-test-suite-failures | |
679 (if (= unexpected-test-suite-failures 1) "failure" "failures") | |
680 (if (= (length unexpected-test-suite-failure-files) 1) | |
681 "file" | |
682 "files")) | |
683 (while unexpected-test-suite-failure-files | |
684 (let ((line (pop unexpected-test-suite-failure-files))) | |
685 (while (and (< (length line) 61) | |
686 unexpected-test-suite-failure-files) | |
687 (setq line | |
688 (concat line " " | |
689 (pop unexpected-test-suite-failure-files)))) | |
690 (message line))))) | |
1719 | 691 (message "\nDone") |
428 | 692 (kill-emacs (if error 1 0)))) |
693 | |
694 (provide 'test-harness) | |
695 | |
696 ;;; test-harness.el ends here |