3 (in-package :it.bese.FiveAM)
7 ;;;; Test suites allow us to collect multiple tests into a single
8 ;;;; object and run them all using asingle name. Test suites do not
9 ;;;; affect the way test are run nor the way the results are handled,
10 ;;;; they are simply a test organizing group.
12 ;;;; Test suites can contain both tests and other test suites. Running
13 ;;;; a test suite causes all of its tests and test suites to be
14 ;;;; run. Suites do not affect test dependencies, running a test suite
15 ;;;; can cause tests which are not in the suite to be run.
17 ;;;; ** Creating Suits
19 (defmacro def-suite (name &key description in default-test-args)
20 "Define a new test-suite named NAME.
22 IN (a symbol), if provided, causes this suite te be nested in the
23 suite named by IN. NB: This macro is built on top of make-suite,
24 as such it, like make-suite, will overrwrite any existing suite
27 DEFAULT-TEST-ARGS, if provided, will ba passed to the TEST forms
28 defined in this suite."
29 `(eval-when (:compile-toplevel :load-toplevel :execute)
31 ,@(when description `(:description ,description))
32 ,@(when in `(:in ',in))
33 ,@(when default-test-args `(:default-test-args ,default-test-args)))
36 (defmacro def-suite* (name &rest def-suite-args)
38 (def-suite ,name ,@def-suite-args)
41 (defun make-suite (name &key description in default-test-args)
42 "Create a new test suite object.
44 Overides any existing suite named NAME."
45 (let ((suite (make-instance 'test-suite :name name :default-test-args default-test-args)))
47 (setf (description suite) description))
48 (loop for i in (ensure-list in)
49 for in-suite = (get-test i)
52 (cerror "Create a new suite named ~A." "Unknown suite ~A." i)
53 (setf (get-test in-suite) (make-suite i)
54 in-suite (get-test in-suite)))
55 (setf (gethash name (tests in-suite)) suite)))
56 (setf (get-test name) suite)
59 ;;;; ** Managing the Current Suite
61 (defvar *suite* (setf (get-test 'NIL)
62 (make-suite 'NIL :description "Global Suite"))
63 "The current test suite object")
65 (defmacro in-suite (suite-name)
66 "Set the *suite* special variable so that all tests defined
67 after the execution of this form are, unless specified otherwise,
68 in the test-suite named SUITE-NAME.
70 See also: DEF-SUITE *SUITE*"
71 `(eval-when (:compile-toplevel :load-toplevel :execute)
72 (%in-suite ,suite-name)))
74 (defmacro in-suite* (suite-name &key in)
75 "Just like in-suite, but silently creates missing suites."
76 `(%in-suite ,suite-name :in ,in :fail-on-error nil))
78 (defmacro %in-suite (suite-name &key (fail-on-error t) in)
79 (with-unique-names (suite)
81 (if-bind ,suite (get-test ',suite-name)
85 (cerror "Create a new suite named ~A."
86 "Unkown suite ~A." ',suite-name))
87 (setf (get-test ',suite-name) (make-suite ',suite-name :in ',in)
88 *suite* (get-test ',suite-name))))
91 ;; Copyright (c) 2002-2003, Edward Marco Baringer
92 ;; All rights reserved.
94 ;; Redistribution and use in source and binary forms, with or without
95 ;; modification, are permitted provided that the following conditions are
98 ;; - Redistributions of source code must retain the above copyright
99 ;; notice, this list of conditions and the following disclaimer.
101 ;; - Redistributions in binary form must reproduce the above copyright
102 ;; notice, this list of conditions and the following disclaimer in the
103 ;; documentation and/or other materials provided with the distribution.
105 ;; - Neither the name of Edward Marco Baringer, nor BESE, nor the names
106 ;; of its contributors may be used to endorse or promote products
107 ;; derived from this software without specific prior written permission.
109 ;; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
110 ;; "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
111 ;; LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
112 ;; A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
113 ;; OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
114 ;; SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
115 ;; LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
116 ;; DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
117 ;; THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
118 ;; (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
119 ;; OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE