3 (:export #:with-test #:report-test-status #:*failures*
4 #:really-invoke-debugger
5 #:*break-on-failure* #:*break-on-expected-failure*))
7 (in-package :test-util)
9 (defvar *test-count* 0)
10 (defvar *test-file* nil)
11 (defvar *failures* nil)
12 (defvar *break-on-failure* nil)
13 (defvar *break-on-expected-failure* nil)
15 (defmacro with-test ((&key fails-on name) &body body)
16 (let ((block-name (gensym)))
18 (handler-bind ((error (lambda (error)
19 (if (expected-failure-p ,fails-on)
20 (fail-test :expected-failure ',name error)
21 (fail-test :unexpected-failure ',name error))
22 (return-from ,block-name))))
26 (when (expected-failure-p ,fails-on)
27 (fail-test :unexpected-success ',name nil)))))))
29 (defun report-test-status ()
30 (with-standard-io-syntax
31 (with-open-file (stream "test-status.lisp-expr"
33 :if-exists :supersede)
34 (format stream "~s~%" *failures*))))
37 (unless (eq *test-file* *load-pathname*)
38 (setf *test-file* *load-pathname*)
39 (setf *test-count* 0))
42 (defun fail-test (type test-name condition)
43 (push (list type *test-file* (or test-name *test-count*))
45 (when (or (and *break-on-failure*
46 (not (eq type :expected-failure)))
47 *break-on-expected-failure*)
48 (really-invoke-debugger condition)))
50 (defun expected-failure-p (fails-on)
51 (sb-impl::featurep fails-on))
53 (defun really-invoke-debugger (condition)
54 (with-simple-restart (continue "Continue")
55 (let ((*invoke-debugger-hook* *invoke-debugger-hook*))
57 (invoke-debugger condition))))