FIX: Store *package* at definition time for tests and rebind it at runtime
[fiveam.git] / src / classes.lisp
1 ;; -*- lisp -*-
2
3 (in-package :it.bese.FiveAM)
4
5 (defclass testable-object ()
6   ((name :initarg :name :accessor name 
7          :documentation "A symbol naming this test object.")
8    (description :initarg :description :accessor description :initform nil
9                 :documentation "The textual description of this test object.")
10    (depends-on :initarg :depends-on :accessor depends-on :initform nil
11                :documentation "The list of AND, OR, NOT forms specifying when to run this test.")
12    (status :initarg :status :accessor status :initform :unknown
13            :documentation "A symbol specifying the current status
14            of this test. Either: T - this test (and all its
15            dependencies, have passed. NIL - this test
16            failed (either it failed or its dependecies weren't
17            met. :circular this test has a circular depenedency
18            and was skipped.")))
19
20 (defmethod print-object ((test testable-object) stream)
21   (print-unreadable-object (test stream :type t :identity t)
22     (format stream "~S" (name test))))
23
24 (defclass test-suite (testable-object)
25   ((tests :accessor tests :initform (make-hash-table :test 'eql)
26           :documentation "The hash table mapping names to test
27           objects in this suite. The values in this hash table
28           can be either test-cases or other test-suites."))
29   (:documentation "A test suite is a collection of tests or test suites.
30
31 Test suites serve to organize tests into groups so that the
32 developer can chose to run some tests and not just one or
33 all. Like tests test suites have a name and a description.
34
35 Test suites, like tests, can be part of other test suites, this
36 allows the developer to create a hierarchy of tests where sub
37 trees can be singularly run.
38
39 Running a test suite has the effect of running every test (or
40 suite) in the suite."))
41
42 (defclass test-case (testable-object)
43   ((test-lambda :initarg :test-lambda :accessor test-lambda
44                 :documentation "The function to run.")
45    (runtime-package :initarg :runtime-package :accessor runtime-package
46                     :documentation "By default it stores *package* from the time this test was defined (macroexpanded)."))
47   (:documentation "A test case is a single, named, collection of
48 checks.
49
50 A test case is the smallest organizational element which can be
51 run individually. Every test case has a name, which is a symbol,
52 a description and a test lambda. The test lambda is a regular
53 funcall'able function which should use the various checking
54 macros to collect results.
55
56 Every test case is part of a suite, when a suite is not
57 explicitly specified (either via the :SUITE parameter to the TEST
58 macro or the global variable *SUITE*) the test is inserted into
59 the global suite named NIL.
60
61 Sometimes we want to run a certain test only if another test has
62 passed. FiveAM allows us to specify the ways in which one test is
63 dependent on another.
64
65 - AND Run this test only if all the named tests passed.
66
67 - OR Run this test if at least one of the named tests passed.
68
69 - NOT Run this test only if another test has failed.
70
71 FiveAM considers a test to have passed if all the checks executed
72 were successful, otherwise we consider the test a failure.
73
74 When a test is not run due to it's dependencies having failed a
75 test-skipped result is added to the results."))
76
77 (defclass explainer ()
78   ())
79
80 (defclass text-explainer (explainer)
81   ())
82
83 (defclass simple-text-explainer (text-explainer)
84   ())
85
86 (defclass detailed-text-explainer (text-explainer)
87   ())
88
89 ;; Copyright (c) 2002-2003, Edward Marco Baringer
90 ;; All rights reserved. 
91 ;; 
92 ;; Redistribution and use in source and binary forms, with or without
93 ;; modification, are permitted provided that the following conditions are
94 ;; met:
95 ;; 
96 ;;  - Redistributions of source code must retain the above copyright
97 ;;    notice, this list of conditions and the following disclaimer.
98 ;; 
99 ;;  - Redistributions in binary form must reproduce the above copyright
100 ;;    notice, this list of conditions and the following disclaimer in the
101 ;;    documentation and/or other materials provided with the distribution.
102 ;;
103 ;;  - Neither the name of Edward Marco Baringer, nor BESE, nor the names
104 ;;    of its contributors may be used to endorse or promote products
105 ;;    derived from this software without specific prior written permission.
106 ;; 
107 ;; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
108 ;; "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
109 ;; LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
110 ;; A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT
111 ;; OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
112 ;; SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
113 ;; LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
114 ;; DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
115 ;; THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
116 ;; (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
117 ;; OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE