The bytecurry.mocks Reference Manual

This is the bytecurry.mocks Reference Manual, version 1.0.0, generated automatically by Declt version 4.0 beta 2 "William Riker" on Sun Dec 15 04:28:31 2024 GMT+0.

Table of Contents


1 Introduction


2 Systems

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


2.1 bytecurry.mocks

Tools to mock functions for unit tests

Author

Thayne McCombs <>

License

MIT

Version

1.0.0

Defsystem Dependency

bytecurry.asdf-ext (system).

Source

bytecurry.mocks.asd.

Child Components

3 Files

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


3.1 Lisp


3.1.1 bytecurry.mocks/bytecurry.mocks.asd

Source

bytecurry.mocks.asd.

Parent Component

bytecurry.mocks (system).

ASDF Systems

bytecurry.mocks.


3.1.2 bytecurry.mocks/package.lisp

Source

bytecurry.mocks.asd.

Parent Component

bytecurry.mocks (system).

Packages

bytecurry.mocks.


3.1.3 bytecurry.mocks/mocks.lisp

Dependency

package.lisp (file).

Source

bytecurry.mocks.asd.

Parent Component

bytecurry.mocks (system).

Public Interface
Internals

4 Packages

Packages are listed by definition order.


4.1 bytecurry.mocks

Package to provide tools to mock functions
in common lisp unit tests.

Provides WITH-MOCKED-FUNCTIONS, which acts like FLET or LABELS, but shadows functions in the global scope, so that the function bindings are available outside of the lexical scope of the body. See docstring for more information.

Source

package.lisp.

Nickname

mocks

Use List

common-lisp.

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 Macros

Macro: with-added-methods (bindings &body body)

Execute BODY with some extra methods.

This works similarly to WITH-MOCKED-FUNCTIONS. But defines methods instead of functions.
The bindings should look like DEFMETHOD definitions without the defmethod symbol.

One particularly useful scenario is to mock up an instance of a class by using eql specializers
for a local variable.

For now, it only supports adding new methods, not replacing existing methods, since it doesn’t restored the previous method. (mostly because I don’t know a good way to extract the specifiers from the definition form.)

Package

bytecurry.mocks.

Source

mocks.lisp.

Macro: with-mocked-functions (bindings &body body)

Execute BODY with some functions mocked up.

BINDINGS is a list of function bindings, similar to those in FLET or LABELS.
Before executing BODY, the bindings are used to replace the definitions of functions, and after BODY has finished, the original function definitions are restored.

You can use this macro to mock funtions for unit tests. For example, if function A calls function B, you can replace the definition of B while testing A, to isolate the test on just the behavior of A.

There are two things to note when using this macro:
1. You can’t mock functions in a locked package (such as CL)
2. The compiler may inline function calls, in which case changing the definition will have no effect.

Package

bytecurry.mocks.

Source

mocks.lisp.


5.2 Internals


5.2.1 Ordinary functions

Function: %get-binding-names (binding)
Package

bytecurry.mocks.

Source

mocks.lisp.

Function: %let-expr (names)

Get the let binding for a mock function binding

Package

bytecurry.mocks.

Source

mocks.lisp.

Function: %setf-for-binding (binding)

Store the mocked function.

Package

bytecurry.mocks.

Source

mocks.lisp.

Function: %setf-for-original (names)
Package

bytecurry.mocks.

Source

mocks.lisp.


Appendix A Indexes


A.1 Concepts


A.3 Variables