:description "Mocking (generic) functions."
:author "Olof-Joachim Frahm <olof@macrolet.net>"
:license "Simplified BSD License"
- :depends-on (#:closer-mop)
+ :depends-on (#:closer-mop #:alexandria)
:in-order-to ((asdf:test-op (asdf:load-op #:cl-mock-tests)))
:perform (asdf:test-op :after (op c)
(funcall (find-symbol (symbol-name '#:run!) '#:fiveam)
(defmacro progm* (methods values &body body)
`(call-with-method-bindings* ,methods ,values (lambda () ,@body)))
+(defun classify (specializer)
+ (if (classp specializer)
+ specializer
+ (find-class specializer)))
+
(defun call-with-method-bindings (methods values function
&optional previous)
(let ((methods
(mapcar (lambda (method)
(destructuring-bind (generic-function qualifiers specializers) method
(list
- (if (functionp generic-function)
- generic-function
- (fdefinition generic-function))
+ (ensure-function generic-function)
qualifiers
- (mapcar (lambda (specializer)
- (if (classp specializer)
- specializer
- (find-class specializer)))
- specializers))))
+ (mapcar #'classify specializers))))
methods)))
(call-with-method-bindings* methods values function (or previous (find-methods methods)))))
(in-package #:cl-user)
(defpackage #:cl-mock
- (:use #:closer-common-lisp)
+ (:use #:closer-common-lisp #:alexandria)
(:export ;;; regular functions
#:dflet