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.
16 :documentation "Lookup table mapping test (and test suite)
20 (loop for test being the hash-keys of *test*
23 (defmacro test (name &body body)
24 "Create a test named NAME. If NAME is a list it must be of the
27 (name &key depends-on suite fixture compile-at profile)
29 NAME is the symbol which names the test.
31 DEPENDS-ON is a list of the form:
33 (AND . test-names) - This test is run only if all of the tests
34 in TEST-NAMES have passed, otherwise a single test-skipped
37 (OR . test-names) - If any of TEST-NAMES has passed this test is
38 run, otherwise a test-skipped result is generated.
40 (NOT test-name) - This is test is run only if TEST-NAME failed.
42 AND, OR and NOT can be combined to produce complex dependencies.
44 If DEPENDS-ON is a symbol it is interpreted as `(AND
45 ,depends-on), this is accomadate the common case of one test
48 FIXTURE specifies a fixtrue to wrap the body in.
50 If PROFILE is T profiling information will be collected as well."
52 (suite-arg (getf (cdr (ensure-list name)) :suite tmp))
54 ((eq tmp suite-arg) '*suite*)
55 (t `(get-test ',suite-arg)))))
57 (remf (cdr name) :suite))
58 (destructuring-bind (name &key depends-on (compile-at :run-time) fixture profile)
60 (declare (type (member :run-time :definition-time) compile-at))
61 (let ((description (if (stringp (car body))
64 (effective-body (if fixture
65 (destructuring-bind (name &rest args)
67 `((with-fixture ,name ,args ,@body)))
70 (setf (get-test ',name) (make-instance 'test-case
72 :runtime-package ,*package*
77 (let ((*package* (find-package ',(package-name *package*))))
78 (compile nil '(lambda ()
79 ,@effective-body))))))
80 (:definition-time effective-body)))
81 :description ,description
82 :depends-on ',depends-on
83 :collect-profiling-info ,profile))
84 (setf (gethash ',name (tests ,suite-form)) ',name)
85 (when *run-test-when-defined*
89 (defvar *run-test-when-defined* nil
90 "When non-NIL tests are run as soon as they are defined.")
92 ;; Copyright (c) 2002-2003, Edward Marco Baringer
93 ;; All rights reserved.
95 ;; Redistribution and use in source and binary forms, with or without
96 ;; modification, are permitted provided that the following conditions are
99 ;; - Redistributions of source code must retain the above copyright
100 ;; notice, this list of conditions and the following disclaimer.
102 ;; - Redistributions in binary form must reproduce the above copyright
103 ;; notice, this list of conditions and the following disclaimer in the
104 ;; documentation and/or other materials provided with the distribution.
106 ;; - Neither the name of Edward Marco Baringer, nor BESE, nor the names
107 ;; of its contributors may be used to endorse or promote products
108 ;; derived from this software without specific prior written permission.
110 ;; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
111 ;; "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
112 ;; LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
113 ;; A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
114 ;; OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
115 ;; SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
116 ;; LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
117 ;; DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
118 ;; THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
119 ;; (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
120 ;; OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.