3f99e51a8504ec55458a071fb137f85c91b1923f
[lisp-unit.git] / lisp-unit.lisp
blob3f99e51a8504ec55458a071fb137f85c91b1923f
1 ;;;-*- Mode: Lisp; Syntax: ANSI-Common-Lisp -*-
3 #|
4 Copyright (c) 2004-2005 Christopher K. Riesbeck
6 Permission is hereby granted, free of charge, to any person obtaining
7 a copy of this software and associated documentation files (the "Software"),
8 to deal in the Software without restriction, including without limitation
9 the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 and/or sell copies of the Software, and to permit persons to whom the
11 Software is furnished to do so, subject to the following conditions:
13 The above copyright notice and this permission notice shall be included
14 in all copies or substantial portions of the Software.
16 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
17 OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
20 OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21 ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22 OTHER DEALINGS IN THE SOFTWARE.
25 How to use
26 ----------
28 1. Read the documentation at:
29 https://github.com/OdonataResearchLLC/lisp-unit/wiki
31 2. Make a file of DEFINE-TEST's. See exercise-tests.lisp for many
32 examples. If you want, start your test file with (REMOVE-TESTS :ALL)
33 to clear any previously defined tests.
35 3. Load this file.
37 4. (use-package :lisp-unit)
39 5. Load your code file and your file of tests.
41 6. Test your code with (RUN-TESTS '(test-name1 test-name2 ...)) or
42 simply (RUN-TESTS :ALL) to run all defined tests.
44 A summary of how many tests passed and failed will be printed.
46 NOTE: Nothing is compiled until RUN-TESTS is expanded. Redefining
47 functions or even macros does not require reloading any tests.
51 ;;; Packages
53 (in-package :cl-user)
55 (defpackage :lisp-unit
56 (:use :common-lisp)
57 ;; Print parameters
58 (:export :*print-summary*
59 :*print-failures*
60 :*print-errors*)
61 ;; Forms for assertions
62 (:export :assert-eq
63 :assert-eql
64 :assert-equal
65 :assert-equalp
66 :assert-equality
67 :assert-prints
68 :assert-expands
69 :assert-true
70 :assert-false
71 :assert-error)
72 ;; Functions for managing tests
73 (:export :define-test
74 :list-tests
75 :test-code
76 :test-documentation
77 :remove-tests
78 :run-tests
79 :use-debugger)
80 ;; Functions for managing tags
81 (:export :list-tags
82 :tagged-tests
83 :remove-tags
84 :run-tags)
85 ;; Functions for reporting test results
86 (:export :test-names
87 :failed-tests
88 :error-tests
89 :missing-tests
90 :print-failures
91 :print-errors
92 :summarize-results)
93 ;; Functions for extensibility via signals
94 (:export :signal-results
95 :test-run-complete
96 :results)
97 ;; Utility predicates
98 (:export :logically-equal :set-equal))
100 (in-package :lisp-unit)
102 ;;; Global counters
104 (defparameter *pass* 0
105 "The passed assertion results.")
107 (defparameter *fail* ()
108 "The failed assertion results.")
110 (defun reset-counters ()
111 "Reset the counters to empty lists."
112 (setf *pass* 0 *fail* ()))
114 ;;; Global options
116 (defparameter *print-summary* nil
117 "Print a summary of the pass, fail, and error count if non-nil.")
119 (defparameter *print-failures* nil
120 "Print failure messages if non-NIL.")
122 (defparameter *print-errors* nil
123 "Print error messages if non-NIL.")
125 (defparameter *use-debugger* nil
126 "If not NIL, enter the debugger when an error is encountered in an
127 assertion.")
129 (defparameter *signal-results* nil
130 "Signal the result if non NIL.")
132 (defun use-debugger-p (condition)
133 "Debug or ignore errors."
134 (cond
135 ((eq :ask *use-debugger*)
136 (y-or-n-p "~A -- debug?" condition))
137 (*use-debugger*)))
139 (defun use-debugger (&optional (flag t))
140 "Use the debugger when testing, or not."
141 (setq *use-debugger* flag))
143 (defun signal-results (&optional (flag t))
144 "Signal the results for extensibility."
145 (setq *signal-results* flag))
147 ;;; Global unit test database
149 (defparameter *test-db* (make-hash-table :test #'eq)
150 "The unit test database is simply a hash table.")
152 (defun package-table (package &optional create)
153 (cond
154 ((gethash (find-package package) *test-db*))
155 (create
156 (setf (gethash package *test-db*) (make-hash-table)))
157 (t (warn "No tests defined for package: ~S" package))))
159 ;;; Global tags database
161 (defparameter *tag-db* (make-hash-table :test #'eq)
162 "The tag database is simply a hash table.")
164 (defun package-tags (package &optional create)
165 "Return the tags DB for the package."
166 (cond
167 ((gethash (find-package package) *tag-db*))
168 (create
169 (setf (gethash package *tag-db*) (make-hash-table)))
170 (t (warn "No tags defined for package: ~S" package))))
172 ;;; Unit test definition
174 (defclass unit-test ()
175 ((doc
176 :type string
177 :initarg :doc
178 :reader doc)
179 (code
180 :type list
181 :initarg :code
182 :reader code))
183 (:default-initargs :doc "" :code ())
184 (:documentation
185 "Organize the unit test documentation and code."))
187 ;;; NOTE: Shamelessly taken from PG's analyze-body
188 (defun parse-body (body &optional doc tag)
189 "Separate the components of the body."
190 (let ((item (first body)))
191 (cond
192 ((and (listp item) (eq :tag (first item)))
193 (parse-body (rest body) doc (nconc (rest item) tag)))
194 ((and (stringp item) (not doc) (rest body))
195 (if tag
196 (values doc tag (rest body))
197 (parse-body (rest body) doc tag)))
198 (t (values doc tag body)))))
200 (defmacro define-test (name &body body)
201 "Store the test in the test database."
202 (let ((qname (gensym "NAME-")))
203 (multiple-value-bind (doc tag code) (parse-body body)
204 `(let* ((,qname ',name)
205 (doc (or ,doc (string ,qname))))
206 (setf
207 ;; Unit test
208 (gethash ,qname (package-table *package* t))
209 (make-instance 'unit-test :doc doc :code ',code))
210 ;; Tags
211 (loop for tag in ',tag do
212 (pushnew
213 ,qname (gethash tag (package-tags *package* t))))
214 ;; Return the name of the test
215 ,qname))))
217 ;;; Manage tests
219 (defun list-tests (&optional (package *package*))
220 "Return a list of the tests in package."
221 (let ((table (package-table package)))
222 (when table
223 (loop for test-name being each hash-key in table
224 collect test-name))))
226 (defun test-documentation (name &optional (package *package*))
227 "Return the documentation for the test."
228 (let ((unit-test (gethash name (package-table package))))
229 (if (null unit-test)
230 (warn "No code defined for test ~A in package ~S."
231 name package)
232 (doc unit-test))))
234 (defun test-code (name &optional (package *package*))
235 "Returns the code stored for the test name."
236 (let ((unit-test (gethash name (package-table package))))
237 (if (null unit-test)
238 (warn "No code defined for test ~A in package ~S."
239 name package)
240 (code unit-test))))
242 (defun remove-tests (names &optional (package *package*))
243 "Remove individual tests or entire sets."
244 (if (eq :all names)
245 (if (null package)
246 (clrhash *test-db*)
247 (progn
248 (remhash (find-package package) *test-db*)
249 (remhash (find-package package) *tag-db*)))
250 (let ((table (package-table package)))
251 (unless (null table)
252 ;; Remove tests
253 (loop for name in names
254 unless (remhash name table) do
255 (warn "No test ~A in package ~A to remove."
256 name (package-name package)))
257 ;; Remove tests from tags
258 (loop with tags = (package-tags package)
259 for tag being each hash-key in tags
260 using (hash-value tagged-tests)
262 (setf
263 (gethash tag tags)
264 (set-difference tagged-tests names)))))))
266 ;;; Manage tags
268 (defun %tests-from-all-tags (&optional (package *package*))
269 "Return all of the tests that have been tagged."
270 (loop for tests being each hash-value in (package-tags package)
271 nconc (copy-list tests) into all-tests
272 finally (return (delete-duplicates all-tests))))
274 (defun %tests-from-tags (tags &optional (package *package*))
275 "Return the tests associated with the tags."
276 (loop with table = (package-tags package)
277 for tag in tags
278 as tests = (gethash tag table)
279 if (null tests) do (warn "No tests tagged with ~S." tag)
280 else nconc (copy-list tests) into all-tests
281 finally (return (delete-duplicates all-tests))))
283 (defun list-tags (&optional (package *package*))
284 "Return a list of the tags in package."
285 (let ((tags (package-tags package)))
286 (when tags
287 (loop for tag being each hash-key in tags collect tag))))
289 (defun tagged-tests (tags &optional (package *package*))
290 "Return a list of the tests associated with the tags."
291 (if (eq :all tags)
292 (%tests-from-all-tags package)
293 (%tests-from-tags tags package)))
295 (defun remove-tags (tags &optional (package *package*))
296 "Remove individual tags or entire sets."
297 (if (eq :all tags)
298 (if (null package)
299 (clrhash *tag-db*)
300 (remhash (find-package package) *tag-db*))
301 (let ((table (package-tags package)))
302 (unless (null table)
303 (loop for tag in tags
304 unless (remhash tag table) do
305 (warn "No tag ~A in package ~A to remove."
306 tag (package-name package)))))))
308 ;;; Assert macros
310 (defmacro assert-eq (expected form &rest extras)
311 "Assert whether expected and form are EQ."
312 `(expand-assert :equal ,form ,form ,expected ,extras :test #'eq))
314 (defmacro assert-eql (expected form &rest extras)
315 "Assert whether expected and form are EQL."
316 `(expand-assert :equal ,form ,form ,expected ,extras :test #'eql))
318 (defmacro assert-equal (expected form &rest extras)
319 "Assert whether expected and form are EQUAL."
320 `(expand-assert :equal ,form ,form ,expected ,extras :test #'equal))
322 (defmacro assert-equalp (expected form &rest extras)
323 "Assert whether expected and form are EQUALP."
324 `(expand-assert :equal ,form ,form ,expected ,extras :test #'equalp))
326 (defmacro assert-error (condition form &rest extras)
327 "Assert whether form signals condition."
328 `(expand-assert :error ,form (expand-error-form ,form)
329 ,condition ,extras))
331 (defmacro assert-expands (expansion form &rest extras)
332 "Assert whether form expands to expansion."
333 `(expand-assert :macro ,form
334 (expand-macro-form ,form nil)
335 ',expansion ,extras))
337 (defmacro assert-false (form &rest extras)
338 "Assert whether the form is false."
339 `(expand-assert :result ,form ,form nil ,extras))
341 (defmacro assert-equality (test expected form &rest extras)
342 "Assert whether expected and form are equal according to test."
343 `(expand-assert :equal ,form ,form ,expected ,extras :test ,test))
345 (defmacro assert-prints (output form &rest extras)
346 "Assert whether printing the form generates the output."
347 `(expand-assert :output ,form (expand-output-form ,form)
348 ,output ,extras))
350 (defmacro assert-true (form &rest extras)
351 "Assert whether the form is true."
352 `(expand-assert :result ,form ,form t ,extras))
354 (defmacro expand-assert (type form body expected extras &key (test '#'eql))
355 "Expand the assertion to the internal format."
356 `(internal-assert ,type ',form
357 (lambda () ,body)
358 (lambda () ,expected)
359 (expand-extras ,extras)
360 ,test))
362 (defmacro expand-error-form (form)
363 "Wrap the error assertion in HANDLER-CASE."
364 `(handler-case ,form
365 (condition (error) error)))
367 (defmacro expand-output-form (form)
368 "Capture the output of the form in a string."
369 (let ((out (gensym)))
370 `(let* ((,out (make-string-output-stream))
371 (*standard-output*
372 (make-broadcast-stream *standard-output* ,out)))
373 ,form
374 (get-output-stream-string ,out))))
376 (defmacro expand-macro-form (form env)
377 "Expand the macro form once."
378 `(let ((*gensym-counter* 1))
379 (macroexpand-1 ',form ,env)))
381 (defmacro expand-extras (extras)
382 "Expand extra forms."
383 `(lambda ()
384 (list ,@(mapcan (lambda (form) (list `',form form)) extras))))
386 (defclass failure-result ()
387 ((form
388 :initarg :form
389 :reader form)
390 (actual
391 :type list
392 :initarg :actual
393 :reader actual)
394 (expected
395 :type list
396 :initarg :expected
397 :reader expected)
398 (extras
399 :type list
400 :initarg :extras
401 :reader extras)
402 (test
403 :type function
404 :initarg :test
405 :reader test))
406 (:documentation
407 "Failure details of the assertion."))
409 (defclass equal-result (failure-result)
411 (:documentation
412 "Result of a failed equal assertion."))
414 (defun equal-result (test expected actual)
415 "Return the result of an equal assertion."
416 (and
417 (<= (length expected) (length actual))
418 (every test expected actual)))
420 (defclass error-result (failure-result)
422 (:documentation
423 "Result of a failed error assertion."))
425 (defun error-result (test expected actual)
426 "Return the result of an error assertion."
427 (declare (ignore test))
429 (eql (car actual) (car expected))
430 (typep (car actual) (car expected))))
432 (defclass macro-result (failure-result)
434 (:documentation
435 "Result of a failed macro expansion assertion."))
437 (defun %expansion-equal (form1 form2)
438 "Descend into the forms checking for equality."
439 (let ((item1 (first form1))
440 (item2 (first form2)))
441 (cond
442 ((and (null item1) (null item2)))
443 ((and (listp item1) (listp item2))
444 (and
445 (%expansion-equal item1 item2)
446 (%expansion-equal (rest form1) (rest form2))))
447 ((and (symbolp item1) (symbolp item2))
448 (and
449 (string= (symbol-name item1) (symbol-name item2))
450 (%expansion-equal (rest form1) (rest form2))))
451 (t (and
452 (equal item1 item2)
453 (%expansion-equal (rest form1) (rest form2)))))))
455 (defun macro-result (test expected actual)
456 "Return the result of a macro assertion."
457 (declare (ignore test))
458 (%expansion-equal (first expected) (first actual)))
460 (defclass boolean-result (failure-result)
462 (:documentation
463 "Result of a failed boolean assertion."))
465 (defun boolean-result (test expected actual)
466 "Return the result of a result assertion."
467 (declare (ignore test))
468 (logically-equal (car actual) (car expected)))
470 (defclass output-result (failure-result)
472 (:documentation
473 "Result of a failed output assertion."))
475 (defun output-result (test expected actual)
476 "Return the result of an output assertion."
477 (declare (ignore test))
478 (string=
479 (string-trim '(#\newline #\return #\space) (car actual))
480 (car expected)))
482 (defun assert-function (type)
483 "Return the function for the assertion type."
484 (ecase type
485 (:equal #'equal-result)
486 (:error #'error-result)
487 (:macro #'macro-result)
488 (:result #'boolean-result)
489 (:output #'output-result)))
491 (defun assert-class (type)
492 "Return the class for the assertion type."
493 (ecase type
494 (:equal 'equal-result)
495 (:error 'error-result)
496 (:macro 'macro-result)
497 (:result 'boolean-result)
498 (:output 'output-result)))
500 (defun internal-assert
501 (type form code-thunk expected-thunk extras test)
502 "Perform the assertion and record the results."
503 (let* ((actual (multiple-value-list (funcall code-thunk)))
504 (expected (multiple-value-list (funcall expected-thunk)))
505 (result
506 (funcall (assert-function type) test expected actual)))
507 (if result
508 (incf *pass*)
509 (push (make-instance
510 (assert-class type)
511 :form form
512 :actual actual
513 :expected expected
514 :extras (when extras (funcall extras))
515 :test test)
516 *fail*))
517 ;; Return the result
518 result))
520 ;;; Unit test results
522 (defclass test-result ()
523 ((name
524 :type symbol
525 :initarg :name
526 :reader name)
527 (pass
528 :type fixnum
529 :initarg :pass
530 :reader pass)
531 (fail
532 :type list
533 :initarg :fail
534 :reader fail)
535 (exerr
536 :initarg :exerr
537 :reader exerr)
538 (run-time
539 :initarg :run-time
540 :reader run-time
541 :documentation
542 "Test run time measured in internal time units"))
543 (:default-initargs :exerr nil)
544 (:documentation
545 "Store the results of the unit test."))
547 (defun print-summary (test-result &optional
548 (stream *standard-output*))
549 "Print a summary of the test result."
550 (format stream "~&~A: ~S assertions passed, ~S failed"
551 (name test-result)
552 (pass test-result)
553 (length (fail test-result)))
554 (if (exerr test-result)
555 (format stream ", and an execution error.")
556 (write-char #\. stream))
557 (terpri stream)
558 (terpri stream))
560 (defun run-code (code)
561 "Run the code to test the assertions."
562 (funcall (coerce `(lambda () ,@code) 'function)))
564 (defun run-test-thunk (name code)
565 (let ((*pass* 0)
566 (*fail* ())
567 (start (get-internal-run-time)))
568 (handler-bind
569 ((error
570 (lambda (condition)
571 (if (use-debugger-p condition)
572 condition
573 (return-from run-test-thunk
574 (make-instance
575 'test-result
576 :name name
577 :pass *pass*
578 :fail *fail*
579 :run-time (- (get-internal-run-time) start)
580 :exerr condition))))))
581 (run-code code))
582 ;; Return the result count
583 (make-instance
584 'test-result
585 :name name
586 :pass *pass*
587 :fail *fail*
588 :run-time (- (get-internal-run-time) start))))
590 ;;; Test results database
592 (defclass test-results-db ()
593 ((database
594 :type hash-table
595 :initform (make-hash-table :test #'eq)
596 :reader database)
597 (pass
598 :type fixnum
599 :initform 0
600 :accessor pass)
601 (fail
602 :type fixnum
603 :initform 0
604 :accessor fail)
605 (exerr
606 :type fixnum
607 :initform 0
608 :accessor exerr)
609 (failed-tests
610 :type list
611 :initform ()
612 :accessor failed-tests)
613 (error-tests
614 :type list
615 :initform ()
616 :accessor error-tests)
617 (missing-tests
618 :type list
619 :initform ()
620 :accessor missing-tests))
621 (:documentation
622 "Store the results of the tests for further evaluation."))
624 (defmethod print-object ((object test-results-db) stream)
625 "Print the summary counts with the object."
626 (let ((pass (pass object))
627 (fail (fail object))
628 (exerr (exerr object)))
629 (format
630 stream "#<~A Total(~D) Passed(~D) Failed(~D) Errors(~D)>~%"
631 (class-name (class-of object))
632 (+ pass fail) pass fail exerr)))
634 (defun test-names (test-results-db)
635 "Return a list of the test names in the database."
636 (loop for name being each hash-key in (database test-results-db)
637 collect name))
639 (defun record-result (test-name code results)
640 "Run the test code and record the result."
641 (let ((result (run-test-thunk test-name code)))
642 ;; Store the result
643 (setf (gethash test-name (database results)) result)
644 ;; Count passed tests
645 (when (plusp (pass result))
646 (incf (pass results) (pass result)))
647 ;; Count failed tests and record the name
648 (when (fail result)
649 (incf (fail results) (length (fail result)))
650 (push test-name (failed-tests results)))
651 ;; Count errors and record the name
652 (when (exerr result)
653 (incf (exerr results))
654 (push test-name (error-tests results)))
655 ;; Running output
656 (when *print-failures* (print-failures result))
657 (when *print-errors* (print-errors result))
658 (when (or *print-summary* *print-failures* *print-errors*)
659 (print-summary result))))
661 (defun summarize-results (results &optional
662 (stream *standard-output*))
663 "Print a summary of all results to the stream."
664 (let ((pass (pass results))
665 (fail (fail results)))
666 (format stream "~&Unit Test Summary~%")
667 (format stream " | ~D assertions total~%" (+ pass fail))
668 (format stream " | ~D passed~%" pass)
669 (format stream " | ~D failed~%" fail)
670 (format stream " | ~D execution errors~%" (exerr results))
671 (format stream " | ~D missing tests~2%"
672 (length (missing-tests results)))))
674 ;;; Run the tests
676 (define-condition test-run-complete ()
677 ((results
678 :type 'test-results-db
679 :initarg :results
680 :reader results))
681 (:documentation
682 "Signaled when a test run is finished."))
684 (defun %run-all-thunks (&optional (package *package*))
685 "Run all of the test thunks in the package."
686 (loop
687 with results = (make-instance 'test-results-db)
688 for test-name being each hash-key in (package-table package)
689 using (hash-value unit-test)
690 if unit-test do
691 (record-result test-name (code unit-test) results)
692 else do
693 (push test-name (missing-tests results))
694 ;; Summarize and return the test results
695 finally
696 (when *signal-results*
697 (signal 'test-run-complete :results results))
698 (summarize-results results)
699 (return results)))
701 (defun %run-thunks (test-names &optional (package *package*))
702 "Run the list of test thunks in the package."
703 (loop
704 with table = (package-table package)
705 and results = (make-instance 'test-results-db)
706 for test-name in test-names
707 as unit-test = (gethash test-name table)
708 if unit-test do
709 (record-result test-name (code unit-test) results)
710 else do
711 (push test-name (missing-tests results))
712 finally
713 (when *signal-results*
714 (signal 'test-run-complete :results results))
715 (summarize-results results)
716 (return results)))
718 (defun run-tests (test-names &optional (package *package*))
719 "Run the specified tests in package."
720 (reset-counters)
721 (if (eq :all test-names)
722 (%run-all-thunks package)
723 (%run-thunks test-names package)))
725 (defun run-tags (tags &optional (package *package*))
726 "Run the tests associated with the specified tags in package."
727 (reset-counters)
728 (%run-thunks (tagged-tests tags package) package))
730 ;;; Print failures
732 (defgeneric print-failures (result &optional stream)
733 (:documentation
734 "Report the results of the failed assertion."))
736 (defmethod print-failures :around ((result failure-result) &optional
737 (stream *standard-output*))
738 "Failure header and footer output."
739 (format stream "~& | Failed Form: ~S" (form result))
740 (call-next-method)
741 (when (extras result)
742 (format stream "~{~& | ~S => ~S~}~%" (extras result)))
743 (format stream "~& |~%"))
745 (defmethod print-failures ((result failure-result) &optional
746 (stream *standard-output*))
747 (format stream "~& | Expected ~{~S~^; ~} " (expected result))
748 (format stream "~<~% | ~:;but saw ~{~S~^; ~}~>" (actual result)))
750 (defmethod print-failures ((result error-result) &optional
751 (stream *standard-output*))
752 (format stream "~& | ~@[Should have signalled ~{~S~^; ~} but saw~]"
753 (expected result))
754 (format stream " ~{~S~^; ~}" (actual result)))
756 (defmethod print-failures ((result macro-result) &optional
757 (stream *standard-output*))
758 (format stream "~& | Should have expanded to ~{~S~^; ~} "
759 (expected result))
760 (format stream "~<~%~:;but saw ~{~S~^; ~}~>" (actual result)))
762 (defmethod print-failures ((result output-result) &optional
763 (stream *standard-output*))
764 (format stream "~& | Should have printed ~{~S~^; ~} "
765 (expected result))
766 (format stream "~<~%~:;but saw ~{~S~^; ~}~>"
767 (actual result)))
769 (defmethod print-failures ((result test-result) &optional
770 (stream *standard-output*))
771 "Print the failed assertions in the unit test."
772 (loop for fail in (fail result) do
773 (print-failures fail stream)))
775 (defmethod print-failures ((results test-results-db) &optional
776 (stream *standard-output*))
777 "Print all of the failure tests."
778 (loop with db = (database results)
779 for test in (failed-tests results)
780 as result = (gethash test db)
782 (print-failures result stream)
783 (print-summary result stream)))
785 ;;; Print errors
787 (defgeneric print-errors (result &optional stream)
788 (:documentation
789 "Print the error condition."))
791 (defmethod print-errors ((result test-result) &optional
792 (stream *standard-output*))
793 "Print the error condition."
794 (let ((exerr (exerr result))
795 (*print-escape* nil))
796 (when exerr
797 (format stream "~& | Execution error:~% | ~W" exerr)
798 (format stream "~& |~%"))))
800 (defmethod print-errors ((results test-results-db) &optional
801 (stream *standard-output*))
802 "Print all of the error tests."
803 (loop with db = (database results)
804 for test in (error-tests results)
805 as result = (gethash test db)
807 (print-errors result stream)
808 (print-summary result stream)))
810 ;;; Useful equality predicates for tests
812 (defun logically-equal (x y)
813 "Return true if x and y are both false or both true."
814 (eql (not x) (not y)))
816 (defun set-equal (list1 list2 &rest initargs &key key (test #'equal))
817 "Return true if every element of list1 is an element of list2 and
818 vice versa."
819 (declare (ignore key test))
820 (and
821 (listp list1)
822 (listp list2)
823 (apply #'subsetp list1 list2 initargs)
824 (apply #'subsetp list2 list1 initargs)))
826 (pushnew :lisp-unit common-lisp:*features*)