The mockingbird Reference Manual

This is the mockingbird Reference Manual, version 0.1, generated automatically by Declt version 4.0 beta 2 "William Riker" on Mon Feb 26 17:22:08 2024 GMT+0.

Table of Contents


1 Introduction


2 Systems

The main system appears first, followed by any subsystem dependency.


2.1 mockingbird

Author

Christopher Eames (Chream)

License

MIT

Long Description

# Mockingbird

This package provides some useful stubbing and mocking macros for unit testing. Used when specified functions in a test should not be computed but should instead return a provided constant value.

This library was called cl-mock before but is/was NOT the library called "cl-mock" on quicklisp. I have now changed the name.

## Usage
“‘
(in-package :cl-user)
(uiop:define-package :my-project
(:use :closer-common-lisp
:prove
:mockingbird))
(in-package :my-project)

(defun foo (x) x)
(defun bar (x y) (+ x (foo x)))

(with-stubs ((foo 10))
(is (foo 1 2) 10)) ;; –> T
(is (bar 1 2) 2)) ;; –> T Only lexically stubbed!

(with-dynamic-stubs ((foo 10))
(is (foo 1 2) 10)) ;; –> T
(is (bar 1 2) 11)) ;; –> T Dynamically stubbed!

(with-mocks (foo bar)
(is (foo 5) nil) ;; –> T
(is (bar 10) nil)) ;; –> T Args dont need to match!

(with-dynamic-mocks (foo bar)
...)
“‘

The arguments passed to mocked or stubbed functions are also saved.

“‘
(with-stubs ((foo 5))
(foo 4 5)
(call-times-for ’foo) ;; –> 1
(verify-call-times-for ’foo 1) ;; –> T
(nth-mock-args-for 1 ’foo) ;; –> ’(4 5)
(verify-nth-call-args-for 1 ’foo 4 5) ;; –> T
(verify-first-call-args-for ’foo 4 5) ;; –> T
(clear-calls)) ;; –> no-value
“‘

These also work for the dynamic and mocking variants.

——————————————————————-

It is also possible to mock/stub individual methods.

