From 22865f0c55fbeb87b8ddf88e6de25bb17c2a25c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Kochma=C5=84ski?= Date: Thu, 4 Apr 2019 20:48:31 +0200 Subject: [PATCH] tests: improve signals macro to allow description --- src/tests/2am.lisp | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/src/tests/2am.lisp b/src/tests/2am.lisp index cd126fc8b..ffcd41abf 100644 --- a/src/tests/2am.lisp +++ b/src/tests/2am.lisp @@ -181,26 +181,30 @@ :format-control ,fmt-ctrl :format-arguments (list ,@fmt-args))))) -(defun %signals (expected fn) +(defun %signals (expected fn &rest args) (flet ((handler (condition) (cond ((typep condition expected) (return-from %signals (passed))) (t (return-from %signals - (failed (make-condition 'test-failure - :name *test-name* - :format-control "Expected to signal ~s, but got ~s:~%~a" - :format-arguments (list expected (type-of condition) condition)))))))) + (let ((fmt-ctrl (if args (car args) "Expected to signal ~s, but got ~s:~%~a")) + (fmt-args (if args (cdr args) (list expected (type-of condition) condition)))) + (failed (make-condition 'test-failure + :name *test-name* + :format-control fmt-ctrl + :format-arguments fmt-args)))))))) (handler-bind ((condition #'handler)) (funcall fn))) - (failed (make-condition 'test-failure - :name *test-name* - :format-control "Expected to signal ~s, but got nothing" - :format-arguments `(,expected)))) + (let ((fmt-ctrl (if args (car args) "Expected to signal ~s, but got nothing")) + (fmt-args (if args (cdr args) `(,expected)))) + (failed (make-condition 'test-failure + :name *test-name* + :format-control fmt-ctrl + :format-arguments fmt-args)))) -(defmacro signals (condition &body body) +(defmacro signals (condition form &rest args) "Assert that `body' signals a condition of type `condition'." - `(%signals ',condition (lambda () ,@body))) + `(%signals ',condition (lambda () ,form) ,@args)) (defmacro finishes (form) `(handler-case (progn