Next: Introduction, Previous: (dir), Up: (dir) [Contents][Index]
This is the mockingbird Reference Manual, version 0.1, generated automatically by Declt version 3.0 "Montgomery Scott" on Tue Dec 22 14:25:50 2020 GMT+0.
• Introduction | What mockingbird is all about | |
• Systems | The systems documentation | |
• Files | The files documentation | |
• Packages | The packages documentation | |
• Definitions | The symbols documentation | |
• Indexes | Concepts, functions, variables and data types |
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.
(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.
Clone this repository and put into asdf load path then
(ql:quickload :mockingbird)
To run tests:
(ql:test-system :mockingbird)
Copyright (c) 2016 Christopher Eames (Chream) (chream@gmx.com)
Next: Files, Previous: Introduction, Up: Top [Contents][Index]
The main system appears first, followed by any subsystem dependency.
• The mockingbird system | ||
• The mockingbird/src/all system | ||
• The mockingbird/src/methods system | ||
• The mockingbird/src/functions system |
Next: The mockingbird/src/all system, Previous: Systems, Up: Systems [Contents][Index]
Christopher Eames (Chream)
MIT
# 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)
0.1
mockingbird/src/all (system)
mockingbird.asd (file)
Next: The mockingbird/src/methods system, Previous: The mockingbird system, Up: Systems [Contents][Index]
Christopher Eames (Chream)
MIT
mockingbird.asd (file)
lisp.lisp (file)
Next: The mockingbird/src/functions system, Previous: The mockingbird/src/all system, Up: Systems [Contents][Index]
Christopher Eames (Chream)
MIT
mockingbird.asd (file)
lisp.lisp (file)
Previous: The mockingbird/src/methods system, Up: Systems [Contents][Index]
Christopher Eames (Chream)
MIT
mockingbird.asd (file)
lisp.lisp (file)
Files are sorted by type and then listed depth-first from the systems components trees.
• Lisp files |
• The mockingbird.asd file | ||
• The mockingbird/src/all/lisp.lisp file | ||
• The mockingbird/src/methods/lisp.lisp file | ||
• The mockingbird/src/functions/lisp.lisp file |
Next: The mockingbird/src/all/lisp․lisp file, Previous: Lisp files, Up: Lisp files [Contents][Index]
mockingbird.asd
Next: The mockingbird/src/methods/lisp․lisp file, Previous: The mockingbird․asd file, Up: Lisp files [Contents][Index]
mockingbird/src/all (system)
src/all.lisp
Next: The mockingbird/src/functions/lisp․lisp file, Previous: The mockingbird/src/all/lisp․lisp file, Up: Lisp files [Contents][Index]
mockingbird/src/methods (system)
src/methods.lisp
Previous: The mockingbird/src/methods/lisp․lisp file, Up: Lisp files [Contents][Index]
mockingbird/src/functions (system)
src/functions.lisp
Next: Definitions, Previous: Files, Up: Top [Contents][Index]
Packages are listed by definition order.
• The mockingbird/src/all package | ||
• The mockingbird/src/methods package | ||
• The mockingbird-asd package | ||
• The mockingbird/src/functions package |
Next: The mockingbird/src/methods package, Previous: Packages, Up: Packages [Contents][Index]
lisp.lisp (file)
Next: The mockingbird-asd package, Previous: The mockingbird/src/all package, Up: Packages [Contents][Index]
lisp.lisp (file)
Next: The mockingbird/src/functions package, Previous: The mockingbird/src/methods package, Up: Packages [Contents][Index]
mockingbird.asd
Previous: The mockingbird-asd package, Up: Packages [Contents][Index]
lisp.lisp (file)
mb.functions
Definitions are sorted by export status, category, package, and then by lexicographic order.
• Exported definitions | ||
• Internal definitions |
Next: Internal definitions, Previous: Definitions, Up: Definitions [Contents][Index]
• Exported special variables | ||
• Exported macros | ||
• Exported functions | ||
• Exported generic functions |
Next: Exported macros, Previous: Exported definitions, Up: Exported definitions [Contents][Index]
lisp.lisp (file)
Next: Exported functions, Previous: Exported special variables, Up: Exported definitions [Contents][Index]
lisp.lisp (file)
lisp.lisp (file)
lisp.lisp (file)
lisp.lisp (file)
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*.
lisp.lisp (file)
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*.
lisp.lisp (file)
Next: Exported generic functions, Previous: Exported macros, Up: Exported definitions [Contents][Index]
lisp.lisp (file)
lisp.lisp (file)
lisp.lisp (file)
lisp.lisp (file)
lisp.lisp (file)
lisp.lisp (file)
lisp.lisp (file)
lisp.lisp (file)
lisp.lisp (file)
lisp.lisp (file)
The error function for undefined-stub-function.
lisp.lisp (file)
lisp.lisp (file)
lisp.lisp (file)
Previous: Exported functions, Up: Exported definitions [Contents][Index]
lisp.lisp (file)
lisp.lisp (file)
lisp.lisp (file)
lisp.lisp (file)
Previous: Exported definitions, Up: Definitions [Contents][Index]
• Internal functions | ||
• Internal generic functions | ||
• Internal conditions |
Next: Internal generic functions, Previous: Internal definitions, Up: Internal definitions [Contents][Index]
lisp.lisp (file)
lisp.lisp (file)
lisp.lisp (file)
Accessor function for the special *mock-calls* variable. Returns the value associated with the function.
lisp.lisp (file)
Accessor function for the special *mock-calls* variable. Returns the full spec.
lisp.lisp (file)
lisp.lisp (file)
lisp.lisp (file)
lisp.lisp (file)
lisp.lisp (file)
lisp.lisp (file)
lisp.lisp (file)
The error function for undefined-stub-function.
lisp.lisp (file)
Next: Internal conditions, Previous: Internal functions, Up: Internal definitions [Contents][Index]
lisp.lisp (file)
lisp.lisp (file)
lisp.lisp (file)
Previous: Internal generic functions, Up: Internal definitions [Contents][Index]
Error:
lisp.lisp (file)
undefined-function (condition)
Error:
lisp.lisp (file)
undefined-function (condition)
undefined-stub-error-specializers (method)
:specializers
undefined-stub-error-specializers (generic function)
Previous: Definitions, Up: Top [Contents][Index]
• Concept index | ||
• Function index | ||
• Variable index | ||
• Data type index |
Next: Function index, Previous: Indexes, Up: Indexes [Contents][Index]
Jump to: | F L M |
---|
Jump to: | F L M |
---|
Next: Variable index, Previous: Concept index, Up: Indexes [Contents][Index]
Jump to: | A C D F G M N R S U V W |
---|
Jump to: | A C D F G M N R S U V W |
---|
Next: Data type index, Previous: Function index, Up: Indexes [Contents][Index]
Jump to: | *
S |
---|
Index Entry | Section | ||
---|---|---|---|
| |||
* | |||
*mock-calls* : | Exported special variables | ||
| |||
S | |||
Slot, specializers : | Internal conditions | ||
Special Variable, *mock-calls* : | Exported special variables | ||
specializers : | Internal conditions | ||
|
Jump to: | *
S |
---|
Previous: Variable index, Up: Indexes [Contents][Index]
Jump to: | C M P S U |
---|
Jump to: | C M P S U |
---|