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 fuces 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.
16 (deflookup-table fixture
17 :documentation "Lookup table mapping fixture names to fixture
20 (defmacro def-fixture (name args &body body)
21 "Defines a fixture named NAME. A fixture is very much like a
22 macro but is used only for simple templating. A fixture created
23 with DEF-FIXTURE is a macro which can use the special macrolet
24 &BODY to specify where the body should go.
26 See Also: WITH-FIXTURE
28 `(eval-when (:compile-toplevel :load-toplevel :execute)
29 (setf (get-fixture ',name) (cons ',args ',body))
32 (defmacro with-fixture (fixture-name args &body body)
33 "Insert BODY into the fixture named FIXTURE-NAME.
35 See Also: DEF-FIXTURE"
36 (destructuring-bind (largs &rest lbody) (get-fixture fixture-name)
37 `(macrolet ((&body () '(progn ,@body)))
38 (funcall (lambda ,largs ,@lbody) ,@args))))
40 ;; Copyright (c) 2002-2003, Edward Marco Baringer
41 ;; All rights reserved.
43 ;; Redistribution and use in source and binary forms, with or without
44 ;; modification, are permitted provided that the following conditions are
47 ;; - Redistributions of source code must retain the above copyright
48 ;; notice, this list of conditions and the following disclaimer.
50 ;; - Redistributions in binary form must reproduce the above copyright
51 ;; notice, this list of conditions and the following disclaimer in the
52 ;; documentation and/or other materials provided with the distribution.
54 ;; - Neither the name of Edward Marco Baringer, nor BESE, nor the names
55 ;; of its contributors may be used to endorse or promote products
56 ;; derived from this software without specific prior written permission.
58 ;; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
59 ;; "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
60 ;; LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
61 ;; A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
62 ;; OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
63 ;; SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
64 ;; LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
65 ;; DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
66 ;; THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
67 ;; (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
68 ;; OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.