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)
34 (setf (gethash ',name *suites*)
36 ,@(when description `(:description ,description))
37 ,@(when in-p `(:in ',in))
38 ,@(when fixture-p `(:fixture ',fixture))))
41 (defmacro def-suite* (name &rest def-suite-args)
43 (def-suite ,name ,@def-suite-args)
46 (defun make-suite (name &key description ((:in parent-suite)) fixture)
47 "Create a new test suite object.
49 Overrides any existing suite named NAME."
50 (let ((suite (make-instance 'test-suite :name name :fixture fixture)))
52 (setf (description suite) description))
53 (loop for i in (ensure-list parent-suite)
54 for in-suite = (get-test i)
57 (cerror "Create a new suite named ~A." "Unknown suite ~A." i)
58 (setf (get-test in-suite) (make-suite i)
59 in-suite (get-test in-suite)))
60 (setf (gethash name (tests in-suite)) suite)))
61 (setf (get-test name) suite)
64 (defun list-all-suites ()
65 (loop for suite being the hash-value in *suites*
68 ;;;; ** Managing the Current Suite
70 (defvar *suite* (setf (get-test 'NIL)
71 (make-suite 'NIL :description "Default global suite"))
72 "The current test suite object")
74 (defmacro in-suite (suite-name)
75 "Set the *suite* special variable so that all tests defined
76 after the execution of this form are, unless specified otherwise,
77 in the test-suite named SUITE-NAME.
79 See also: DEF-SUITE *SUITE*"
80 `(eval-when (:compile-toplevel :load-toplevel :execute)
81 (%in-suite ,suite-name)))
83 (defmacro in-suite* (suite-name &key in)
84 "Just like in-suite, but silently creates missing suites."
85 `(%in-suite ,suite-name :in ,in :fail-on-error nil))
87 (defmacro %in-suite (suite-name &key (fail-on-error t) in)
90 (if-let (,suite (get-test ',suite-name))
94 (cerror "Create a new suite named ~A."
95 "Unknown suite ~A." ',suite-name))
96 (setf (get-test ',suite-name) (make-suite ',suite-name :in ',in)
97 *suite* (get-test ',suite-name))))
100 ;; Copyright (c) 2002-2003, Edward Marco Baringer
101 ;; All rights reserved.
103 ;; Redistribution and use in source and binary forms, with or without
104 ;; modification, are permitted provided that the following conditions are
107 ;; - Redistributions of source code must retain the above copyright
108 ;; notice, this list of conditions and the following disclaimer.
110 ;; - Redistributions in binary form must reproduce the above copyright
111 ;; notice, this list of conditions and the following disclaimer in the
112 ;; documentation and/or other materials provided with the distribution.
114 ;; - Neither the name of Edward Marco Baringer, nor BESE, nor the names
115 ;; of its contributors may be used to endorse or promote products
116 ;; derived from this software without specific prior written permission.
118 ;; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
119 ;; "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
120 ;; LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
121 ;; A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
122 ;; OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
123 ;; SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
124 ;; LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
125 ;; DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
126 ;; THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
127 ;; (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
128 ;; OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE