1.0.29.20: fix build breakage from 1.0.29.12 (PPC and MIPS, hopefully)
[sbcl/pkhuong.git] / tests / test-util.lisp
blob7ef6b6baec35a03968d17be5be78af9ebf9e23e9
1 (defpackage :test-util
2 (:use :cl :sb-ext)
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)))
23 `(block ,block-name
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))))
29 (progn
30 (log-msg "Running ~S" ',name)
31 (start-test)
32 ,@body
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"
40 :direction :output
41 :if-exists :supersede)
42 (format stream "~s~%" *failures*))))
44 (defun start-test ()
45 (unless (eq *test-file* *load-pathname*)
46 (setf *test-file* *load-pathname*)
47 (setf *test-count* 0))
48 (incf *test-count*))
50 (defun fail-test (type test-name condition)
51 (log-msg "~A ~S" type test-name)
52 (push (list type *test-file* (or test-name *test-count*))
53 *failures*)
54 (when (or (and *break-on-failure*
55 (not (eq type :expected-failure)))
56 *break-on-expected-failure*)
57 (really-invoke-debugger condition)))
59 (defun expected-failure-p (fails-on)
60 (sb-impl::featurep fails-on))
62 (defun really-invoke-debugger (condition)
63 (with-simple-restart (continue "Continue")
64 (let ((*invoke-debugger-hook* *invoke-debugger-hook*))
65 (enable-debugger)
66 (invoke-debugger condition))))