3 (in-package :it.bese.fiveam)
7 ;;;; When running tests we often need to setup some kind of context
8 ;;;; (create dummy db connections, simulate an http request,
9 ;;;; etc.). Fixtures provide a way to conviently hide this context
10 ;;;; into a macro and allow the test to focus on testing.
12 ;;;; NB: A FiveAM fixture is nothing more than a macro. Since the term
13 ;;;; 'fixture' is so common in testing frameworks we've provided a
14 ;;;; wrapper around defmacro for this purpose.
17 (make-hash-table :test 'eql)
18 "Lookup table mapping fixture names to fixture
21 (defun get-fixture (key &optional default)
22 (gethash key *fixture* default))
24 (defun (setf get-fixture) (value key)
25 (setf (gethash key *fixture*) value))
27 (defun rem-fixture (key)
28 (remhash key *fixture*))
30 (defmacro def-fixture (name (&rest args) &body body)
31 "Defines a fixture named NAME. A fixture is very much like a
32 macro but is used only for simple templating. A fixture created
33 with DEF-FIXTURE is a macro which can use the special macrolet
34 &BODY to specify where the body should go.
36 See Also: WITH-FIXTURE
38 `(eval-when (:compile-toplevel :load-toplevel :execute)
39 (setf (get-fixture ',name) (cons ',args ',body))
42 (defmacro with-fixture (fixture-name (&rest args) &body body)
43 "Insert BODY into the fixture named FIXTURE-NAME.
45 See Also: DEF-FIXTURE"
46 (assert (get-fixture fixture-name)
48 "Unknown fixture ~S." fixture-name)
49 (destructuring-bind ((&rest largs) &rest lbody)
50 (get-fixture fixture-name)
51 `(macrolet ((&body () '(progn ,@body)))
52 (funcall (lambda (,@largs) ,@lbody) ,@args))))
54 ;; Copyright (c) 2002-2003, Edward Marco Baringer
55 ;; All rights reserved.
57 ;; Redistribution and use in source and binary forms, with or without
58 ;; modification, are permitted provided that the following conditions are
61 ;; - Redistributions of source code must retain the above copyright
62 ;; notice, this list of conditions and the following disclaimer.
64 ;; - Redistributions in binary form must reproduce the above copyright
65 ;; notice, this list of conditions and the following disclaimer in the
66 ;; documentation and/or other materials provided with the distribution.
68 ;; - Neither the name of Edward Marco Baringer, nor BESE, nor the names
69 ;; of its contributors may be used to endorse or promote products
70 ;; derived from this software without specific prior written permission.
72 ;; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
73 ;; "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
74 ;; LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
75 ;; A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
76 ;; OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
77 ;; SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
78 ;; LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
79 ;; DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
80 ;; THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
81 ;; (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
82 ;; OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.