Mercurial > hg > xemacs-beta
annotate lisp/test-harness.el @ 5451:10cd76b594a5
License comment terminated.
author | Mats Lidell <matsl@xemacs.org> |
---|---|
date | Fri, 07 Jan 2011 23:31:56 +0100 |
parents | 308d34e9f07d |
children | ac37a5f7e5be |
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 | |
5402
308d34e9f07d
Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents:
5274
diff
changeset
|
12 ;; XEmacs is free software: you can redistribute it and/or modify it |
308d34e9f07d
Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents:
5274
diff
changeset
|
13 ;; under the terms of the GNU General Public License as published by the |
308d34e9f07d
Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents:
5274
diff
changeset
|
14 ;; Free Software Foundation, either version 3 of the License, or (at your |
308d34e9f07d
Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents:
5274
diff
changeset
|
15 ;; option) any later version. |
428 | 16 |
5402
308d34e9f07d
Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents:
5274
diff
changeset
|
17 ;; XEmacs is distributed in the hope that it will be useful, but WITHOUT |
308d34e9f07d
Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents:
5274
diff
changeset
|
18 ;; ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
308d34e9f07d
Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents:
5274
diff
changeset
|
19 ;; FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
308d34e9f07d
Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents:
5274
diff
changeset
|
20 ;; for more details. |
428 | 21 |
22 ;; You should have received a copy of the GNU General Public License | |
5402
308d34e9f07d
Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents:
5274
diff
changeset
|
23 ;; along with XEmacs. If not, see <http://www.gnu.org/licenses/>. |
428 | 24 |
25 ;;; Synched up with: Not in FSF. | |
26 | |
27 ;;; Commentary: | |
28 | |
29 ;;; A test suite harness for testing XEmacs. | |
30 ;;; The actual tests are in other files in this directory. | |
31 ;;; Basically you just create files of emacs-lisp, and use the | |
1095 | 32 ;;; Assert, Check-Error, Check-Message, and Check-Error-Message functions |
33 ;;; to create tests. See `test-harness-from-buffer' below. | |
34 ;;; Don't suppress tests just because they're due to known bugs not yet | |
1413 | 35 ;;; fixed -- use the Known-Bug-Expect-Failure and |
36 ;;; Implementation-Incomplete-Expect-Failure wrapper macros to mark them. | |
1095 | 37 ;;; A lot of the tests we run push limits; suppress Ebola message with the |
38 ;;; Ignore-Ebola wrapper macro. | |
3472 | 39 ;;; Some noisy code will call `message'. Output from `message' can be |
40 ;;; suppressed with the Silence-Message macro. Functions that are known to | |
41 ;;; issue messages include `write-region', `find-tag', `tag-loop-continue', | |
42 ;;; `insert', and `mark-whole-buffer'. N.B. The Silence-Message macro | |
43 ;;; currently does not suppress the newlines printed by `message'. | |
44 ;;; Definitely do not use Silence-Message with Check-Message. | |
45 ;;; In general it should probably only be used on code that prepares for a | |
46 ;;; test, not on tests. | |
1095 | 47 ;;; |
428 | 48 ;;; You run the tests using M-x test-emacs-test-file, |
5069
14f0dd1fabdb
move test-harness to lisp/ directory so it gets byte-compiled
Ben Wing <ben@xemacs.org>
parents:
5064
diff
changeset
|
49 ;;; or $(EMACS) -batch -l test-harness -f batch-test-emacs file ... |
428 | 50 ;;; which is run for you by the `make check' target in the top-level Makefile. |
51 | |
52 (require 'bytecomp) | |
53 | |
3471 | 54 (defvar unexpected-test-suite-failures 0 |
55 "Cumulative number of unexpected failures since test-harness was loaded. | |
56 | |
57 \"Unexpected failures\" are those caught by a generic handler established | |
58 outside of the test context. As such they involve an abort of the test | |
59 suite for the file being tested. | |
60 | |
61 They often occur during preparation of a test or recording of the results. | |
62 For example, an executable used to generate test data might not be present | |
63 on the system, or a system error might occur while reading a data file.") | |
64 | |
65 (defvar unexpected-test-suite-failure-files nil | |
66 "List of test files causing unexpected failures.") | |
67 | |
68 ;; Declared for dynamic scope; _do not_ initialize here. | |
69 (defvar unexpected-test-file-failures) | |
70 | |
5040
3daf9fc57cd4
fixes to test harness to allow backtracing/debugging of failures
Ben Wing <ben@xemacs.org>
parents:
4962
diff
changeset
|
71 (defvar test-harness-bug-expected nil |
3daf9fc57cd4
fixes to test harness to allow backtracing/debugging of failures
Ben Wing <ben@xemacs.org>
parents:
4962
diff
changeset
|
72 "Non-nil means a bug is expected; backtracing/debugging should not happen.") |
3daf9fc57cd4
fixes to test harness to allow backtracing/debugging of failures
Ben Wing <ben@xemacs.org>
parents:
4962
diff
changeset
|
73 |
1758 | 74 (defvar test-harness-test-compiled nil |
4366
7b628daa39d4
Move debugging code to usage example.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4323
diff
changeset
|
75 "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
|
76 |
7b628daa39d4
Move debugging code to usage example.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4323
diff
changeset
|
77 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
|
78 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
|
79 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
|
80 implementation of this variable: |
7b628daa39d4
Move debugging code to usage example.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4323
diff
changeset
|
81 |
7b628daa39d4
Move debugging code to usage example.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4323
diff
changeset
|
82 \(when test-harness-test-compiled |
7b628daa39d4
Move debugging code to usage example.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4323
diff
changeset
|
83 ;; 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
|
84 \(setq test-harness-failure-tag |
7b628daa39d4
Move debugging code to usage example.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4323
diff
changeset
|
85 \"KNOWN BUG - fix reverted; after 2003-10-31 notify stephen\n\"))") |
1758 | 86 |
428 | 87 (defvar test-harness-verbose |
88 (and (not noninteractive) (> (device-baud-rate) search-slow-speed)) | |
89 "*Non-nil means print messages describing progress of emacs-tester.") | |
90 | |
5040
3daf9fc57cd4
fixes to test harness to allow backtracing/debugging of failures
Ben Wing <ben@xemacs.org>
parents:
4962
diff
changeset
|
91 (defvar test-harness-unexpected-error-enter-debugger debug-on-error |
3daf9fc57cd4
fixes to test harness to allow backtracing/debugging of failures
Ben Wing <ben@xemacs.org>
parents:
4962
diff
changeset
|
92 "*Non-nil means enter debugger when an unexpected error occurs. |
3daf9fc57cd4
fixes to test harness to allow backtracing/debugging of failures
Ben Wing <ben@xemacs.org>
parents:
4962
diff
changeset
|
93 Only applies interactively. Normally true if `debug-on-error' has been set. |
3daf9fc57cd4
fixes to test harness to allow backtracing/debugging of failures
Ben Wing <ben@xemacs.org>
parents:
4962
diff
changeset
|
94 See also `test-harness-assertion-failure-enter-debugger' and |
3daf9fc57cd4
fixes to test harness to allow backtracing/debugging of failures
Ben Wing <ben@xemacs.org>
parents:
4962
diff
changeset
|
95 `test-harness-unexpected-error-show-backtrace'.") |
3daf9fc57cd4
fixes to test harness to allow backtracing/debugging of failures
Ben Wing <ben@xemacs.org>
parents:
4962
diff
changeset
|
96 |
3daf9fc57cd4
fixes to test harness to allow backtracing/debugging of failures
Ben Wing <ben@xemacs.org>
parents:
4962
diff
changeset
|
97 (defvar test-harness-assertion-failure-enter-debugger debug-on-error |
3daf9fc57cd4
fixes to test harness to allow backtracing/debugging of failures
Ben Wing <ben@xemacs.org>
parents:
4962
diff
changeset
|
98 "*Non-nil means enter debugger when an assertion failure occurs. |
3daf9fc57cd4
fixes to test harness to allow backtracing/debugging of failures
Ben Wing <ben@xemacs.org>
parents:
4962
diff
changeset
|
99 Only applies interactively. Normally true if `debug-on-error' has been set. |
3daf9fc57cd4
fixes to test harness to allow backtracing/debugging of failures
Ben Wing <ben@xemacs.org>
parents:
4962
diff
changeset
|
100 See also `test-harness-unexpected-error-enter-debugger' and |
3daf9fc57cd4
fixes to test harness to allow backtracing/debugging of failures
Ben Wing <ben@xemacs.org>
parents:
4962
diff
changeset
|
101 `test-harness-assertion-failure-show-backtrace'.") |
3daf9fc57cd4
fixes to test harness to allow backtracing/debugging of failures
Ben Wing <ben@xemacs.org>
parents:
4962
diff
changeset
|
102 |
3daf9fc57cd4
fixes to test harness to allow backtracing/debugging of failures
Ben Wing <ben@xemacs.org>
parents:
4962
diff
changeset
|
103 (defvar test-harness-unexpected-error-show-backtrace t |
3daf9fc57cd4
fixes to test harness to allow backtracing/debugging of failures
Ben Wing <ben@xemacs.org>
parents:
4962
diff
changeset
|
104 "*Non-nil means show backtrace upon unexpected error. |
3daf9fc57cd4
fixes to test harness to allow backtracing/debugging of failures
Ben Wing <ben@xemacs.org>
parents:
4962
diff
changeset
|
105 Only applies when debugger is not entered. Normally true by default. See also |
3daf9fc57cd4
fixes to test harness to allow backtracing/debugging of failures
Ben Wing <ben@xemacs.org>
parents:
4962
diff
changeset
|
106 `test-harness-unexpected-error-enter-debugger' and |
3daf9fc57cd4
fixes to test harness to allow backtracing/debugging of failures
Ben Wing <ben@xemacs.org>
parents:
4962
diff
changeset
|
107 `test-harness-assertion-failure-show-backtrace'.") |
3daf9fc57cd4
fixes to test harness to allow backtracing/debugging of failures
Ben Wing <ben@xemacs.org>
parents:
4962
diff
changeset
|
108 |
3daf9fc57cd4
fixes to test harness to allow backtracing/debugging of failures
Ben Wing <ben@xemacs.org>
parents:
4962
diff
changeset
|
109 (defvar test-harness-assertion-failure-show-backtrace stack-trace-on-error |
3daf9fc57cd4
fixes to test harness to allow backtracing/debugging of failures
Ben Wing <ben@xemacs.org>
parents:
4962
diff
changeset
|
110 "*Non-nil means show backtrace upon assertion failure. |
3daf9fc57cd4
fixes to test harness to allow backtracing/debugging of failures
Ben Wing <ben@xemacs.org>
parents:
4962
diff
changeset
|
111 Only applies when debugger is not entered. Normally true if |
3daf9fc57cd4
fixes to test harness to allow backtracing/debugging of failures
Ben Wing <ben@xemacs.org>
parents:
4962
diff
changeset
|
112 `stack-trace-on-error' has been set. See also |
3daf9fc57cd4
fixes to test harness to allow backtracing/debugging of failures
Ben Wing <ben@xemacs.org>
parents:
4962
diff
changeset
|
113 `test-harness-assertion-failure-enter-debugger' and |
3daf9fc57cd4
fixes to test harness to allow backtracing/debugging of failures
Ben Wing <ben@xemacs.org>
parents:
4962
diff
changeset
|
114 `test-harness-unexpected-error-show-backtrace'.") |
3daf9fc57cd4
fixes to test harness to allow backtracing/debugging of failures
Ben Wing <ben@xemacs.org>
parents:
4962
diff
changeset
|
115 |
1719 | 116 (defvar test-harness-file-results-alist nil |
117 "Each element is a list (FILE SUCCESSES TESTS). | |
118 The order is the reverse of the order in which tests are run. | |
119 | |
120 FILE is a string naming the test file. | |
121 SUCCESSES is a non-negative integer, the number of successes. | |
122 TESTS is a non-negative integer, the number of tests run.") | |
123 | |
1425 | 124 (defvar test-harness-risk-infloops nil |
125 "*Non-nil to run tests that may loop infinitely in buggy implementations.") | |
126 | |
428 | 127 (defvar test-harness-current-file nil) |
128 | |
129 (defvar emacs-lisp-file-regexp (purecopy "\\.el\\'") | |
130 "*Regexp which matches Emacs Lisp source files.") | |
131 | |
1751 | 132 (defconst test-harness-file-summary-template |
133 (format "%%-%ds %%%dd of %%%dd tests successful (%%3d%%%%)." | |
134 (length "byte-compiler-tests.el:") ; use the longest file name | |
135 5 | |
136 5) | |
137 "Format for summary lines printed after each file is run.") | |
138 | |
139 (defconst test-harness-null-summary-template | |
140 (format "%%-%ds No tests run." | |
141 (length "byte-compiler-tests.el:")) ; use the longest file name | |
142 "Format for \"No tests\" lines printed after a file is run.") | |
143 | |
4906
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4891
diff
changeset
|
144 (defconst test-harness-aborted-summary-template |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4891
diff
changeset
|
145 (format "%%-%ds %%%dd tests completed (aborted)." |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4891
diff
changeset
|
146 (length "byte-compiler-tests.el:") ; use the longest file name |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4891
diff
changeset
|
147 5) |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4891
diff
changeset
|
148 "Format for summary lines printed after a test run on a file was aborted.") |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4891
diff
changeset
|
149 |
428 | 150 ;;;###autoload |
151 (defun test-emacs-test-file (filename) | |
152 "Test a file of Lisp code named FILENAME. | |
153 The output file's name is made by appending `c' to the end of FILENAME." | |
154 (interactive | |
155 (let ((file buffer-file-name) | |
156 (file-name nil) | |
157 (file-dir nil)) | |
158 (and file | |
159 (eq (cdr (assq 'major-mode (buffer-local-variables))) | |
160 'emacs-lisp-mode) | |
161 (setq file-name (file-name-nondirectory file) | |
162 file-dir (file-name-directory file))) | |
163 (list (read-file-name "Test file: " file-dir nil nil file-name)))) | |
164 ;; Expand now so we get the current buffer's defaults | |
165 (setq filename (expand-file-name filename)) | |
166 | |
167 ;; If we're testing a file that's in a buffer and is modified, offer | |
168 ;; to save it first. | |
169 (or noninteractive | |
170 (let ((b (get-file-buffer (expand-file-name filename)))) | |
171 (if (and b (buffer-modified-p b) | |
172 (y-or-n-p (format "save buffer %s first? " (buffer-name b)))) | |
173 (save-excursion (set-buffer b) (save-buffer))))) | |
174 | |
175 (if (or noninteractive test-harness-verbose) | |
176 (message "Testing %s..." filename)) | |
177 (let ((test-harness-current-file filename) | |
178 input-buffer) | |
179 (save-excursion | |
180 (setq input-buffer (get-buffer-create " *Test Input*")) | |
181 (set-buffer input-buffer) | |
182 (erase-buffer) | |
183 (insert-file-contents filename) | |
184 ;; Run hooks including the uncompression hook. | |
185 ;; If they change the file name, then change it for the output also. | |
186 (let ((buffer-file-name filename) | |
187 (default-major-mode 'emacs-lisp-mode) | |
188 (enable-local-eval nil)) | |
189 (normal-mode) | |
190 (setq filename buffer-file-name))) | |
191 (test-harness-from-buffer input-buffer filename) | |
192 (kill-buffer input-buffer) | |
193 )) | |
194 | |
5110 | 195 (defsubst test-harness-backtrace () |
196 "Display a reasonable-size backtrace." | |
197 (let ((print-escape-newlines t) | |
198 (print-length 50)) | |
199 (backtrace nil t))) | |
200 | |
5040
3daf9fc57cd4
fixes to test harness to allow backtracing/debugging of failures
Ben Wing <ben@xemacs.org>
parents:
4962
diff
changeset
|
201 (defsubst test-harness-assertion-failure-do-debug (error-info) |
3daf9fc57cd4
fixes to test harness to allow backtracing/debugging of failures
Ben Wing <ben@xemacs.org>
parents:
4962
diff
changeset
|
202 "Maybe enter debugger or display a backtrace on assertion failure. |
3daf9fc57cd4
fixes to test harness to allow backtracing/debugging of failures
Ben Wing <ben@xemacs.org>
parents:
4962
diff
changeset
|
203 ERROR-INFO is a cons of the args (SIG . DATA) that were passed to `signal'. |
3daf9fc57cd4
fixes to test harness to allow backtracing/debugging of failures
Ben Wing <ben@xemacs.org>
parents:
4962
diff
changeset
|
204 The debugger will be entered if noninteractive and |
3daf9fc57cd4
fixes to test harness to allow backtracing/debugging of failures
Ben Wing <ben@xemacs.org>
parents:
4962
diff
changeset
|
205 `test-harness-unexpected-error-enter-debugger' is non-nil; else, a |
3daf9fc57cd4
fixes to test harness to allow backtracing/debugging of failures
Ben Wing <ben@xemacs.org>
parents:
4962
diff
changeset
|
206 backtrace will be displayed if `test-harness-unexpected-error-show-backtrace' |
3daf9fc57cd4
fixes to test harness to allow backtracing/debugging of failures
Ben Wing <ben@xemacs.org>
parents:
4962
diff
changeset
|
207 is non-nil." |
3daf9fc57cd4
fixes to test harness to allow backtracing/debugging of failures
Ben Wing <ben@xemacs.org>
parents:
4962
diff
changeset
|
208 (when (not test-harness-bug-expected) |
3daf9fc57cd4
fixes to test harness to allow backtracing/debugging of failures
Ben Wing <ben@xemacs.org>
parents:
4962
diff
changeset
|
209 (cond ((and (not noninteractive) |
3daf9fc57cd4
fixes to test harness to allow backtracing/debugging of failures
Ben Wing <ben@xemacs.org>
parents:
4962
diff
changeset
|
210 test-harness-assertion-failure-enter-debugger) |
3daf9fc57cd4
fixes to test harness to allow backtracing/debugging of failures
Ben Wing <ben@xemacs.org>
parents:
4962
diff
changeset
|
211 (funcall debugger 'error error-info)) |
3daf9fc57cd4
fixes to test harness to allow backtracing/debugging of failures
Ben Wing <ben@xemacs.org>
parents:
4962
diff
changeset
|
212 (test-harness-assertion-failure-show-backtrace |
5110 | 213 (test-harness-backtrace))))) |
5040
3daf9fc57cd4
fixes to test harness to allow backtracing/debugging of failures
Ben Wing <ben@xemacs.org>
parents:
4962
diff
changeset
|
214 |
3daf9fc57cd4
fixes to test harness to allow backtracing/debugging of failures
Ben Wing <ben@xemacs.org>
parents:
4962
diff
changeset
|
215 (defsubst test-harness-unexpected-error-do-debug (error-info) |
3daf9fc57cd4
fixes to test harness to allow backtracing/debugging of failures
Ben Wing <ben@xemacs.org>
parents:
4962
diff
changeset
|
216 "Maybe enter debugger or display a backtrace on unexpected error. |
3daf9fc57cd4
fixes to test harness to allow backtracing/debugging of failures
Ben Wing <ben@xemacs.org>
parents:
4962
diff
changeset
|
217 ERROR-INFO is a cons of the args (SIG . DATA) that were passed to `signal'. |
3daf9fc57cd4
fixes to test harness to allow backtracing/debugging of failures
Ben Wing <ben@xemacs.org>
parents:
4962
diff
changeset
|
218 The debugger will be entered if noninteractive and |
3daf9fc57cd4
fixes to test harness to allow backtracing/debugging of failures
Ben Wing <ben@xemacs.org>
parents:
4962
diff
changeset
|
219 `test-harness-unexpected-error-enter-debugger' is non-nil; else, a |
3daf9fc57cd4
fixes to test harness to allow backtracing/debugging of failures
Ben Wing <ben@xemacs.org>
parents:
4962
diff
changeset
|
220 backtrace will be displayed if `test-harness-unexpected-error-show-backtrace' |
3daf9fc57cd4
fixes to test harness to allow backtracing/debugging of failures
Ben Wing <ben@xemacs.org>
parents:
4962
diff
changeset
|
221 is non-nil." |
3daf9fc57cd4
fixes to test harness to allow backtracing/debugging of failures
Ben Wing <ben@xemacs.org>
parents:
4962
diff
changeset
|
222 (when (not test-harness-bug-expected) |
3daf9fc57cd4
fixes to test harness to allow backtracing/debugging of failures
Ben Wing <ben@xemacs.org>
parents:
4962
diff
changeset
|
223 (cond ((and (not noninteractive) |
3daf9fc57cd4
fixes to test harness to allow backtracing/debugging of failures
Ben Wing <ben@xemacs.org>
parents:
4962
diff
changeset
|
224 test-harness-unexpected-error-enter-debugger) |
3daf9fc57cd4
fixes to test harness to allow backtracing/debugging of failures
Ben Wing <ben@xemacs.org>
parents:
4962
diff
changeset
|
225 (funcall debugger 'error error-info)) |
3daf9fc57cd4
fixes to test harness to allow backtracing/debugging of failures
Ben Wing <ben@xemacs.org>
parents:
4962
diff
changeset
|
226 (test-harness-unexpected-error-show-backtrace |
5110 | 227 (test-harness-backtrace))))) |
5040
3daf9fc57cd4
fixes to test harness to allow backtracing/debugging of failures
Ben Wing <ben@xemacs.org>
parents:
4962
diff
changeset
|
228 |
3daf9fc57cd4
fixes to test harness to allow backtracing/debugging of failures
Ben Wing <ben@xemacs.org>
parents:
4962
diff
changeset
|
229 (defsubst test-harness-unexpected-error-condition-handler (error-info context-msg) |
3daf9fc57cd4
fixes to test harness to allow backtracing/debugging of failures
Ben Wing <ben@xemacs.org>
parents:
4962
diff
changeset
|
230 "Condition handler for when unexpected errors occur. |
3daf9fc57cd4
fixes to test harness to allow backtracing/debugging of failures
Ben Wing <ben@xemacs.org>
parents:
4962
diff
changeset
|
231 Useful in conjunction with `call-with-condition-handler'. ERROR-INFO is the |
3daf9fc57cd4
fixes to test harness to allow backtracing/debugging of failures
Ben Wing <ben@xemacs.org>
parents:
4962
diff
changeset
|
232 value passed to the condition handler. CONTEXT-MSG is a string indicating |
3daf9fc57cd4
fixes to test harness to allow backtracing/debugging of failures
Ben Wing <ben@xemacs.org>
parents:
4962
diff
changeset
|
233 the context in which the unexpected error occurred. A message is outputted |
3daf9fc57cd4
fixes to test harness to allow backtracing/debugging of failures
Ben Wing <ben@xemacs.org>
parents:
4962
diff
changeset
|
234 including CONTEXT-MSG in it, `unexpected-test-file-failures' is incremented, |
3daf9fc57cd4
fixes to test harness to allow backtracing/debugging of failures
Ben Wing <ben@xemacs.org>
parents:
4962
diff
changeset
|
235 and `test-harness-unexpected-error-do-debug' is called, which may enter the |
3daf9fc57cd4
fixes to test harness to allow backtracing/debugging of failures
Ben Wing <ben@xemacs.org>
parents:
4962
diff
changeset
|
236 debugger or output a backtrace, depending on the settings of |
3daf9fc57cd4
fixes to test harness to allow backtracing/debugging of failures
Ben Wing <ben@xemacs.org>
parents:
4962
diff
changeset
|
237 `test-harness-unexpected-error-enter-debugger' and |
3daf9fc57cd4
fixes to test harness to allow backtracing/debugging of failures
Ben Wing <ben@xemacs.org>
parents:
4962
diff
changeset
|
238 `test-harness-unexpected-error-show-backtrace'. |
3daf9fc57cd4
fixes to test harness to allow backtracing/debugging of failures
Ben Wing <ben@xemacs.org>
parents:
4962
diff
changeset
|
239 |
3daf9fc57cd4
fixes to test harness to allow backtracing/debugging of failures
Ben Wing <ben@xemacs.org>
parents:
4962
diff
changeset
|
240 The function returns normally, which causes error-handling processing to |
3daf9fc57cd4
fixes to test harness to allow backtracing/debugging of failures
Ben Wing <ben@xemacs.org>
parents:
4962
diff
changeset
|
241 continue; if you want to catch the error, you also need to wrap everything |
3daf9fc57cd4
fixes to test harness to allow backtracing/debugging of failures
Ben Wing <ben@xemacs.org>
parents:
4962
diff
changeset
|
242 in `condition-case'. See also `test-harness-error-wrap', which does this |
3daf9fc57cd4
fixes to test harness to allow backtracing/debugging of failures
Ben Wing <ben@xemacs.org>
parents:
4962
diff
changeset
|
243 wrapping." |
3daf9fc57cd4
fixes to test harness to allow backtracing/debugging of failures
Ben Wing <ben@xemacs.org>
parents:
4962
diff
changeset
|
244 (incf unexpected-test-file-failures) |
3daf9fc57cd4
fixes to test harness to allow backtracing/debugging of failures
Ben Wing <ben@xemacs.org>
parents:
4962
diff
changeset
|
245 (princ (format "Unexpected error %S while %s\n" |
3daf9fc57cd4
fixes to test harness to allow backtracing/debugging of failures
Ben Wing <ben@xemacs.org>
parents:
4962
diff
changeset
|
246 error-info context-msg)) |
3daf9fc57cd4
fixes to test harness to allow backtracing/debugging of failures
Ben Wing <ben@xemacs.org>
parents:
4962
diff
changeset
|
247 (message "Unexpected error %S while %s." error-info context-msg) |
3daf9fc57cd4
fixes to test harness to allow backtracing/debugging of failures
Ben Wing <ben@xemacs.org>
parents:
4962
diff
changeset
|
248 (test-harness-unexpected-error-do-debug error-info)) |
3daf9fc57cd4
fixes to test harness to allow backtracing/debugging of failures
Ben Wing <ben@xemacs.org>
parents:
4962
diff
changeset
|
249 |
3daf9fc57cd4
fixes to test harness to allow backtracing/debugging of failures
Ben Wing <ben@xemacs.org>
parents:
4962
diff
changeset
|
250 (defmacro test-harness-error-wrap (context-msg abort-msg &rest body) |
3daf9fc57cd4
fixes to test harness to allow backtracing/debugging of failures
Ben Wing <ben@xemacs.org>
parents:
4962
diff
changeset
|
251 "Wrap BODY so that unexpected errors are caught. |
3daf9fc57cd4
fixes to test harness to allow backtracing/debugging of failures
Ben Wing <ben@xemacs.org>
parents:
4962
diff
changeset
|
252 The debugger will be entered if noninteractive and |
3daf9fc57cd4
fixes to test harness to allow backtracing/debugging of failures
Ben Wing <ben@xemacs.org>
parents:
4962
diff
changeset
|
253 `test-harness-unexpected-error-enter-debugger' is non-nil; else, a backtrace |
3daf9fc57cd4
fixes to test harness to allow backtracing/debugging of failures
Ben Wing <ben@xemacs.org>
parents:
4962
diff
changeset
|
254 will be displayed if `test-harness-unexpected-error-show-backtrace' is |
3daf9fc57cd4
fixes to test harness to allow backtracing/debugging of failures
Ben Wing <ben@xemacs.org>
parents:
4962
diff
changeset
|
255 non-nil. CONTEXT-MSG is displayed as part of a message shown before entering |
3daf9fc57cd4
fixes to test harness to allow backtracing/debugging of failures
Ben Wing <ben@xemacs.org>
parents:
4962
diff
changeset
|
256 the debugger or showing a backtrace, and ABORT-MSG, if non-nil, is displayed |
3daf9fc57cd4
fixes to test harness to allow backtracing/debugging of failures
Ben Wing <ben@xemacs.org>
parents:
4962
diff
changeset
|
257 afterwards. See " |
3daf9fc57cd4
fixes to test harness to allow backtracing/debugging of failures
Ben Wing <ben@xemacs.org>
parents:
4962
diff
changeset
|
258 `(condition-case nil |
3daf9fc57cd4
fixes to test harness to allow backtracing/debugging of failures
Ben Wing <ben@xemacs.org>
parents:
4962
diff
changeset
|
259 (call-with-condition-handler |
3daf9fc57cd4
fixes to test harness to allow backtracing/debugging of failures
Ben Wing <ben@xemacs.org>
parents:
4962
diff
changeset
|
260 #'(lambda (error-info) |
3daf9fc57cd4
fixes to test harness to allow backtracing/debugging of failures
Ben Wing <ben@xemacs.org>
parents:
4962
diff
changeset
|
261 (test-harness-unexpected-error-condition-handler |
3daf9fc57cd4
fixes to test harness to allow backtracing/debugging of failures
Ben Wing <ben@xemacs.org>
parents:
4962
diff
changeset
|
262 error-info ,context-msg)) |
3daf9fc57cd4
fixes to test harness to allow backtracing/debugging of failures
Ben Wing <ben@xemacs.org>
parents:
4962
diff
changeset
|
263 #'(lambda () |
3daf9fc57cd4
fixes to test harness to allow backtracing/debugging of failures
Ben Wing <ben@xemacs.org>
parents:
4962
diff
changeset
|
264 ,@body)) |
3daf9fc57cd4
fixes to test harness to allow backtracing/debugging of failures
Ben Wing <ben@xemacs.org>
parents:
4962
diff
changeset
|
265 (error ,(if abort-msg `(message ,abort-msg) nil)))) |
3daf9fc57cd4
fixes to test harness to allow backtracing/debugging of failures
Ben Wing <ben@xemacs.org>
parents:
4962
diff
changeset
|
266 |
428 | 267 (defun test-harness-read-from-buffer (buffer) |
268 "Read forms from BUFFER, and turn it into a lambda test form." | |
269 (let ((body nil)) | |
270 (goto-char (point-min) buffer) | |
5040
3daf9fc57cd4
fixes to test harness to allow backtracing/debugging of failures
Ben Wing <ben@xemacs.org>
parents:
4962
diff
changeset
|
271 (condition-case nil |
3daf9fc57cd4
fixes to test harness to allow backtracing/debugging of failures
Ben Wing <ben@xemacs.org>
parents:
4962
diff
changeset
|
272 (call-with-condition-handler |
3daf9fc57cd4
fixes to test harness to allow backtracing/debugging of failures
Ben Wing <ben@xemacs.org>
parents:
4962
diff
changeset
|
273 #'(lambda (error-info) |
3daf9fc57cd4
fixes to test harness to allow backtracing/debugging of failures
Ben Wing <ben@xemacs.org>
parents:
4962
diff
changeset
|
274 ;; end-of-file is expected, so don't output error or backtrace |
3daf9fc57cd4
fixes to test harness to allow backtracing/debugging of failures
Ben Wing <ben@xemacs.org>
parents:
4962
diff
changeset
|
275 ;; or enter debugger in this case. |
3daf9fc57cd4
fixes to test harness to allow backtracing/debugging of failures
Ben Wing <ben@xemacs.org>
parents:
4962
diff
changeset
|
276 (unless (eq 'end-of-file (car error-info)) |
3daf9fc57cd4
fixes to test harness to allow backtracing/debugging of failures
Ben Wing <ben@xemacs.org>
parents:
4962
diff
changeset
|
277 (test-harness-unexpected-error-condition-handler |
3daf9fc57cd4
fixes to test harness to allow backtracing/debugging of failures
Ben Wing <ben@xemacs.org>
parents:
4962
diff
changeset
|
278 error-info "reading forms from buffer"))) |
3daf9fc57cd4
fixes to test harness to allow backtracing/debugging of failures
Ben Wing <ben@xemacs.org>
parents:
4962
diff
changeset
|
279 #'(lambda () |
3daf9fc57cd4
fixes to test harness to allow backtracing/debugging of failures
Ben Wing <ben@xemacs.org>
parents:
4962
diff
changeset
|
280 (while t |
3daf9fc57cd4
fixes to test harness to allow backtracing/debugging of failures
Ben Wing <ben@xemacs.org>
parents:
4962
diff
changeset
|
281 (setq body (cons (read buffer) body))))) |
3daf9fc57cd4
fixes to test harness to allow backtracing/debugging of failures
Ben Wing <ben@xemacs.org>
parents:
4962
diff
changeset
|
282 (error nil)) |
428 | 283 `(lambda () |
284 (defvar passes) | |
285 (defvar assertion-failures) | |
286 (defvar no-error-failures) | |
287 (defvar wrong-error-failures) | |
288 (defvar missing-message-failures) | |
289 (defvar other-failures) | |
290 | |
291 (defvar trick-optimizer) | |
292 | |
293 ,@(nreverse body)))) | |
294 | |
295 (defun test-harness-from-buffer (inbuffer filename) | |
296 "Run tests in buffer INBUFFER, visiting FILENAME." | |
297 (defvar trick-optimizer) | |
298 (let ((passes 0) | |
299 (assertion-failures 0) | |
300 (no-error-failures 0) | |
301 (wrong-error-failures 0) | |
302 (missing-message-failures 0) | |
303 (other-failures 0) | |
3471 | 304 (unexpected-test-file-failures 0) |
428 | 305 |
973 | 306 ;; #### perhaps this should be a defvar, and output at the very end |
307 ;; OTOH, this way AC types can use a null EMACSPACKAGEPATH to find | |
308 ;; what stuff is needed, and ways to avoid using them | |
309 (skipped-test-reasons (make-hash-table :test 'equal)) | |
310 | |
428 | 311 (trick-optimizer nil) |
826 | 312 (debug-on-error t) |
5064
501b5e84f5a7
remove unused var in test-harness
Ben Wing <ben@xemacs.org>
parents:
5040
diff
changeset
|
313 ) |
428 | 314 (with-output-to-temp-buffer "*Test-Log*" |
826 | 315 (princ (format "Testing %s...\n\n" filename)) |
1095 | 316 |
1413 | 317 (defconst test-harness-failure-tag "FAIL") |
318 (defconst test-harness-success-tag "PASS") | |
1095 | 319 |
4891
732c35cdded8
fix failing-case output of Assert-test, add Assert-test-not
Ben Wing <ben@xemacs.org>
parents:
4856
diff
changeset
|
320 ;;;;; BEGIN DEFINITION OF MACROS USEFUL IN TEST CODE |
732c35cdded8
fix failing-case output of Assert-test, add Assert-test-not
Ben Wing <ben@xemacs.org>
parents:
4856
diff
changeset
|
321 |
1095 | 322 (defmacro Known-Bug-Expect-Failure (&rest body) |
4891
732c35cdded8
fix failing-case output of Assert-test, add Assert-test-not
Ben Wing <ben@xemacs.org>
parents:
4856
diff
changeset
|
323 "Wrap a BODY that consists of tests that are known to fail. |
732c35cdded8
fix failing-case output of Assert-test, add Assert-test-not
Ben Wing <ben@xemacs.org>
parents:
4856
diff
changeset
|
324 This causes messages to be printed on failure indicating that this is expected, |
732c35cdded8
fix failing-case output of Assert-test, add Assert-test-not
Ben Wing <ben@xemacs.org>
parents:
4856
diff
changeset
|
325 and on success indicating that this is unexpected." |
5040
3daf9fc57cd4
fixes to test harness to allow backtracing/debugging of failures
Ben Wing <ben@xemacs.org>
parents:
4962
diff
changeset
|
326 `(let ((test-harness-bug-expected t) |
3daf9fc57cd4
fixes to test harness to allow backtracing/debugging of failures
Ben Wing <ben@xemacs.org>
parents:
4962
diff
changeset
|
327 (test-harness-failure-tag "KNOWN BUG") |
1413 | 328 (test-harness-success-tag "PASS (FAILURE EXPECTED)")) |
329 ,@body)) | |
4323
94509abd0ef0
Commit a forgotten chunk of 4d0f773d5e21.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4199
diff
changeset
|
330 |
94509abd0ef0
Commit a forgotten chunk of 4d0f773d5e21.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4199
diff
changeset
|
331 (defmacro Known-Bug-Expect-Error (expected-error &rest body) |
4891
732c35cdded8
fix failing-case output of Assert-test, add Assert-test-not
Ben Wing <ben@xemacs.org>
parents:
4856
diff
changeset
|
332 "Wrap a BODY that consists of tests that are known to trigger an error. |
732c35cdded8
fix failing-case output of Assert-test, add Assert-test-not
Ben Wing <ben@xemacs.org>
parents:
4856
diff
changeset
|
333 This causes messages to be printed on failure indicating that this is expected, |
732c35cdded8
fix failing-case output of Assert-test, add Assert-test-not
Ben Wing <ben@xemacs.org>
parents:
4856
diff
changeset
|
334 and on success indicating that this is unexpected." |
4323
94509abd0ef0
Commit a forgotten chunk of 4d0f773d5e21.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4199
diff
changeset
|
335 (let ((quoted-body (if (= 1 (length body)) |
94509abd0ef0
Commit a forgotten chunk of 4d0f773d5e21.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4199
diff
changeset
|
336 `(quote ,(car body)) `(quote (progn ,@body))))) |
5040
3daf9fc57cd4
fixes to test harness to allow backtracing/debugging of failures
Ben Wing <ben@xemacs.org>
parents:
4962
diff
changeset
|
337 `(let ((test-harness-bug-expected t) |
3daf9fc57cd4
fixes to test harness to allow backtracing/debugging of failures
Ben Wing <ben@xemacs.org>
parents:
4962
diff
changeset
|
338 (test-harness-failure-tag "KNOWN BUG") |
4323
94509abd0ef0
Commit a forgotten chunk of 4d0f773d5e21.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4199
diff
changeset
|
339 (test-harness-success-tag "PASS (FAILURE EXPECTED)")) |
94509abd0ef0
Commit a forgotten chunk of 4d0f773d5e21.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4199
diff
changeset
|
340 (condition-case error-info |
94509abd0ef0
Commit a forgotten chunk of 4d0f773d5e21.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4199
diff
changeset
|
341 (progn |
94509abd0ef0
Commit a forgotten chunk of 4d0f773d5e21.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4199
diff
changeset
|
342 (setq trick-optimizer (progn ,@body)) |
94509abd0ef0
Commit a forgotten chunk of 4d0f773d5e21.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4199
diff
changeset
|
343 (Print-Pass |
94509abd0ef0
Commit a forgotten chunk of 4d0f773d5e21.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4199
diff
changeset
|
344 "%S executed successfully, but expected error %S" |
94509abd0ef0
Commit a forgotten chunk of 4d0f773d5e21.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4199
diff
changeset
|
345 ,quoted-body |
94509abd0ef0
Commit a forgotten chunk of 4d0f773d5e21.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4199
diff
changeset
|
346 ',expected-error) |
94509abd0ef0
Commit a forgotten chunk of 4d0f773d5e21.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4199
diff
changeset
|
347 (incf passes)) |
94509abd0ef0
Commit a forgotten chunk of 4d0f773d5e21.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4199
diff
changeset
|
348 (,expected-error |
94509abd0ef0
Commit a forgotten chunk of 4d0f773d5e21.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4199
diff
changeset
|
349 (Print-Failure "%S ==> error %S, as expected" |
94509abd0ef0
Commit a forgotten chunk of 4d0f773d5e21.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4199
diff
changeset
|
350 ,quoted-body ',expected-error) |
94509abd0ef0
Commit a forgotten chunk of 4d0f773d5e21.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4199
diff
changeset
|
351 (incf no-error-failures)) |
94509abd0ef0
Commit a forgotten chunk of 4d0f773d5e21.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4199
diff
changeset
|
352 (error |
94509abd0ef0
Commit a forgotten chunk of 4d0f773d5e21.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4199
diff
changeset
|
353 (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
|
354 ,quoted-body ',expected-error error-info) |
94509abd0ef0
Commit a forgotten chunk of 4d0f773d5e21.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4199
diff
changeset
|
355 (incf wrong-error-failures)))))) |
94509abd0ef0
Commit a forgotten chunk of 4d0f773d5e21.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4199
diff
changeset
|
356 |
1413 | 357 (defmacro Implementation-Incomplete-Expect-Failure (&rest body) |
4891
732c35cdded8
fix failing-case output of Assert-test, add Assert-test-not
Ben Wing <ben@xemacs.org>
parents:
4856
diff
changeset
|
358 "Wrap a BODY containing tests that are known to fail due to incomplete code. |
732c35cdded8
fix failing-case output of Assert-test, add Assert-test-not
Ben Wing <ben@xemacs.org>
parents:
4856
diff
changeset
|
359 This causes messages to be printed on failure indicating that the |
732c35cdded8
fix failing-case output of Assert-test, add Assert-test-not
Ben Wing <ben@xemacs.org>
parents:
4856
diff
changeset
|
360 implementation is incomplete (and hence the failure is expected); and on |
732c35cdded8
fix failing-case output of Assert-test, add Assert-test-not
Ben Wing <ben@xemacs.org>
parents:
4856
diff
changeset
|
361 success indicating that this is unexpected." |
5040
3daf9fc57cd4
fixes to test harness to allow backtracing/debugging of failures
Ben Wing <ben@xemacs.org>
parents:
4962
diff
changeset
|
362 `(let ((test-harness-bug-expected t) |
3daf9fc57cd4
fixes to test harness to allow backtracing/debugging of failures
Ben Wing <ben@xemacs.org>
parents:
4962
diff
changeset
|
363 (test-harness-failure-tag "IMPLEMENTATION INCOMPLETE") |
1413 | 364 (test-harness-success-tag "PASS (FAILURE EXPECTED)")) |
365 ,@body)) | |
826 | 366 |
367 (defun Print-Failure (fmt &rest args) | |
1413 | 368 (setq fmt (format "%s: %s" test-harness-failure-tag fmt)) |
826 | 369 (if (noninteractive) (apply #'message fmt args)) |
370 (princ (concat (apply #'format fmt args) "\n"))) | |
371 | |
372 (defun Print-Pass (fmt &rest args) | |
1413 | 373 (setq fmt (format "%s: %s" test-harness-success-tag fmt)) |
826 | 374 (and test-harness-verbose |
375 (princ (concat (apply #'format fmt args) "\n")))) | |
376 | |
973 | 377 (defun Print-Skip (test reason &optional fmt &rest args) |
1095 | 378 (setq fmt (concat "SKIP: %S BECAUSE %S" fmt)) |
973 | 379 (princ (concat (apply #'format fmt test reason args) "\n"))) |
380 | |
1095 | 381 (defmacro Skip-Test-Unless (condition reason description &rest body) |
382 "Unless CONDITION is satisfied, skip test BODY. | |
383 REASON is a description of the condition failure, and must be unique (it | |
384 is used as a hash key). DESCRIPTION describes the tests that were skipped. | |
385 BODY is a sequence of expressions and may contain several tests." | |
386 `(if (not ,condition) | |
387 (let ((count (gethash ,reason skipped-test-reasons))) | |
388 (puthash ,reason (if (null count) 1 (1+ count)) | |
389 skipped-test-reasons) | |
390 (Print-Skip ,description ,reason)) | |
391 ,@body)) | |
428 | 392 |
4747
294a86d29f99
Eliminate C asserts from c-tests.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4415
diff
changeset
|
393 (defmacro Assert (assertion &optional failing-case description) |
294a86d29f99
Eliminate C asserts from c-tests.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4415
diff
changeset
|
394 "Test passes if ASSERTION is true. |
4856 | 395 Optional FAILING-CASE describes the particular failure. Optional |
396 DESCRIPTION describes the assertion; by default, the unevalated assertion | |
397 expression is given. FAILING-CASE and DESCRIPTION are useful when Assert | |
398 is used in a loop." | |
5136
0f66906b6e37
Undo Assert-equal, Assert=, etc.; make `Assert' handle this automatically
Ben Wing <ben@xemacs.org>
parents:
5110
diff
changeset
|
399 (let ((test-assertion assertion) |
0f66906b6e37
Undo Assert-equal, Assert=, etc.; make `Assert' handle this automatically
Ben Wing <ben@xemacs.org>
parents:
5110
diff
changeset
|
400 (negated nil)) |
0f66906b6e37
Undo Assert-equal, Assert=, etc.; make `Assert' handle this automatically
Ben Wing <ben@xemacs.org>
parents:
5110
diff
changeset
|
401 (when (and (listp test-assertion) |
0f66906b6e37
Undo Assert-equal, Assert=, etc.; make `Assert' handle this automatically
Ben Wing <ben@xemacs.org>
parents:
5110
diff
changeset
|
402 (= 2 (length test-assertion)) |
0f66906b6e37
Undo Assert-equal, Assert=, etc.; make `Assert' handle this automatically
Ben Wing <ben@xemacs.org>
parents:
5110
diff
changeset
|
403 (memq (car test-assertion) '(not null))) |
0f66906b6e37
Undo Assert-equal, Assert=, etc.; make `Assert' handle this automatically
Ben Wing <ben@xemacs.org>
parents:
5110
diff
changeset
|
404 (setq test-assertion (cadr test-assertion)) |
0f66906b6e37
Undo Assert-equal, Assert=, etc.; make `Assert' handle this automatically
Ben Wing <ben@xemacs.org>
parents:
5110
diff
changeset
|
405 (setq negated t)) |
0f66906b6e37
Undo Assert-equal, Assert=, etc.; make `Assert' handle this automatically
Ben Wing <ben@xemacs.org>
parents:
5110
diff
changeset
|
406 (when (and (listp test-assertion) |
0f66906b6e37
Undo Assert-equal, Assert=, etc.; make `Assert' handle this automatically
Ben Wing <ben@xemacs.org>
parents:
5110
diff
changeset
|
407 (= 3 (length test-assertion)) |
0f66906b6e37
Undo Assert-equal, Assert=, etc.; make `Assert' handle this automatically
Ben Wing <ben@xemacs.org>
parents:
5110
diff
changeset
|
408 (member (car test-assertion) |
0f66906b6e37
Undo Assert-equal, Assert=, etc.; make `Assert' handle this automatically
Ben Wing <ben@xemacs.org>
parents:
5110
diff
changeset
|
409 '(eq eql equal equalp = string= < <= > >=))) |
0f66906b6e37
Undo Assert-equal, Assert=, etc.; make `Assert' handle this automatically
Ben Wing <ben@xemacs.org>
parents:
5110
diff
changeset
|
410 (let* ((test (car test-assertion)) |
0f66906b6e37
Undo Assert-equal, Assert=, etc.; make `Assert' handle this automatically
Ben Wing <ben@xemacs.org>
parents:
5110
diff
changeset
|
411 (testval (second test-assertion)) |
0f66906b6e37
Undo Assert-equal, Assert=, etc.; make `Assert' handle this automatically
Ben Wing <ben@xemacs.org>
parents:
5110
diff
changeset
|
412 (expected (third test-assertion)) |
0f66906b6e37
Undo Assert-equal, Assert=, etc.; make `Assert' handle this automatically
Ben Wing <ben@xemacs.org>
parents:
5110
diff
changeset
|
413 (failmsg `(format ,(if negated |
0f66906b6e37
Undo Assert-equal, Assert=, etc.; make `Assert' handle this automatically
Ben Wing <ben@xemacs.org>
parents:
5110
diff
changeset
|
414 "%S shouldn't be `%s' to %S but is" |
0f66906b6e37
Undo Assert-equal, Assert=, etc.; make `Assert' handle this automatically
Ben Wing <ben@xemacs.org>
parents:
5110
diff
changeset
|
415 "%S should be `%s' to %S but isn't") |
0f66906b6e37
Undo Assert-equal, Assert=, etc.; make `Assert' handle this automatically
Ben Wing <ben@xemacs.org>
parents:
5110
diff
changeset
|
416 ,testval ',test ,expected))) |
0f66906b6e37
Undo Assert-equal, Assert=, etc.; make `Assert' handle this automatically
Ben Wing <ben@xemacs.org>
parents:
5110
diff
changeset
|
417 (setq failing-case (if failing-case |
0f66906b6e37
Undo Assert-equal, Assert=, etc.; make `Assert' handle this automatically
Ben Wing <ben@xemacs.org>
parents:
5110
diff
changeset
|
418 `(concat |
0f66906b6e37
Undo Assert-equal, Assert=, etc.; make `Assert' handle this automatically
Ben Wing <ben@xemacs.org>
parents:
5110
diff
changeset
|
419 (format "%S, " ,failing-case) |
0f66906b6e37
Undo Assert-equal, Assert=, etc.; make `Assert' handle this automatically
Ben Wing <ben@xemacs.org>
parents:
5110
diff
changeset
|
420 ,failmsg) |
0f66906b6e37
Undo Assert-equal, Assert=, etc.; make `Assert' handle this automatically
Ben Wing <ben@xemacs.org>
parents:
5110
diff
changeset
|
421 failmsg))))) |
4856 | 422 (let ((description |
423 (or description `(quote ,assertion)))) | |
5040
3daf9fc57cd4
fixes to test harness to allow backtracing/debugging of failures
Ben Wing <ben@xemacs.org>
parents:
4962
diff
changeset
|
424 `(condition-case nil |
3daf9fc57cd4
fixes to test harness to allow backtracing/debugging of failures
Ben Wing <ben@xemacs.org>
parents:
4962
diff
changeset
|
425 (call-with-condition-handler |
3daf9fc57cd4
fixes to test harness to allow backtracing/debugging of failures
Ben Wing <ben@xemacs.org>
parents:
4962
diff
changeset
|
426 #'(lambda (error-info) |
3daf9fc57cd4
fixes to test harness to allow backtracing/debugging of failures
Ben Wing <ben@xemacs.org>
parents:
4962
diff
changeset
|
427 (if (eq 'cl-assertion-failed (car error-info)) |
3daf9fc57cd4
fixes to test harness to allow backtracing/debugging of failures
Ben Wing <ben@xemacs.org>
parents:
4962
diff
changeset
|
428 (progn |
3daf9fc57cd4
fixes to test harness to allow backtracing/debugging of failures
Ben Wing <ben@xemacs.org>
parents:
4962
diff
changeset
|
429 (Print-Failure |
3daf9fc57cd4
fixes to test harness to allow backtracing/debugging of failures
Ben Wing <ben@xemacs.org>
parents:
4962
diff
changeset
|
430 (if ,failing-case |
3daf9fc57cd4
fixes to test harness to allow backtracing/debugging of failures
Ben Wing <ben@xemacs.org>
parents:
4962
diff
changeset
|
431 "Assertion failed: %S; failing case = %S" |
3daf9fc57cd4
fixes to test harness to allow backtracing/debugging of failures
Ben Wing <ben@xemacs.org>
parents:
4962
diff
changeset
|
432 "Assertion failed: %S") |
3daf9fc57cd4
fixes to test harness to allow backtracing/debugging of failures
Ben Wing <ben@xemacs.org>
parents:
4962
diff
changeset
|
433 ,description ,failing-case) |
3daf9fc57cd4
fixes to test harness to allow backtracing/debugging of failures
Ben Wing <ben@xemacs.org>
parents:
4962
diff
changeset
|
434 (incf assertion-failures) |
3daf9fc57cd4
fixes to test harness to allow backtracing/debugging of failures
Ben Wing <ben@xemacs.org>
parents:
4962
diff
changeset
|
435 (test-harness-assertion-failure-do-debug error-info)) |
3daf9fc57cd4
fixes to test harness to allow backtracing/debugging of failures
Ben Wing <ben@xemacs.org>
parents:
4962
diff
changeset
|
436 (Print-Failure |
3daf9fc57cd4
fixes to test harness to allow backtracing/debugging of failures
Ben Wing <ben@xemacs.org>
parents:
4962
diff
changeset
|
437 (if ,failing-case |
3daf9fc57cd4
fixes to test harness to allow backtracing/debugging of failures
Ben Wing <ben@xemacs.org>
parents:
4962
diff
changeset
|
438 "%S ==> error: %S; failing case = %S" |
3daf9fc57cd4
fixes to test harness to allow backtracing/debugging of failures
Ben Wing <ben@xemacs.org>
parents:
4962
diff
changeset
|
439 "%S ==> error: %S") |
3daf9fc57cd4
fixes to test harness to allow backtracing/debugging of failures
Ben Wing <ben@xemacs.org>
parents:
4962
diff
changeset
|
440 ,description error-info ,failing-case) |
3daf9fc57cd4
fixes to test harness to allow backtracing/debugging of failures
Ben Wing <ben@xemacs.org>
parents:
4962
diff
changeset
|
441 (incf other-failures) |
3daf9fc57cd4
fixes to test harness to allow backtracing/debugging of failures
Ben Wing <ben@xemacs.org>
parents:
4962
diff
changeset
|
442 (test-harness-unexpected-error-do-debug error-info))) |
3daf9fc57cd4
fixes to test harness to allow backtracing/debugging of failures
Ben Wing <ben@xemacs.org>
parents:
4962
diff
changeset
|
443 #'(lambda () |
3daf9fc57cd4
fixes to test harness to allow backtracing/debugging of failures
Ben Wing <ben@xemacs.org>
parents:
4962
diff
changeset
|
444 (assert ,assertion) |
3daf9fc57cd4
fixes to test harness to allow backtracing/debugging of failures
Ben Wing <ben@xemacs.org>
parents:
4962
diff
changeset
|
445 (Print-Pass "%S" ,description) |
3daf9fc57cd4
fixes to test harness to allow backtracing/debugging of failures
Ben Wing <ben@xemacs.org>
parents:
4962
diff
changeset
|
446 (incf passes))) |
3daf9fc57cd4
fixes to test harness to allow backtracing/debugging of failures
Ben Wing <ben@xemacs.org>
parents:
4962
diff
changeset
|
447 (cl-assertion-failed nil)))) |
2056 | 448 |
428 | 449 (defmacro Check-Error (expected-error &rest body) |
450 (let ((quoted-body (if (= 1 (length body)) | |
451 `(quote ,(car body)) `(quote (progn ,@body))))) | |
452 `(condition-case error-info | |
453 (progn | |
454 (setq trick-optimizer (progn ,@body)) | |
826 | 455 (Print-Failure "%S executed successfully, but expected error %S" |
428 | 456 ,quoted-body |
826 | 457 ',expected-error) |
428 | 458 (incf no-error-failures)) |
459 (,expected-error | |
826 | 460 (Print-Pass "%S ==> error %S, as expected" |
461 ,quoted-body ',expected-error) | |
428 | 462 (incf passes)) |
463 (error | |
826 | 464 (Print-Failure "%S ==> expected error %S, got error %S instead" |
465 ,quoted-body ',expected-error error-info) | |
428 | 466 (incf wrong-error-failures))))) |
467 | |
826 | 468 (defmacro Check-Error-Message (expected-error expected-error-regexp |
469 &rest body) | |
428 | 470 (let ((quoted-body (if (= 1 (length body)) |
471 `(quote ,(car body)) `(quote (progn ,@body))))) | |
472 `(condition-case error-info | |
473 (progn | |
474 (setq trick-optimizer (progn ,@body)) | |
826 | 475 (Print-Failure "%S executed successfully, but expected error %S" |
476 ,quoted-body ',expected-error) | |
428 | 477 (incf no-error-failures)) |
478 (,expected-error | |
4199 | 479 ;; #### Damn, this binding doesn't capture frobs, eg, for |
480 ;; invalid_argument() ... you only get the REASON. And for | |
481 ;; wrong_type_argument(), there's no reason only FROBs. | |
482 ;; If this gets fixed, fix tests in regexp-tests.el. | |
428 | 483 (let ((error-message (second error-info))) |
484 (if (string-match ,expected-error-regexp error-message) | |
485 (progn | |
826 | 486 (Print-Pass "%S ==> error %S %S, as expected" |
487 ,quoted-body error-message ',expected-error) | |
428 | 488 (incf passes)) |
826 | 489 (Print-Failure "%S ==> got error %S as expected, but error message %S did not match regexp %S" |
490 ,quoted-body ',expected-error error-message ,expected-error-regexp) | |
428 | 491 (incf wrong-error-failures)))) |
492 (error | |
826 | 493 (Print-Failure "%S ==> expected error %S, got error %S instead" |
494 ,quoted-body ',expected-error error-info) | |
428 | 495 (incf wrong-error-failures))))) |
496 | |
3472 | 497 ;; Do not use this with Silence-Message. |
428 | 498 (defmacro Check-Message (expected-message-regexp &rest body) |
5069
14f0dd1fabdb
move test-harness to lisp/ directory so it gets byte-compiled
Ben Wing <ben@xemacs.org>
parents:
5064
diff
changeset
|
499 (let ((quoted-body (if (= 1 (length body)) |
14f0dd1fabdb
move test-harness to lisp/ directory so it gets byte-compiled
Ben Wing <ben@xemacs.org>
parents:
5064
diff
changeset
|
500 `(quote ,(car body)) |
14f0dd1fabdb
move test-harness to lisp/ directory so it gets byte-compiled
Ben Wing <ben@xemacs.org>
parents:
5064
diff
changeset
|
501 `(quote (progn ,@body))))) |
14f0dd1fabdb
move test-harness to lisp/ directory so it gets byte-compiled
Ben Wing <ben@xemacs.org>
parents:
5064
diff
changeset
|
502 `(Skip-Test-Unless (fboundp 'defadvice) "can't defadvice" |
5274
ecdd1daab447
Add an omitted comma, Check-Message, test-harness.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5136
diff
changeset
|
503 ,expected-message-regexp |
5069
14f0dd1fabdb
move test-harness to lisp/ directory so it gets byte-compiled
Ben Wing <ben@xemacs.org>
parents:
5064
diff
changeset
|
504 (let ((messages "")) |
14f0dd1fabdb
move test-harness to lisp/ directory so it gets byte-compiled
Ben Wing <ben@xemacs.org>
parents:
5064
diff
changeset
|
505 (defadvice message (around collect activate) |
14f0dd1fabdb
move test-harness to lisp/ directory so it gets byte-compiled
Ben Wing <ben@xemacs.org>
parents:
5064
diff
changeset
|
506 (defvar messages) |
14f0dd1fabdb
move test-harness to lisp/ directory so it gets byte-compiled
Ben Wing <ben@xemacs.org>
parents:
5064
diff
changeset
|
507 (let ((msg-string (apply 'format (ad-get-args 0)))) |
14f0dd1fabdb
move test-harness to lisp/ directory so it gets byte-compiled
Ben Wing <ben@xemacs.org>
parents:
5064
diff
changeset
|
508 (setq messages (concat messages msg-string)) |
14f0dd1fabdb
move test-harness to lisp/ directory so it gets byte-compiled
Ben Wing <ben@xemacs.org>
parents:
5064
diff
changeset
|
509 msg-string)) |
14f0dd1fabdb
move test-harness to lisp/ directory so it gets byte-compiled
Ben Wing <ben@xemacs.org>
parents:
5064
diff
changeset
|
510 (ignore-errors |
14f0dd1fabdb
move test-harness to lisp/ directory so it gets byte-compiled
Ben Wing <ben@xemacs.org>
parents:
5064
diff
changeset
|
511 (call-with-condition-handler |
14f0dd1fabdb
move test-harness to lisp/ directory so it gets byte-compiled
Ben Wing <ben@xemacs.org>
parents:
5064
diff
changeset
|
512 #'(lambda (error-info) |
14f0dd1fabdb
move test-harness to lisp/ directory so it gets byte-compiled
Ben Wing <ben@xemacs.org>
parents:
5064
diff
changeset
|
513 (Print-Failure "%S ==> unexpected error %S" |
14f0dd1fabdb
move test-harness to lisp/ directory so it gets byte-compiled
Ben Wing <ben@xemacs.org>
parents:
5064
diff
changeset
|
514 ,quoted-body error-info) |
14f0dd1fabdb
move test-harness to lisp/ directory so it gets byte-compiled
Ben Wing <ben@xemacs.org>
parents:
5064
diff
changeset
|
515 (incf other-failures) |
14f0dd1fabdb
move test-harness to lisp/ directory so it gets byte-compiled
Ben Wing <ben@xemacs.org>
parents:
5064
diff
changeset
|
516 (test-harness-unexpected-error-do-debug error-info)) |
14f0dd1fabdb
move test-harness to lisp/ directory so it gets byte-compiled
Ben Wing <ben@xemacs.org>
parents:
5064
diff
changeset
|
517 #'(lambda () |
14f0dd1fabdb
move test-harness to lisp/ directory so it gets byte-compiled
Ben Wing <ben@xemacs.org>
parents:
5064
diff
changeset
|
518 (setq trick-optimizer (progn ,@body)) |
14f0dd1fabdb
move test-harness to lisp/ directory so it gets byte-compiled
Ben Wing <ben@xemacs.org>
parents:
5064
diff
changeset
|
519 (if (string-match ,expected-message-regexp messages) |
14f0dd1fabdb
move test-harness to lisp/ directory so it gets byte-compiled
Ben Wing <ben@xemacs.org>
parents:
5064
diff
changeset
|
520 (progn |
14f0dd1fabdb
move test-harness to lisp/ directory so it gets byte-compiled
Ben Wing <ben@xemacs.org>
parents:
5064
diff
changeset
|
521 (Print-Pass |
14f0dd1fabdb
move test-harness to lisp/ directory so it gets byte-compiled
Ben Wing <ben@xemacs.org>
parents:
5064
diff
changeset
|
522 "%S ==> value %S, message %S, matching %S, as expected" |
14f0dd1fabdb
move test-harness to lisp/ directory so it gets byte-compiled
Ben Wing <ben@xemacs.org>
parents:
5064
diff
changeset
|
523 ,quoted-body trick-optimizer messages |
14f0dd1fabdb
move test-harness to lisp/ directory so it gets byte-compiled
Ben Wing <ben@xemacs.org>
parents:
5064
diff
changeset
|
524 ',expected-message-regexp) |
14f0dd1fabdb
move test-harness to lisp/ directory so it gets byte-compiled
Ben Wing <ben@xemacs.org>
parents:
5064
diff
changeset
|
525 (incf passes)) |
14f0dd1fabdb
move test-harness to lisp/ directory so it gets byte-compiled
Ben Wing <ben@xemacs.org>
parents:
5064
diff
changeset
|
526 (Print-Failure |
14f0dd1fabdb
move test-harness to lisp/ directory so it gets byte-compiled
Ben Wing <ben@xemacs.org>
parents:
5064
diff
changeset
|
527 "%S ==> value %S, message %S, NOT matching expected %S" |
14f0dd1fabdb
move test-harness to lisp/ directory so it gets byte-compiled
Ben Wing <ben@xemacs.org>
parents:
5064
diff
changeset
|
528 ,quoted-body trick-optimizer messages |
14f0dd1fabdb
move test-harness to lisp/ directory so it gets byte-compiled
Ben Wing <ben@xemacs.org>
parents:
5064
diff
changeset
|
529 ',expected-message-regexp) |
14f0dd1fabdb
move test-harness to lisp/ directory so it gets byte-compiled
Ben Wing <ben@xemacs.org>
parents:
5064
diff
changeset
|
530 (incf missing-message-failures))))) |
14f0dd1fabdb
move test-harness to lisp/ directory so it gets byte-compiled
Ben Wing <ben@xemacs.org>
parents:
5064
diff
changeset
|
531 (ad-unadvise 'message))))) |
428 | 532 |
3472 | 533 ;; #### Perhaps this should override `message' itself, too? |
534 (defmacro Silence-Message (&rest body) | |
4323
94509abd0ef0
Commit a forgotten chunk of 4d0f773d5e21.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4199
diff
changeset
|
535 `(flet ((append-message (&rest args) ()) |
94509abd0ef0
Commit a forgotten chunk of 4d0f773d5e21.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4199
diff
changeset
|
536 (clear-message (&rest args) ())) |
94509abd0ef0
Commit a forgotten chunk of 4d0f773d5e21.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4199
diff
changeset
|
537 ,@body)) |
3472 | 538 |
428 | 539 (defmacro Ignore-Ebola (&rest body) |
540 `(let ((debug-issue-ebola-notices -42)) ,@body)) | |
541 | |
542 (defun Int-to-Marker (pos) | |
543 (save-excursion | |
544 (set-buffer standard-output) | |
545 (save-excursion | |
546 (goto-char pos) | |
547 (point-marker)))) | |
548 | |
549 (princ "Testing Interpreted Lisp\n\n") | |
5040
3daf9fc57cd4
fixes to test harness to allow backtracing/debugging of failures
Ben Wing <ben@xemacs.org>
parents:
4962
diff
changeset
|
550 |
3daf9fc57cd4
fixes to test harness to allow backtracing/debugging of failures
Ben Wing <ben@xemacs.org>
parents:
4962
diff
changeset
|
551 (test-harness-error-wrap |
3daf9fc57cd4
fixes to test harness to allow backtracing/debugging of failures
Ben Wing <ben@xemacs.org>
parents:
4962
diff
changeset
|
552 "executing interpreted code" |
3daf9fc57cd4
fixes to test harness to allow backtracing/debugging of failures
Ben Wing <ben@xemacs.org>
parents:
4962
diff
changeset
|
553 "Test suite execution aborted." |
3daf9fc57cd4
fixes to test harness to allow backtracing/debugging of failures
Ben Wing <ben@xemacs.org>
parents:
4962
diff
changeset
|
554 (funcall (test-harness-read-from-buffer inbuffer))) |
3daf9fc57cd4
fixes to test harness to allow backtracing/debugging of failures
Ben Wing <ben@xemacs.org>
parents:
4962
diff
changeset
|
555 |
428 | 556 (princ "\nTesting Compiled Lisp\n\n") |
5040
3daf9fc57cd4
fixes to test harness to allow backtracing/debugging of failures
Ben Wing <ben@xemacs.org>
parents:
4962
diff
changeset
|
557 |
1758 | 558 (let (code |
559 (test-harness-test-compiled t)) | |
5040
3daf9fc57cd4
fixes to test harness to allow backtracing/debugging of failures
Ben Wing <ben@xemacs.org>
parents:
4962
diff
changeset
|
560 (test-harness-error-wrap |
3daf9fc57cd4
fixes to test harness to allow backtracing/debugging of failures
Ben Wing <ben@xemacs.org>
parents:
4962
diff
changeset
|
561 "byte-compiling code" nil |
3daf9fc57cd4
fixes to test harness to allow backtracing/debugging of failures
Ben Wing <ben@xemacs.org>
parents:
4962
diff
changeset
|
562 (setq code |
3daf9fc57cd4
fixes to test harness to allow backtracing/debugging of failures
Ben Wing <ben@xemacs.org>
parents:
4962
diff
changeset
|
563 ;; our lisp code is often intentionally dubious, |
3daf9fc57cd4
fixes to test harness to allow backtracing/debugging of failures
Ben Wing <ben@xemacs.org>
parents:
4962
diff
changeset
|
564 ;; so throw away _all_ the byte compiler warnings. |
3daf9fc57cd4
fixes to test harness to allow backtracing/debugging of failures
Ben Wing <ben@xemacs.org>
parents:
4962
diff
changeset
|
565 (letf (((symbol-function 'byte-compile-warn) |
3daf9fc57cd4
fixes to test harness to allow backtracing/debugging of failures
Ben Wing <ben@xemacs.org>
parents:
4962
diff
changeset
|
566 'ignore)) |
3daf9fc57cd4
fixes to test harness to allow backtracing/debugging of failures
Ben Wing <ben@xemacs.org>
parents:
4962
diff
changeset
|
567 (byte-compile (test-harness-read-from-buffer |
3daf9fc57cd4
fixes to test harness to allow backtracing/debugging of failures
Ben Wing <ben@xemacs.org>
parents:
4962
diff
changeset
|
568 inbuffer)))) |
3daf9fc57cd4
fixes to test harness to allow backtracing/debugging of failures
Ben Wing <ben@xemacs.org>
parents:
4962
diff
changeset
|
569 ) |
3daf9fc57cd4
fixes to test harness to allow backtracing/debugging of failures
Ben Wing <ben@xemacs.org>
parents:
4962
diff
changeset
|
570 |
3daf9fc57cd4
fixes to test harness to allow backtracing/debugging of failures
Ben Wing <ben@xemacs.org>
parents:
4962
diff
changeset
|
571 (test-harness-error-wrap "executing byte-compiled code" |
3daf9fc57cd4
fixes to test harness to allow backtracing/debugging of failures
Ben Wing <ben@xemacs.org>
parents:
4962
diff
changeset
|
572 "Test suite execution aborted." |
3daf9fc57cd4
fixes to test harness to allow backtracing/debugging of failures
Ben Wing <ben@xemacs.org>
parents:
4962
diff
changeset
|
573 (if code (funcall code))) |
3daf9fc57cd4
fixes to test harness to allow backtracing/debugging of failures
Ben Wing <ben@xemacs.org>
parents:
4962
diff
changeset
|
574 ) |
826 | 575 (princ (format "\nSUMMARY for %s:\n" filename)) |
428 | 576 (princ (format "\t%5d passes\n" passes)) |
577 (princ (format "\t%5d assertion failures\n" assertion-failures)) | |
578 (princ (format "\t%5d errors that should have been generated, but weren't\n" no-error-failures)) | |
579 (princ (format "\t%5d wrong-error failures\n" wrong-error-failures)) | |
580 (princ (format "\t%5d missing-message failures\n" missing-message-failures)) | |
581 (princ (format "\t%5d other failures\n" other-failures)) | |
582 (let* ((total (+ passes | |
583 assertion-failures | |
584 no-error-failures | |
585 wrong-error-failures | |
586 missing-message-failures | |
587 other-failures)) | |
588 (basename (file-name-nondirectory filename)) | |
589 (summary-msg | |
4906
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4891
diff
changeset
|
590 (cond ((> unexpected-test-file-failures 0) |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4891
diff
changeset
|
591 (format test-harness-aborted-summary-template |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4891
diff
changeset
|
592 (concat basename ":") total)) |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4891
diff
changeset
|
593 ((> total 0) |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4891
diff
changeset
|
594 (format test-harness-file-summary-template |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4891
diff
changeset
|
595 (concat basename ":") |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4891
diff
changeset
|
596 passes total (/ (* 100 passes) total))) |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4891
diff
changeset
|
597 (t |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4891
diff
changeset
|
598 (format test-harness-null-summary-template |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4891
diff
changeset
|
599 (concat basename ":"))))) |
973 | 600 (reasons "")) |
601 (maphash (lambda (key value) | |
602 (setq reasons | |
603 (concat reasons | |
1095 | 604 (format "\n %d tests skipped because %s." |
973 | 605 value key)))) |
606 skipped-test-reasons) | |
607 (when (> (length reasons) 1) | |
608 (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
|
609 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
|
610 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
|
611 --package-path to enable the skipped tests."))) |
1719 | 612 (setq test-harness-file-results-alist |
613 (cons (list filename passes total) | |
614 test-harness-file-results-alist)) | |
428 | 615 (message "%s" summary-msg)) |
3471 | 616 (when (> unexpected-test-file-failures 0) |
617 (setq unexpected-test-suite-failure-files | |
618 (cons filename unexpected-test-suite-failure-files)) | |
619 (setq unexpected-test-suite-failures | |
620 (+ unexpected-test-suite-failures unexpected-test-file-failures)) | |
428 | 621 (message "Test suite execution failed unexpectedly.")) |
622 (fmakunbound 'Assert) | |
623 (fmakunbound 'Check-Error) | |
863 | 624 (fmakunbound 'Check-Message) |
625 (fmakunbound 'Check-Error-Message) | |
428 | 626 (fmakunbound 'Ignore-Ebola) |
627 (fmakunbound 'Int-to-Marker) | |
1719 | 628 (and noninteractive |
629 (message "%s" (buffer-substring-no-properties | |
1751 | 630 nil nil "*Test-Log*"))) |
631 ))) | |
428 | 632 |
633 (defvar test-harness-results-point-max nil) | |
634 (defmacro displaying-emacs-test-results (&rest body) | |
635 `(let ((test-harness-results-point-max test-harness-results-point-max)) | |
636 ;; Log the file name. | |
637 (test-harness-log-file) | |
638 ;; Record how much is logged now. | |
639 ;; We will display the log buffer if anything more is logged | |
640 ;; before the end of BODY. | |
641 (or test-harness-results-point-max | |
642 (save-excursion | |
643 (set-buffer (get-buffer-create "*Test-Log*")) | |
644 (setq test-harness-results-point-max (point-max)))) | |
645 (unwind-protect | |
646 (condition-case error-info | |
647 (progn ,@body) | |
648 (error | |
649 (test-harness-report-error error-info))) | |
650 (save-excursion | |
651 ;; If there were compilation warnings, display them. | |
652 (set-buffer "*Test-Log*") | |
653 (if (= test-harness-results-point-max (point-max)) | |
654 nil | |
655 (if temp-buffer-show-function | |
656 (let ((show-buffer (get-buffer-create "*Test-Log-Show*"))) | |
657 (save-excursion | |
658 (set-buffer show-buffer) | |
659 (setq buffer-read-only nil) | |
660 (erase-buffer)) | |
661 (copy-to-buffer show-buffer | |
662 (save-excursion | |
663 (goto-char test-harness-results-point-max) | |
664 (forward-line -1) | |
665 (point)) | |
666 (point-max)) | |
667 (funcall temp-buffer-show-function show-buffer)) | |
668 (select-window | |
669 (prog1 (selected-window) | |
670 (select-window (display-buffer (current-buffer))) | |
671 (goto-char test-harness-results-point-max) | |
672 (recenter 1))))))))) | |
673 | |
674 (defun batch-test-emacs-1 (file) | |
675 (condition-case error-info | |
676 (progn (test-emacs-test-file file) t) | |
677 (error | |
678 (princ ">>Error occurred processing ") | |
679 (princ file) | |
680 (princ ": ") | |
681 (display-error error-info nil) | |
682 (terpri) | |
683 nil))) | |
684 | |
685 (defun batch-test-emacs () | |
686 "Run `test-harness' on the files remaining on the command line. | |
687 Use this from the command line, with `-batch'; | |
688 it won't work in an interactive Emacs. | |
689 Each file is processed even if an error occurred previously. | |
5069
14f0dd1fabdb
move test-harness to lisp/ directory so it gets byte-compiled
Ben Wing <ben@xemacs.org>
parents:
5064
diff
changeset
|
690 A directory can be given as well, and all files will be processed. |
4948
8b230c53075b
fix some tests in `make check', also add our own file-tests
Ben Wing <ben@xemacs.org>
parents:
4856
diff
changeset
|
691 For example, invoke \"xemacs -batch -f batch-test-emacs tests\"" |
428 | 692 ;; command-line-args-left is what is left of the command line (from |
693 ;; startup.el) | |
694 (defvar command-line-args-left) ;Avoid 'free variable' warning | |
695 (defvar debug-issue-ebola-notices) | |
696 (if (not noninteractive) | |
697 (error "`batch-test-emacs' is to be used only with -batch")) | |
698 (let ((error nil)) | |
699 (dolist (file command-line-args-left) | |
700 (if (file-directory-p file) | |
701 (dolist (file-in-dir (directory-files file t)) | |
702 (when (and (string-match emacs-lisp-file-regexp file-in-dir) | |
703 (not (or (auto-save-file-name-p file-in-dir) | |
5069
14f0dd1fabdb
move test-harness to lisp/ directory so it gets byte-compiled
Ben Wing <ben@xemacs.org>
parents:
5064
diff
changeset
|
704 (backup-file-name-p file-in-dir)))) |
428 | 705 (or (batch-test-emacs-1 file-in-dir) |
706 (setq error t)))) | |
707 (or (batch-test-emacs-1 file) | |
708 (setq error t)))) | |
1719 | 709 (let ((namelen 0) |
710 (succlen 0) | |
711 (testlen 0) | |
712 (results test-harness-file-results-alist)) | |
713 ;; compute maximum lengths of variable components of report | |
714 ;; probably should just use (length "byte-compiler-tests.el") | |
715 ;; and 5-place sizes -- this will also work for the file-by-file | |
716 ;; printing when Adrian's kludge gets reverted | |
717 (flet ((print-width (i) | |
718 (let ((x 10) (y 1)) | |
719 (while (>= i x) | |
720 (setq x (* 10 x) y (1+ y))) | |
721 y))) | |
722 (while results | |
723 (let* ((head (car results)) | |
724 (nn (length (file-name-nondirectory (first head)))) | |
725 (ss (print-width (second head))) | |
726 (tt (print-width (third head)))) | |
727 (when (> nn namelen) (setq namelen nn)) | |
728 (when (> ss succlen) (setq succlen ss)) | |
729 (when (> tt testlen) (setq testlen tt))) | |
730 (setq results (cdr results)))) | |
731 ;; create format and print | |
1751 | 732 (let ((results (reverse test-harness-file-results-alist))) |
1719 | 733 (while results |
734 (let* ((head (car results)) | |
1751 | 735 (basename (file-name-nondirectory (first head))) |
1719 | 736 (nsucc (second head)) |
737 (ntest (third head))) | |
4906
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4891
diff
changeset
|
738 (cond ((member (first head) unexpected-test-suite-failure-files) |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4891
diff
changeset
|
739 (message test-harness-aborted-summary-template |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4891
diff
changeset
|
740 (concat basename ":") |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4891
diff
changeset
|
741 ntest)) |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4891
diff
changeset
|
742 ((> ntest 0) |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4891
diff
changeset
|
743 (message test-harness-file-summary-template |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4891
diff
changeset
|
744 (concat basename ":") |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4891
diff
changeset
|
745 nsucc |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4891
diff
changeset
|
746 ntest |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4891
diff
changeset
|
747 (/ (* 100 nsucc) ntest))) |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4891
diff
changeset
|
748 (t |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4891
diff
changeset
|
749 (message test-harness-null-summary-template |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4891
diff
changeset
|
750 (concat basename ":")))) |
3471 | 751 (setq results (cdr results))))) |
752 (when (> unexpected-test-suite-failures 0) | |
753 (message "\n***** There %s %d unexpected test suite %s in %s:" | |
754 (if (= unexpected-test-suite-failures 1) "was" "were") | |
755 unexpected-test-suite-failures | |
756 (if (= unexpected-test-suite-failures 1) "failure" "failures") | |
757 (if (= (length unexpected-test-suite-failure-files) 1) | |
758 "file" | |
759 "files")) | |
760 (while unexpected-test-suite-failure-files | |
761 (let ((line (pop unexpected-test-suite-failure-files))) | |
762 (while (and (< (length line) 61) | |
763 unexpected-test-suite-failure-files) | |
764 (setq line | |
765 (concat line " " | |
766 (pop unexpected-test-suite-failure-files)))) | |
767 (message line))))) | |
1719 | 768 (message "\nDone") |
428 | 769 (kill-emacs (if error 1 0)))) |
770 | |
771 (provide 'test-harness) | |
772 | |
773 ;;; test-harness.el ends here |