Formatting.
[cl-mock.git] / README.md
1 -*- mode: markdown; coding: utf-8-unix; -*-
2
3 CL-MOCK - Mocking (generic) functions.
4
5 Copyright (C) 2013 Olof-Joachim Frahm
6
7 Release under a Simplified BSD license.
8
9 Working, but unfinished.
10
11 Should be portable thanks to [`CLOSER-MOP`][1].
12
13 Since it is pretty easy to just roll something like this on your own,
14 the main purpose is to develop a nice syntax (lispy, declarative) to
15 keep tests readable and maintainable.
16
17 Some parts may be used independently of the testing facilities,
18 e.g. dynamic `FLET` and method bindings with `PROGM` may be of general
19 interest.
20
21
22 # GENERIC FUNCTIONS
23
24 Since behaviour isn't bound to classes, but to generic functions,
25 creating new classes on the fly isn't particularly interesting.
26
27 We provide the form `PROGM` to bind a number of methods during the
28 execution of its contained body:
29
30     > (progm
31     >     '((baz NIL (list)))
32     >     '((lambda (list) list))
33     >   ...)
34
35 For example:
36
37     > (defclass foo () ())
38     > (defgeneric baz (foo)
39         (:method ((foo foo))
40           42))
41     > (progm '((baz NIL (list)))
42              '((lambda (list) list))
43         (values (baz (make-instance 'foo)) (baz '(1 2 3))))
44     > => 42
45     > => (1 2 3)
46
47
48 # UTILITIES
49
50 `DFLET` dynamically rebinds functions similar to `FLET`:
51
52     > (defun foo () 42)
53     > (defun bar () (foo))
54     > (bar)
55     > => 42
56     > (dflet ((foo () 23))
57     >   (bar))
58     > => 23
59     > (OR) => 42, if FOO was inlined
60
61 The caveat is that this might not work on certain optimization settings,
62 including inlining.
63
64 The underlying function `PROGF` may be used as well similarly to standard
65 `PROG`:
66
67     > (progf '(foo) (list (lambda () 23))
68     >   (bar))
69     > => 23
70     > (OR) => 42, if FOO was inlined
71
72 [1]: http://common-lisp.net/project/closer/closer-mop.html