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