diff options
Diffstat (limited to 'testiere.lisp')
-rw-r--r-- | testiere.lisp | 22 |
1 files changed, 15 insertions, 7 deletions
diff --git a/testiere.lisp b/testiere.lisp index 003647c..8bdd526 100644 --- a/testiere.lisp +++ b/testiere.lisp @@ -59,17 +59,25 @@ (list (mapcar (lambda (spec) (build-test name spec)) specs) (append before after)))))) + (defmacro defun/t (name lambda-list &body body) "Like regular DEFUN, but with embedded unit tests. If those tests would fail, the function fails to be defined. " (destructuring-bind (tests function-body) (extract-tests name body) - `(labels ((,name ,lambda-list ,@function-body)) - (handler-case - (progn ,@tests - (defun ,name ,lambda-list ,@function-body)) - (error (e) - (invoke-debugger e) - ))))) + (let ((cached (gensym))) + `(let ((,cached + (when (fboundp ',name) + (symbol-function ',name)))) + (restart-case + (progn + (defun ,name ,lambda-list ,@function-body) + ,@tests) + (make-unbound () (fmakunbound ',name)) + (revert-to-last-good-version () + (if ,cached + (setf (symbol-function ',name) + ,cached) + (fmakunbound ',name)))))))) |