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 (defun log-msg (&rest args)
16 (format *trace-output* "~&::: ")
17 (apply #'format *trace-output* args)
18 (terpri *trace-output*)
19 (force-output *trace-output*))
21 (defmacro with-test ((&key fails-on name) &body body)
22 (let ((block-name (gensym)))
24 (handler-bind ((error (lambda (error)
25 (if (expected-failure-p ,fails-on)
26 (fail-test :expected-failure ',name error)
27 (fail-test :unexpected-failure ',name error))
28 (return-from ,block-name))))
30 (log-msg "Running ~S" ',name)
33 (if (expected-failure-p ,fails-on)
34 (fail-test :unexpected-success ',name nil)
35 (log-msg "Success ~S" ',name)))))))
37 (defun report-test-status ()
38 (with-standard-io-syntax
39 (with-open-file (stream "test-status.lisp-expr"
41 :if-exists :supersede)
42 (format stream "~s~%" *failures*))))
45 (unless (eq *test-file* *load-pathname*)
46 (setf *test-file* *load-pathname*)
47 (setf *test-count* 0))
50 (defun fail-test (type test-name condition)
51 (log-msg "~@<~A ~S ~:_due to ~S: ~4I~:_\"~A\"~:>"
52 type test-name condition condition)
53 (push (list type *test-file* (or test-name *test-count*))
55 (when (or (and *break-on-failure*
56 (not (eq type :expected-failure)))
57 *break-on-expected-failure*)
58 (really-invoke-debugger condition)))
60 (defun expected-failure-p (fails-on)
61 (sb-impl::featurep fails-on))
63 (defun really-invoke-debugger (condition)
64 (with-simple-restart (continue "Continue")
65 (let ((*invoke-debugger-hook* *invoke-debugger-hook*))
67 (invoke-debugger condition))))