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