X-Git-Url: http://repo.macrolet.net/gitweb/?a=blobdiff_plain;f=tests%2Ffacade.lisp;h=ff4840f1d545ac90c5ed106c7b0c5cb0be92d277;hb=e8b227cbde3cf3eeb9b28f347f9ff78acb0cf0a8;hp=c8534cff9edbdca1895e29c6c67e9948cab7e074;hpb=9635bd8a9ea703c1ea60feb8c16984692a6af6c0;p=cl-mock.git diff --git a/tests/facade.lisp b/tests/facade.lisp index c8534cf..ff4840f 100644 --- a/tests/facade.lisp +++ b/tests/facade.lisp @@ -4,115 +4,34 @@ (in-suite cl-mock) -(def-test call-with-mocks.empty () - (is (equal '(T) (call-with-mocks - (make-mock-bindings) - (constantly T))))) - -(def-test call-with-mocks.discards-values () - (is (equal - '((1 2 3) NIL) - (multiple-value-list - (call-with-mocks - (make-mock-bindings) - (lambda () - (values 1 2 3))))))) - -(def-test call-with-mocks.simple () - (declare (notinline foo)) - (defun foo () - (fail "original function binding ~A was called" 'foo)) - (let ((mock-bindings (make-mock-bindings))) - (register-mock mock-bindings 'foo) - (call-with-mocks - mock-bindings - (lambda () - (foo) - (pass))))) - -(def-test call-with-mocks.default-values () - (declare (notinline foo)) - (defun foo () 'foo) - (let ((mock-bindings (make-mock-bindings))) - (register-mock mock-bindings 'foo) - (call-with-mocks - mock-bindings - (lambda () - (is (null (multiple-value-list (foo)))))))) - -(def-test if-called.simple () - (declare (notinline foo)) - (defun foo () 'foo) - (let ((mock-bindings (make-mock-bindings))) - (if-called mock-bindings 'foo (constantly T) (constantly 42)) - (call-with-mocks - mock-bindings - (lambda () - (is (eql 42 (foo))))))) - -(def-test call-with-mocks.invocations () - (declare (notinline foo)) - (defun foo () 'foo) - (let ((mock-bindings (make-mock-bindings))) - (register-mock mock-bindings 'foo) - (is (equal - '(NIL ((foo 1) (foo 2) (foo 3))) - (multiple-value-list - (call-with-mocks - mock-bindings - (lambda () - (foo 1) - (foo 2) - (foo 3)))))))) - -(def-test when-called.simple () - (declare (notinline foo)) - (defun foo () 'foo) - (let ((mock-bindings (make-mock-bindings))) - (when-called mock-bindings foo 42) - (when-called mock-bindings foo 23) - (call-with-mocks - mock-bindings - (lambda () - (is (eql 42 (foo))))))) - -(def-test when-called.literal () - (declare (notinline foo)) - (defun foo () 'foo) - (let ((mock-bindings (make-mock-bindings))) - (when-called mock-bindings (foo 1) 2) - (when-called mock-bindings (foo 2) 3) - (when-called mock-bindings foo 42) - (call-with-mocks - mock-bindings - (lambda () - (is (eql 2 (foo 1))) - (is (eql 2 (foo 1))) - (is (eql 3 (foo 2))) - (is (eql 3 (foo 2))) - (is (eql 42 (foo))) - (is (eql 42 (foo 'foo))))))) - -(def-test when-called.times () - (declare (notinline foo)) - (defun foo () 'foo) - (let ((mock-bindings (make-mock-bindings))) - (when-called mock-bindings foo 1 2 3) - (call-with-mocks - mock-bindings - (lambda () - (is (eql 1 (foo))) - (is (eql 2 (foo))) - (is (eql 3 (foo))) - (is (eql 3 (foo))))))) - -(def-test when-called.call-previous () - (declare (notinline foo)) - (defun foo () 'foo) - (let ((mock-bindings (make-mock-bindings))) - (when-called mock-bindings foo 3 (call-previous)) - (call-with-mocks - mock-bindings - (lambda () - (is (eql 3 (foo))) - (is (eq 'foo (foo))))))) +(def-test answer.simple () + (with-mocks () + (answer (foo 1) 42) + (answer foo 23) + (is (eql 42 (foo 1))))) + +(def-test answer.literal () + (with-mocks () + (answer (foo 1) 2) + (answer (foo 2) 3) + (answer foo 42) + (is (eql 2 (foo 1))) + (is (eql 2 (foo 1))) + (is (eql 3 (foo 2))) + (is (eql 3 (foo 2))) + (is (eql 42 (foo))) + (is (eql 42 (foo 'foo))))) + +(def-test answer.times () + (with-mocks () + (answer foo 1 2 3) + (is (eql 1 (foo))) + (is (eql 2 (foo))) + (is (eql 3 (foo))) + (is (eql 3 (foo))))) + +(def-test answer.call-previous () + (with-mocks () + (answer foo 3 (call-previous)) + (is (eql 3 (foo))) + (is (eq 'foo (foo)))))