0118e1a5012c5b3324a04cc9cc5436219559a3cb
[fiveam.git] / src / suite.lisp
1 ;; -*- lisp -*-
2
3 (in-package :it.bese.FiveAM)
4
5 ;;;; * Test Suites
6
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.
11
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.
16
17 ;;;; ** Creating Suits
18
19 (defmacro def-suite (name &key description in)
20   "Define a new test-suite named NAME.
21
22 IN (a symbol), if provided, causes this suite te be nested in the
23 suite named by IN."
24   `(progn
25      (make-suite ',name
26                  ,@(when description `(:description ,description))
27                  ,@(when in `(:in ',in)))
28      ',name))
29
30 (defun make-suite (name &key description in)
31   "Create a new test suite object."
32   (let ((suite (make-instance 'test-suite :name name)))
33     (when description
34       (setf (description suite) description))
35     (loop for i in (ensure-list in)
36           for in-suite = (get-test i)
37           do (progn
38                (when (null in-suite)
39                  (cerror "Create a new suite named ~A." "Unknown suite ~A." i)
40                  (setf (get-test in-suite) (make-suite i)
41                        in-suite (get-test in-suite)))
42                (setf (gethash name (tests in-suite)) suite)))
43     (setf (get-test name) suite)
44     suite))
45
46 ;;;; ** Managing the Current Suite
47
48 (defvar *suite* (setf (get-test 'NIL)
49                       (make-suite 'NIL :description "Global Suite"))
50   "The current test suite object")
51
52 (defmacro in-suite (suite-name)
53   "Set the *suite* special variable so that all tests defined
54 after the execution of this form are, unless specified otherwise,
55 in the test-suite named SUITE-NAME.
56
57 See also: DEF-SUITE *SUITE*"
58   (with-unique-names (suite)
59     `(progn
60        (if-bind ,suite (get-test ',suite-name)
61            (setf *suite* ,suite)
62            (progn
63              (cerror "Create a new suite named ~A."
64                      "Unkown suite ~A." ',suite-name)
65              (setf (get-test ',suite-name) (make-suite ',suite-name)
66                    *suite* (get-test ',suite-name))))
67        ',suite-name)))
68
69 ;; Copyright (c) 2002-2003, Edward Marco Baringer
70 ;; All rights reserved. 
71 ;; 
72 ;; Redistribution and use in source and binary forms, with or without
73 ;; modification, are permitted provided that the following conditions are
74 ;; met:
75 ;; 
76 ;;  - Redistributions of source code must retain the above copyright
77 ;;    notice, this list of conditions and the following disclaimer.
78 ;; 
79 ;;  - Redistributions in binary form must reproduce the above copyright
80 ;;    notice, this list of conditions and the following disclaimer in the
81 ;;    documentation and/or other materials provided with the distribution.
82 ;;
83 ;;  - Neither the name of Edward Marco Baringer, nor BESE, nor the names
84 ;;    of its contributors may be used to endorse or promote products
85 ;;    derived from this software without specific prior written permission.
86 ;; 
87 ;; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
88 ;; "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
89 ;; LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
90 ;; A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT
91 ;; OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
92 ;; SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
93 ;; LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
94 ;; DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
95 ;; THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
96 ;; (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
97 ;; OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE