1 ;;; -*- mode: lisp; syntax: common-lisp; coding: utf-8-unix; package: cl-mock-tests; -*-
3 (in-package #:cl-mock-tests)
5 (import 'cl-mock::(call-with-mocks make-mock-bindings register-mock if-called when-called call-previous))
7 (def-test call-with-mocks.empty ()
8 (is (eq T (call-with-mocks
12 (def-test call-with-mocks.discards-values ()
21 (def-test call-with-mocks.simple ()
22 (declare (notinline foo))
24 (fail "original function binding ~A was called" 'foo))
25 (let ((mock-bindings (make-mock-bindings)))
26 (register-mock mock-bindings 'foo)
33 (def-test call-with-mocks.default-values ()
34 (declare (notinline foo))
36 (let ((mock-bindings (make-mock-bindings)))
37 (register-mock mock-bindings 'foo)
41 (is (null (multiple-value-list (foo))))))))
43 (def-test if-called.simple ()
44 (declare (notinline foo))
46 (let ((mock-bindings (make-mock-bindings)))
47 (if-called mock-bindings 'foo (constantly T) (constantly 42))
51 (is (eql 42 (foo)))))))
53 (def-test call-with-mocks.invocations ()
54 (declare (notinline foo))
56 (let ((mock-bindings (make-mock-bindings)))
57 (register-mock mock-bindings 'foo)
59 '(NIL ((foo 1) (foo 2) (foo 3)))
68 (def-test when-called.simple ()
69 (declare (notinline foo))
71 (let ((mock-bindings (make-mock-bindings)))
72 (when-called mock-bindings foo 42)
73 (when-called mock-bindings foo 23)
77 (is (eql 42 (foo)))))))
79 (def-test when-called.literal ()
80 (declare (notinline foo))
82 (let ((mock-bindings (make-mock-bindings)))
83 (when-called mock-bindings (foo 1) 2)
84 (when-called mock-bindings (foo 2) 3)
85 (when-called mock-bindings foo 42)
94 (is (eql 42 (foo 'foo)))))))
96 (def-test when-called.times ()
97 (declare (notinline foo))
99 (let ((mock-bindings (make-mock-bindings)))
100 (when-called mock-bindings foo 1 2 3)
107 (is (eql 3 (foo)))))))
109 (def-test when-called.call-previous ()
110 (declare (notinline foo))
112 (let ((mock-bindings (make-mock-bindings)))
113 (when-called mock-bindings foo 3 (call-previous))
118 (is (eq 'foo (foo)))))))