1 ;;;; -*- Mode: Lisp; indent-tabs-mode: nil -*-
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 (defvar *suites* (make-hash-table :test 'eql))
21 (defmacro def-suite (name &key description (in nil in-p) (fixture nil fixture-p))
22 "Define a new test-suite named NAME.
24 IN (a symbol), if provided, causes this suite te be nested in the
25 suite named by IN. NB: This macro is built on top of make-suite,
26 as such it, like make-suite, will overrwrite any existing suite
29 DESCRIPTION is just a string.
31 FIXTURE is the fixture argument (exactly like the :fixture argument to
32 def-test) to pass to tests in this suite."
33 `(eval-when (:compile-toplevel :load-toplevel :execute)
35 ,@(when description `(:description ,description))
36 ,@(when in-p `(:in ',in))
37 ,@(when fixture-p `(:fixture ',fixture)))
40 (defmacro def-suite* (name &rest def-suite-args)
42 (def-suite ,name ,@def-suite-args)
45 (defun remove-from-suites (test-name)
46 (when (get-test test-name)
47 ;; if this suite alruady exists, and its :IN some other suite, remove it.
48 (dolist (s (list-all-suites))
49 (when (gethash test-name (tests s))
50 (remhash test-name (tests s))))))
52 (defun make-suite (name &key description ((:in parent-suite) *suite*) fixture)
53 "Create a new test suite object.
55 Overrides any existing suite named NAME."
56 (remove-from-suites name)
57 (let ((suite (make-instance 'test-suite :name name :fixture fixture)))
59 (setf (description suite) description))
60 (setf (gethash name *suites*) suite)
61 (loop for i in (ensure-list parent-suite)
62 for in-suite = (get-test i)
65 (cerror "Create a new suite named ~A." "Unknown suite ~A." i)
66 (setf (get-test in-suite) (make-suite i)
67 in-suite (get-test in-suite)))
68 (setf (gethash name (tests in-suite)) suite)))
69 (setf (get-test name) suite)
72 (defun list-all-suites ()
73 (loop for suite being the hash-value in *suites*
76 ;;;; ** Managing the Current Suite
78 (defvar *suite* (setf (get-test 'T) (make-suite 'T :description "Default global suite" :in nil))
79 "The current test suite object")
81 (defmacro in-suite (suite-name)
82 "Set the *suite* special variable so that all tests defined
83 after the execution of this form are, unless specified otherwise,
84 in the test-suite named SUITE-NAME.
86 See also: DEF-SUITE *SUITE*"
87 `(eval-when (:compile-toplevel :load-toplevel :execute)
88 (%in-suite ,suite-name)))
90 (defmacro in-suite* (suite-name &key (in nil in-p))
91 "Just like in-suite, but silently creates missing suites."
92 `(%in-suite ,suite-name
93 ,@(when in-p `(:in ,in))
96 (defmacro %in-suite (suite-name &key (fail-on-error t) (in nil in-p))
99 (if-let (,suite (get-test ',suite-name))
100 (setf *suite* ,suite)
103 (cerror "Create a new suite named ~A."
104 "Unknown suite ~A." ',suite-name))
105 (setf (get-test ',suite-name) (make-suite ',suite-name ,@(when in-p `(:in ',in)))
106 *suite* (get-test ',suite-name))))
109 ;; Copyright (c) 2002-2003, Edward Marco Baringer
110 ;; All rights reserved.
112 ;; Redistribution and use in source and binary forms, with or without
113 ;; modification, are permitted provided that the following conditions are
116 ;; - Redistributions of source code must retain the above copyright
117 ;; notice, this list of conditions and the following disclaimer.
119 ;; - Redistributions in binary form must reproduce the above copyright
120 ;; notice, this list of conditions and the following disclaimer in the
121 ;; documentation and/or other materials provided with the distribution.
123 ;; - Neither the name of Edward Marco Baringer, nor BESE, nor the names
124 ;; of its contributors may be used to endorse or promote products
125 ;; derived from this software without specific prior written permission.
127 ;; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
128 ;; "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
129 ;; LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
130 ;; A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
131 ;; OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
132 ;; SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
133 ;; LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
134 ;; DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
135 ;; THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
136 ;; (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
137 ;; OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE