X-Git-Url: http://repo.macrolet.net/gitweb/?a=blobdiff_plain;f=src%2Fcheck.lisp;h=06c9bba8b63dac0a8aeca35c8f31babc5453673b;hb=4fec31c7fee75162da986168c8578017c56c197d;hp=b8ec760d1ddf0ab643930baa5c2e4774fb266597;hpb=b946ea038243212fde4fa87103604a00666ddbf3;p=fiveam.git diff --git a/src/check.lisp b/src/check.lisp index b8ec760..06c9bba 100644 --- a/src/check.lisp +++ b/src/check.lisp @@ -147,16 +147,14 @@ Wrapping the TEST form in a NOT simply preducse a negated reason string." (setf bindings (list (list v ?value)) effective-test `(,?satisfies ,v) default-reason-args (list "~S did not satisfy ~S" v `',?satisfies))) - (t + (?_ (setf bindings '() effective-test test - default-reason-args "No reason supplied."))) + default-reason-args (list "No reason supplied")))) `(let ,bindings (if ,effective-test (add-result 'test-passed :test-expr ',test) - (process-failure :reason ,(if (null reason-args) - `(format nil ,@default-reason-args) - `(format nil ,@reason-args)) + (process-failure :reason (format nil ,@(or reason-args default-reason-args)) :test-expr ',test)))))) ;;;; *** Other checks @@ -193,24 +191,29 @@ Wrapping the TEST form in a NOT simply preducse a negated reason string." :test-expr ',condition) (add-result 'test-passed :test-expr ',condition))) -(defmacro signals (condition &body body) +(defmacro signals (condition-spec + &body body) "Generates a pass if BODY signals a condition of type CONDITION. BODY is evaluated in a block named NIL, CONDITION is not evaluated." (let ((block-name (gensym))) - `(block ,block-name - (handler-bind ((,condition (lambda (c) - (declare (ignore c)) - ;; ok, body threw condition - (add-result 'test-passed - :test-expr ',condition) - (return-from ,block-name t)))) - (block nil - ,@body - (process-failure - :reason (format nil "Failed to signal a ~S" ',condition) - :test-expr ',condition) - (return-from ,block-name nil)))))) + (destructuring-bind (condition &optional reason-control reason-args) + (ensure-list condition-spec) + `(block ,block-name + (handler-bind ((,condition (lambda (c) + (declare (ignore c)) + ;; ok, body threw condition + (add-result 'test-passed + :test-expr ',condition) + (return-from ,block-name t)))) + (block nil + ,@body + (process-failure + :reason ,(if reason-control + `(format nil ,reason-control ,@reason-args) + `(format nil "Failed to signal a ~S" ',condition)) + :test-expr ',condition) + (return-from ,block-name nil))))))) (defmacro finishes (&body body) "Generates a pass if BODY executes to normal completion. In