-;;; -*- mode: lisp; syntax: common-lisp; coding: utf-8-unix; package: cl-user; -*-
+;; -*- mode: lisp; syntax: common-lisp; coding: utf-8-unix; package: cl-user; -*-
(in-package #:cl-user)
\f
(:file "suite")
(:file "functions")
(:file "facade")
- (:file "methods")))))
\ No newline at end of file
+ (:file "methods")))))
-;;; -*- mode: lisp; syntax: common-lisp; coding: utf-8-unix; package: cl-user; -*-
+;; -*- mode: lisp; syntax: common-lisp; coding: utf-8-unix; package: cl-user; -*-
(in-package #:cl-user)
\f
-;;; -*- 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)
\f
-;;; -*- 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)
\f
-;;; -*- 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)
\f
-;;; -*- 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)
\f
(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)))
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."
-;;; -*- mode: lisp; syntax: common-lisp; coding: utf-8-unix; package: cl-user; -*-
+;; -*- mode: lisp; syntax: common-lisp; coding: utf-8-unix; package: cl-user; -*-
(in-package #:cl-user)
\f
(defpackage #:cl-mock
(:use #:closer-common-lisp #:alexandria)
(:import-from #:arnesi #:with-collector)
- (:export ;;; regular functions
+ (:export ;; regular functions
#:progf
#:dflet
- ;;; mocking of regular functions
- ;;; mocking of generic functions
+ ;; mocking of regular functions
+ ;; mocking of generic functions
))
-;;; -*- mode: lisp; syntax: common-lisp; coding: utf-8-unix; package: cl-mock-tests; -*-
+;; -*- mode: lisp; syntax: common-lisp; coding: utf-8-unix; package: cl-mock-tests; -*-
(in-package #:cl-mock-tests)
\f
-;;; -*- mode: lisp; syntax: common-lisp; coding: utf-8-unix; package: cl-mock-tests; -*-
+;; -*- mode: lisp; syntax: common-lisp; coding: utf-8-unix; package: cl-mock-tests; -*-
(in-package #:cl-mock-tests)
\f
-;;; -*- mode: lisp; syntax: common-lisp; coding: utf-8-unix; package: cl-mock-tests; -*-
+;; -*- mode: lisp; syntax: common-lisp; coding: utf-8-unix; package: cl-mock-tests; -*-
(in-package #:cl-mock-tests)
\f
-;;; -*- mode: lisp; syntax: common-lisp; coding: utf-8-unix; package: cl-user; -*-
+;; -*- mode: lisp; syntax: common-lisp; coding: utf-8-unix; package: cl-user; -*-
(in-package #:cl-user)
\f
(defpackage #:cl-mock-tests
(:use #:cl #:cl-mock #:fiveam)
- (:import-from
- #:cl-mock
- #:call-with-mocks
- #:progm
- #:make-mock-bindings
- #:if-called
- #:when-called
- #:call-previous
- #:register-mock))
+ (:import-from #:cl-mock
+ #:call-with-mocks
+ #:progm
+ #:make-mock-bindings
+ #:if-called
+ #:when-called
+ #:call-previous
+ #:register-mock))