Use lowercase-only characters for package names to fix compilation on Allegro
[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. NB: This macro is built on top of make-suite,
24 as such it, like make-suite, will overrwrite any existing suite
25 named NAME."
26   `(eval-when (:compile-toplevel :load-toplevel :execute)
27      (make-suite ',name
28                  ,@(when description `(:description ,description))
29                  ,@(when in `(:in ',in)))
30      ',name))
31
32 (defmacro def-suite* (name &rest def-suite-args)
33   `(progn
34      (def-suite ,name ,@def-suite-args)
35      (in-suite ,name)))
36
37 (defun make-suite (name &key description in)
38   "Create a new test suite object.
39
40 Overides any existing suite named NAME."
41   (let ((suite (make-instance 'test-suite :name name)))
42     (when description
43       (setf (description suite) description))
44     (loop for i in (ensure-list in)
45           for in-suite = (get-test i)
46           do (progn
47                (when (null in-suite)
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)
53     suite))
54
55 ;;;; ** Managing the Current Suite
56
57 (defvar *suite* (setf (get-test 'NIL)
58                       (make-suite 'NIL :description "Global Suite"))
59   "The current test suite object")
60
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.
65
66 See also: DEF-SUITE *SUITE*"
67   `(eval-when (:compile-toplevel :load-toplevel :execute)
68      (%in-suite ,suite-name)))
69
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))
73
74 (defmacro %in-suite (suite-name &key (fail-on-error t) in)
75   (with-unique-names (suite)
76     `(progn
77        (if-bind ,suite (get-test ',suite-name)
78          (setf *suite* ,suite)
79          (progn
80            (when ,fail-on-error
81              (cerror "Create a new suite named ~A."
82                      "Unkown suite ~A." ',suite-name))
83            (setf (get-test ',suite-name) (make-suite ',suite-name :in ',in)
84                  *suite* (get-test ',suite-name))))
85        ',suite-name)))
86
87 ;; Copyright (c) 2002-2003, Edward Marco Baringer
88 ;; All rights reserved.
89 ;;
90 ;; Redistribution and use in source and binary forms, with or without
91 ;; modification, are permitted provided that the following conditions are
92 ;; met:
93 ;;
94 ;;  - Redistributions of source code must retain the above copyright
95 ;;    notice, this list of conditions and the following disclaimer.
96 ;;
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.
100 ;;
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.
104 ;;
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