2
;;;; Author: Paul Dietz
3
;;;; Created: Sun Mar 9 05:40:13 2003
4
;;;; Contains: Auxiliary functions for testing DEFINE-CONDITION
8
(defun make-def-cond-name (name &rest suffixes)
9
(intern (apply #'concatenate 'string (string name) "/"
10
(mapcar #'string suffixes))
13
(defmacro define-condition-with-tests (name-symbol
14
parents slot-specs &rest options)
16
"Create a condition and some associated tests."
18
(assert (symbolp name-symbol))
19
(dolist (parent parents) (assert (symbolp parent)))
21
(let ((name (symbol-name name-symbol)))
22
`(eval-when (:load-toplevel :compile-toplevel :execute)
23
(report-and-ignore-errors (eval '(define-condition ,name-symbol ,parents
24
,slot-specs ,@options)))
25
,@(loop for parent in (adjoin 'condition parents)
27
`(deftest ,(make-def-cond-name name "IS-SUBTYPE-OF/" parent)
28
(subtypep* ',name-symbol ',parent)
30
,@(loop for parent in (adjoin 'condition parents)
32
`(deftest ,(make-def-cond-name name "IS-SUBTYPE-OF-2/" parent)
33
(check-all-subtypep ',name-symbol ',parent)
35
,@(loop for parent in (adjoin 'condition parents)
37
`(deftest ,(make-def-cond-name name
38
"IS-NOT-SUPERTYPE-OF/" parent)
39
(subtypep* ',parent ',name-symbol)
41
,@(loop for parent in (adjoin 'condition parents)
43
`(deftest ,(make-def-cond-name name "IS-A/" parent)
44
(let ((c (make-condition ',name-symbol)))
45
(notnot-mv (typep c ',parent)))
47
,@(loop for parent in (adjoin 'condition parents)
49
`(deftest ,(make-def-cond-name name "IS-SUBCLASS-OF/" parent)
50
(subtypep* (find-class ',name-symbol)
51
(find-class ',parent))
53
,@(loop for parent in (adjoin 'condition parents)
55
`(deftest ,(make-def-cond-name name
56
"IS-NOT-SUPERCLASS-OF/" parent)
57
(subtypep* (find-class ',parent)
58
(find-class ',name-symbol))
60
,@(loop for parent in (adjoin 'condition parents)
62
`(deftest ,(make-def-cond-name name "IS-A-MEMBER-OF-CLASS/"
64
(let ((c (make-condition ',name-symbol)))
65
(notnot-mv (typep c (find-class ',parent))))
67
(deftest ,(make-def-cond-name name "HANDLER-CASE-1")
68
(let ((c (make-condition ',name-symbol)))
69
(handler-case (normally (signal c))
70
(,name-symbol (c1) (eqt c c1))))
72
(deftest ,(make-def-cond-name name "HANDLER-CASE-2")
73
(let ((c (make-condition ',name-symbol)))
74
(handler-case (normally (signal c))
75
(condition (c1) (eqt c c1))))
77
,@(unless (some #'(lambda (ct) (subtypep ct 'error)) parents)
78
`((deftest ,(make-def-cond-name name "HANDLER-CASE-3")
79
(let ((c (make-condition ',name-symbol)))
80
(handler-case (normally (signal c))
82
(,name-symbol (c2) (eqt c c2))))