“‘
(with-method-stubs ((foo (x y) ’is-stubbed)
(foo ((x aclass) (y aclass)) ’aclass-stubbed)
...)

“‘

The calls to methods are currently NOT saved so the above verification functions can not be used.

## Installation

Clone this repository and put into asdf load path then
“‘
(ql:quickload :mockingbird)
“‘

To run tests:
“‘
(ql:test-system :mockingbird)
“‘

## Author

* Christopher Eames (Chream) (chream@gmx.com)

## Copyright

Copyright (c) 2016 Christopher Eames (Chream) (chream@gmx.com)

Version

0.1

Dependency

mockingbird/src/all (system).

Source

mockingbird.asd.


2.2 mockingbird/src/all

Author

Christopher Eames (Chream)

License

MIT

Dependencies
Source

mockingbird.asd.


2.3 mockingbird/src/functions

Author

Christopher Eames (Chream)

License

MIT

Dependencies
  • closer-mop (system).
  • fare-utils (system).
  • alexandria (system).
  • trivial-arguments (system).
Source

mockingbird.asd.


2.4 mockingbird/src/methods

Author

Christopher Eames (Chream)

License

MIT

Dependencies
Source

mockingbird.asd.


3 Files

Files are sorted by type and then listed depth-first from the systems components trees.


3.1 Lisp


3.1.1 mockingbird/mockingbird.asd

Source

mockingbird.asd.

Parent Component

mockingbird (system).

ASDF Systems
Packages

mockingbird-asd.


3.1.2 mockingbird/src/all/file-type.lisp

Source

mockingbird.asd.

Parent Component

mockingbird/src/all (system).

Packages

mockingbird/src/all.


3.1.3 mockingbird/src/functions/file-type.lisp

Source

mockingbird.asd.

Parent Component

mockingbird/src/functions (system).

Packages

mockingbird/src/functions.

Public Interface
Internals

3.1.4 mockingbird/src/methods/file-type.lisp

Source

mockingbird.asd.

Parent Component

mockingbird/src/methods (system).

Packages

mockingbird/src/methods.

Public Interface
Internals

4 Packages

Packages are listed by definition order.


4.1 mockingbird-asd

Source

mockingbird.asd.

Use List
  • asdf/interface.
  • common-lisp.

4.2 mockingbird/src/all

Source

file-type.lisp.

Nicknames
  • mockingbird
  • mb
Use List

4.3 mockingbird/src/functions

Source

file-type.lisp.

Nickname

mb.functions

Use List
  • alexandria.
  • closer-common-lisp.
  • fare-utils.
  • uiop/driver.
Used By List

mockingbird/src/all.

Public Interface
Internals

4.4 mockingbird/src/methods

Source

file-type.lisp.

Use List
  • alexandria.
  • closer-common-lisp.
  • fare-utils.
  • uiop/driver.
Used By List

mockingbird/src/all.

Public Interface
Internals

5 Definitions

Definitions are sorted by export status, category, package, and then by lexicographic order.


5.1 Public Interface


5.1.1 Special variables

Special Variable: *mock-calls*
Package

mockingbird/src/functions.

Source

file-type.lisp.


5.1.2 Macros

Macro: verify-first-call-args-for (fn-name &rest args)
Package

mockingbird/src/functions.

Source

file-type.lisp.

Macro: with-dynamic-mocks ((&rest fn-names) &body body)
Package

mockingbird/src/functions.

Source

file-type.lisp.

Macro: with-dynamic-stubs ((&rest fdefs) &body body)
Package

mockingbird/src/functions.

Source

file-type.lisp.

Macro: with-method-stubs ((&rest method-defs) &body body)
Package

mockingbird/src/methods.

Source

file-type.lisp.

Macro: with-mocks ((&rest fn-names) &body body)

The mock macro. Lexically binds a new mock function which will return nil. Calls are counted and the arguments are saved in the dynamic variable *mock-calls*.

Package

mockingbird/src/functions.

Source

file-type.lisp.

Macro: with-stubs ((&rest fdefs) &body body)

The stub macro. Lexically binds a new stub function in place and returns a constant supplied value. Calls are counted and the arguments are saved in the dynamic variable *mock-calls*.

Package

mockingbird/src/functions.

Source

file-type.lisp.


5.1.3 Ordinary functions

Function: add-methods-for (generic-function-object applicable-methods-objects)
Package

mockingbird/src/methods.

Source

file-type.lisp.

Function: applicable-methods-metaobjects-from (method-defs)
Package

mockingbird/src/methods.

Source

file-type.lisp.

Function: call-times-for (fn-name)
Package

mockingbird/src/functions.

Source

file-type.lisp.

Function: clear-calls ()
Package

mockingbird/src/functions.

Source

file-type.lisp.

Function: gf-metaobjects-from (method-defs)
Package

mockingbird/src/methods.

Source

file-type.lisp.

Function: method-metaobjects-from (method-defs)
Package

mockingbird/src/methods.

Source

file-type.lisp.

Function: method-spec-from (method-defs)
Package

mockingbird/src/methods.

Source

file-type.lisp.

Function: nth-mock-args-for (n fn-name)
Package

mockingbird/src/functions.

Source

file-type.lisp.

Function: remove-methods-for (generic-function-object applicable-methods-objects)
Package

mockingbird/src/methods.

Source

file-type.lisp.

Function: specializers/list-from (method-objects)
Package

mockingbird/src/methods.

Source

file-type.lisp.

Function: undefined-stub-function-error (name)

The error function for undefined-stub-function.

Package

mockingbird/src/functions.

Source

file-type.lisp.

Function: verify-call-times-for (fn-name number)
Package

mockingbird/src/functions.

Source

file-type.lisp.

Function: verify-nth-call-args-for (n fn-name &rest args)
Package

mockingbird/src/functions.

Source

file-type.lisp.


5.1.4 Generic functions

Generic Function: generic-function-method-combination-options (generic-functions)
Package

mockingbird/src/methods.

Source

file-type.lisp.

Methods
Method: generic-function-method-combination-options ((object generic-function))
Generic Function: generic-function-method-combination-type-name (generic-functions)
Package

mockingbird/src/methods.

Source

file-type.lisp.

Methods
Method: generic-function-method-combination-type-name ((object generic-function))
Generic Function: method-combination-options (object)
Package

mockingbird/src/methods.

Methods
Method: method-combination-options ((object method-combination))
Source

file-type.lisp.

Generic Function: method-combination-type-name (method-combination)
Package

mockingbird/src/methods.

Source

file-type.lisp.

Methods
Method: method-combination-type-name ((object method-combination))

5.2 Internals


5.2.1 Ordinary functions

Function: defined-fns-bound-p (fdefs)
Package

mockingbird/src/functions.

Source

file-type.lisp.

Function: flet-spec (fn-defs)
Package

mockingbird/src/functions.

Source

file-type.lisp.

Function: fn-names-from (fdefs)
Package

mockingbird/src/functions.

Source

file-type.lisp.

Function: mock-calls-for (fn-name)

Accessor function for the special *mock-calls* variable. Returns the value associated with the function.

Package

mockingbird/src/functions.

Source

file-type.lisp.

Function: mock-calls-spec-for (fn-name)

Accessor function for the special *mock-calls* variable. Returns the full spec.

Package

mockingbird/src/functions.

Source

file-type.lisp.

Function: mock-fn-registered-p (fn)
Package

mockingbird/src/functions.

Source

file-type.lisp.

Function: rebind-original-fn-bindings-spec (fdefs temp-fn-vars)
Package

mockingbird/src/functions.

Source

file-type.lisp.

Function: register-mock-call-for (fn args)
Package

mockingbird/src/functions.

Source

file-type.lisp.

Function: replace-fn-bindings-spec (fdefs temp-fn-vars)
Package

mockingbird/src/functions.

Source

file-type.lisp.

Function: returns-from (fdefs)
Package

mockingbird/src/functions.

Source

file-type.lisp.

Function: stub-fns-from (fdefs)
Package

mockingbird/src/functions.

Source

file-type.lisp.

Function: undefined-stub-method-error (name specializers)

The error function for undefined-stub-function.

Package

mockingbird/src/methods.

Source

file-type.lisp.


5.2.2 Generic functions

Generic Function: filter-applicable-methods (method-comb-spec comb-options method-objects specializers)
Package

mockingbird/src/methods.

Source

file-type.lisp.

Methods
Method: filter-applicable-methods (method-comb comb-options method-objects specializers)
Method: filter-applicable-methods ((method-comb-spec (eql standard)) comb-options all-applicable-methods specializers)
Generic Function: method-combination-type-options (method-combination)
Package

mockingbird/src/methods.

Source

file-type.lisp.

Generic Reader: undefined-stub-error-specializers (condition)
Package

mockingbird/src/methods.

Methods
Reader Method: undefined-stub-error-specializers ((condition undefined-stub-method))
Source

file-type.lisp.

Target Slot

specializers.


5.2.3 Conditions

Condition: undefined-stub-function

Error:

Package

mockingbird/src/functions.

Source

file-type.lisp.

Direct superclasses

undefined-function.

Condition: undefined-stub-method

Error:

Package

mockingbird/src/functions.

Source

file-type.lisp.

Direct superclasses

undefined-function.

Direct methods

undefined-stub-error-specializers.

Direct slots
Slot: specializers
Package

mockingbird/src/methods.

Initargs

:specializers

Readers

undefined-stub-error-specializers.

Writers

This slot is read-only.


Appendix A Indexes


A.1 Concepts


A.2 Functions

Jump to:   A   C   D   F   G   M   N   R   S   U   V   W  
Index Entry  Section

A
add-methods-for: Public ordinary functions
applicable-methods-metaobjects-from: Public ordinary functions

C
call-times-for: Public ordinary functions
clear-calls: Public ordinary functions

D
defined-fns-bound-p: Private ordinary functions

F
filter-applicable-methods: Private generic functions
filter-applicable-methods: Private generic functions
filter-applicable-methods: Private generic functions
flet-spec: Private ordinary functions
fn-names-from: Private ordinary functions
Function, add-methods-for: Public ordinary functions
Function, applicable-methods-metaobjects-from: Public ordinary functions
Function, call-times-for: Public ordinary functions
Function, clear-calls: Public ordinary functions
Function, defined-fns-bound-p: Private ordinary functions
Function, flet-spec: Private ordinary functions
Function, fn-names-from: Private ordinary functions
Function, gf-metaobjects-from: Public ordinary functions
Function, method-metaobjects-from: Public ordinary functions
Function, method-spec-from: Public ordinary functions
Function, mock-calls-for: Private ordinary functions
Function, mock-calls-spec-for: Private ordinary functions
Function, mock-fn-registered-p: Private ordinary functions
Function, nth-mock-args-for: Public ordinary functions
Function, rebind-original-fn-bindings-spec: Private ordinary functions
Function, register-mock-call-for: Private ordinary functions
Function, remove-methods-for: Public ordinary functions
Function, replace-fn-bindings-spec: Private ordinary functions
Function, returns-from: Private ordinary functions
Function, specializers/list-from: Public ordinary functions
Function, stub-fns-from: Private ordinary functions
Function, undefined-stub-function-error: Public ordinary functions
Function, undefined-stub-method-error: Private ordinary functions
Function, verify-call-times-for: Public ordinary functions
Function, verify-nth-call-args-for: Public ordinary functions

G
Generic Function, filter-applicable-methods: Private generic functions
Generic Function, generic-function-method-combination-options: Public generic functions
Generic Function, generic-function-method-combination-type-name: Public generic functions
Generic Function, method-combination-options: Public generic functions
Generic Function, method-combination-type-name: Public generic functions
Generic Function, method-combination-type-options: Private generic functions
Generic Function, undefined-stub-error-specializers: Private generic functions
generic-function-method-combination-options: Public generic functions
generic-function-method-combination-options: Public generic functions
generic-function-method-combination-type-name: Public generic functions
generic-function-method-combination-type-name: Public generic functions
gf-metaobjects-from: Public ordinary functions

M
Macro, verify-first-call-args-for: Public macros
Macro, with-dynamic-mocks: Public macros
Macro, with-dynamic-stubs: Public macros
Macro, with-method-stubs: Public macros
Macro, with-mocks: Public macros
Macro, with-stubs: Public macros
Method, filter-applicable-methods: Private generic functions
Method, filter-applicable-methods: Private generic functions
Method, generic-function-method-combination-options: Public generic functions
Method, generic-function-method-combination-type-name: Public generic functions
Method, method-combination-options: Public generic functions
Method, method-combination-type-name: Public generic functions
Method, undefined-stub-error-specializers: Private generic functions
method-combination-options: Public generic functions
method-combination-options: Public generic functions
method-combination-type-name: Public generic functions
method-combination-type-name: Public generic functions
method-combination-type-options: Private generic functions
method-metaobjects-from: Public ordinary functions
method-spec-from: Public ordinary functions
mock-calls-for: Private ordinary functions
mock-calls-spec-for: Private ordinary functions
mock-fn-registered-p: Private ordinary functions

N
nth-mock-args-for: Public ordinary functions

R
rebind-original-fn-bindings-spec: Private ordinary functions
register-mock-call-for: Private ordinary functions
remove-methods-for: Public ordinary functions
replace-fn-bindings-spec: Private ordinary functions
returns-from: Private ordinary functions

S
specializers/list-from: Public ordinary functions
stub-fns-from: Private ordinary functions

U
undefined-stub-error-specializers: Private generic functions
undefined-stub-error-specializers: Private generic functions
undefined-stub-function-error: Public ordinary functions
undefined-stub-method-error: Private ordinary functions

V
verify-call-times-for: Public ordinary functions
verify-first-call-args-for: Public macros
verify-nth-call-args-for: Public ordinary functions

W
with-dynamic-mocks: Public macros
with-dynamic-stubs: Public macros
with-method-stubs: Public macros
with-mocks: Public macros
with-stubs: Public macros


A.4 Data types

Jump to:   C   F   M   P   S   U  
Index Entry  Section

C
Condition, undefined-stub-function: Private conditions
Condition, undefined-stub-method: Private conditions

F
File, file-type.lisp: The mockingbird/src/all/file-type․lisp file
File, file-type.lisp: The mockingbird/src/functions/file-type․lisp file
File, file-type.lisp: The mockingbird/src/methods/file-type․lisp file
File, mockingbird.asd: The mockingbird/mockingbird․asd file
file-type.lisp: The mockingbird/src/all/file-type․lisp file
file-type.lisp: The mockingbird/src/functions/file-type․lisp file
file-type.lisp: The mockingbird/src/methods/file-type․lisp file

M
mockingbird: The mockingbird system
mockingbird-asd: The mockingbird-asd package
mockingbird.asd: The mockingbird/mockingbird․asd file
mockingbird/src/all: The mockingbird/src/all system
mockingbird/src/all: The mockingbird/src/all package
mockingbird/src/functions: The mockingbird/src/functions system
mockingbird/src/functions: The mockingbird/src/functions package
mockingbird/src/methods: The mockingbird/src/methods system
mockingbird/src/methods: The mockingbird/src/methods package

P
Package, mockingbird-asd: The mockingbird-asd package
Package, mockingbird/src/all: The mockingbird/src/all package
Package, mockingbird/src/functions: The mockingbird/src/functions package
Package, mockingbird/src/methods: The mockingbird/src/methods package

S
System, mockingbird: The mockingbird system
System, mockingbird/src/all: The mockingbird/src/all system
System, mockingbird/src/functions: The mockingbird/src/functions system
System, mockingbird/src/methods: The mockingbird/src/methods system

U
undefined-stub-function: Private conditions
undefined-stub-method: Private conditions