X-Git-Url: http://repo.macrolet.net/gitweb/?a=blobdiff_plain;f=src%2Fmock.lisp;h=e10bb325bbf9908e9cdfbab7fff30dd9d619bdd3;hb=f6b59f232c6963cb305d9241742bb0f46cbbbad5;hp=ae9522d77aa446652e879526759a5370f71906ad;hpb=82370fd12b07679559c9e0b3f720aade582d42fb;p=cl-mock.git diff --git a/src/mock.lisp b/src/mock.lisp index ae9522d..e10bb32 100644 --- a/src/mock.lisp +++ b/src/mock.lisp @@ -1,4 +1,4 @@ -;;; -*- mode: lisp; syntax: common-lisp; coding: utf-8-unix; package: cl-mock; -*- +;; -*- mode: lisp; syntax: common-lisp; coding: utf-8-unix; package: cl-mock; -*- (in-package #:cl-mock) @@ -25,8 +25,8 @@ and executes it. If no mock was found, no values are returned instead." (defun call-with-mocks (mock-bindings function &key (recordp T)) "Calls FUNCTION with the given MOCK-BINDINGS established and returns -its first return value, if any. If RECORDP is set, all invocations will -be recorded and returned as the second return value, else NIL." +its return values as a LIST. If RECORDP is set, all invocations will be +recorded and returned as the second return value, else NIL." (let* ((mocks (mock-bindings-mocks mock-bindings)) (functions (mapcar #'car mocks)) (previous (mapcar #'maybe-fdefinition functions))) @@ -41,10 +41,19 @@ be recorded and returned as the second return value, else NIL." mocks previous) (lambda () (values - (funcall function) + (multiple-value-list + (funcall function)) (invocations))) previous)))) +(defmacro with-mocks ((mock-bindings &key (recordp T)) form &body body) + `(multiple-value-bind (,values ,calls) + (call-with-mocks + ,mock-bindings + (lambda () ,form) + :recordp ,recordp) + ,@body)) + (defun register-mock (mock-bindings name) "Registers a mocked function under NAME. The mocked function will return no values. See IF-CALLED to add some behaviour to it."