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