3 (in-package :it.bese.FiveAM)
7 ;;;; While executing checks and collecting the results is the core job
8 ;;;; of a testing framework it is also important to be able to
9 ;;;; organize checks into groups, FiveAM provides two mechanisms for
10 ;;;; organizing checks: tests and test suites. A test is a named
11 ;;;; collection of checks which can be run and a test suite is a named
12 ;;;; collection of tests and test suites.
15 :documentation "Lookup table mapping test (and test suite)
19 (loop for test being the hash-keys of *test*
22 (defmacro test (name &body body)
23 "Create a test named NAME. If NAME is a list it must be of the
26 (name &key depends-on suite)
28 NAME is the symbol which names the test.
30 DEPENDS-ON is a list of the form:
32 (AND . test-names) - This test is run only if all of the tests
33 in TEST-NAMES have passed, otherwise a single test-skipped
36 (OR . test-names) - If any of TEST-NAMES has passed this test is
37 run, otherwise a test-skipped result is generated.
39 (NOT test-name) - This is test is run only if TEST-NAME failed.
41 AND, OR and NOT can be combined to produce complex dependencies.
43 If DEPENDS-ON is a symbol it is interpreted as `(AND
44 ,depends-on), this is accomadate the common case of one test
47 SUITE defaults to the current value of *SUITE*."
48 (destructuring-bind (name &key depends-on (suite nil suite-supplied-p))
51 (setf description (if (stringp (car body))
55 (setf (get-test ',name) (make-instance 'test-case
57 :runtime-package ,*package*
60 (funcall (compile nil '(lambda () ,@body))))
61 :description ,description
62 :depends-on ',depends-on))
64 `(setf (gethash ',name (tests (get-test ',suite)))
66 `(setf (gethash ',name (tests (or *suite* (get-test 'NIL))))
68 (when *run-test-when-defined*
72 (defvar *run-test-when-defined* nil
73 "When non-NIL tests are run as soon as they are defined.")
75 ;; Copyright (c) 2002-2003, Edward Marco Baringer
76 ;; All rights reserved.
78 ;; Redistribution and use in source and binary forms, with or without
79 ;; modification, are permitted provided that the following conditions are
82 ;; - Redistributions of source code must retain the above copyright
83 ;; notice, this list of conditions and the following disclaimer.
85 ;; - Redistributions in binary form must reproduce the above copyright
86 ;; notice, this list of conditions and the following disclaimer in the
87 ;; documentation and/or other materials provided with the distribution.
89 ;; - Neither the name of Edward Marco Baringer, nor BESE, nor the names
90 ;; of its contributors may be used to endorse or promote products
91 ;; derived from this software without specific prior written permission.
93 ;; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
94 ;; "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
95 ;; LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
96 ;; A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
97 ;; OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
98 ;; SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
99 ;; LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
100 ;; DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
101 ;; THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
102 ;; (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
103 ;; OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.