1 ;-*-syntax:COMMON-LISP;Package:(RT :use "COMMON-LISP" :colon-mode :external)-*-
3 #|----------------------------------------------------------------------------|
4 | Copyright 1990 by the Massachusetts Institute of Technology, Cambridge MA. |
6 | Permission to use, copy, modify, and distribute this software and its |
7 | documentation for any purpose and without fee is hereby granted, provided |
8 | that this copyright and permission notice appear in all copies and |
9 | supporting documentation, and that the name of M.I.T. not be used in |
10 | advertising or publicity pertaining to distribution of the software |
11 | without specific, written prior permission. M.I.T. makes no |
12 | representations about the suitability of this software for any purpose. |
13 | It is provided "as is" without express or implied warranty. |
15 | M.I.T. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING |
16 | ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL |
17 | M.I.T. BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR |
18 | ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, |
19 | WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, |
20 | ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS |
22 |----------------------------------------------------------------------------|#
24 ;This is the December 19, 1990 version of the regression tester.
28 (:export deftest get-test do-test rem-test
29 rem-all-tests do-tests pending-tests
30 continue-testing *test*
31 *do-tests-when-defined*))
33 (defvar *test* nil "Current test name")
34 (defvar *do-tests-when-defined* nil)
35 (defvar *entries* '(nil) "Test database")
36 (defvar *in-test* nil "Used by TEST")
37 (defvar *debug* nil "For debugging")
39 (defstruct (entry (:conc-name nil)
43 (defmacro vals (entry) `(cdddr ,entry))
45 (defmacro defn (entry) `(cdr ,entry))
47 (defun pending-tests ()
48 (do ((l (cdr *entries*) (cdr l))
50 ((null l) (nreverse r))
52 (push (name (car l)) r))))
54 (defun rem-all-tests ()
55 (setq *entries* (list nil))
58 (defun rem-test (&optional (name *test*))
59 (do ((l *entries* (cdr l)))
61 (when (equal (name (cadr l)) name)
62 (setf (cdr l) (cddr l))
65 (defun get-test (&optional (name *test*))
66 (defn (get-entry name)))
68 (defun get-entry (name)
69 (let ((entry (find name (cdr *entries*)
74 "~%No test with name ~:@(~S~)."
78 (defmacro deftest (name form &rest values)
79 `(add-entry '(t ,name ,form .,values)))
81 (defun add-entry (entry)
82 (setq entry (copy-list entry))
83 (do ((l *entries* (cdr l))) (nil)
85 (setf (cdr l) (list entry))
87 (when (equal (name (cadr l))
91 "Redefining test ~@:(~S~)"
94 (when *do-tests-when-defined*
96 (setq *test* (name entry)))
98 (defun report-error (error? &rest args)
100 (apply #'format t args)
101 (if error? (throw '*debug* nil)))
102 (error? (apply #'error args))
103 (t (apply #'warn args))))
105 (defun do-test (&optional (name *test*))
106 (do-entry (get-entry name)))
108 (defun do-entry (entry &optional
109 (s *standard-output*))
111 (setq *test* (name entry))
112 (setf (pend entry) t)
114 (*break-on-warnings* t)
115 (r (multiple-value-list
116 (eval (form entry)))))
118 (not (equal r (vals entry))))
120 (format s "~&Test ~:@(~S~) failed~
122 ~%Expected value~P: ~
127 (length (vals entry))
130 (when (not (pend entry)) *test*))
132 (defun continue-testing ()
134 (throw '*in-test* nil)
135 (do-entries *standard-output*)))
137 (defun do-tests (&optional
138 (out *standard-output*))
139 (dolist (entry (cdr *entries*))
140 (setf (pend entry) t))
144 (stream out :direction :output)
145 (do-entries stream))))
147 (defun do-entries (s)
148 (format s "~&Doing ~A pending test~:P ~
149 of ~A tests total.~%"
150 (count t (cdr *entries*)
152 (length (cdr *entries*)))
153 (dolist (entry (cdr *entries*))
155 (format s "~@[~<~%~:; ~:@(~S~)~>~]"
156 (do-entry entry s))))
157 (let ((pending (pending-tests)))
159 (format s "~&No tests failed.")
160 (format s "~&~A out of ~A ~
161 total tests failed: ~
165 (length (cdr *entries*))