1 ;;;; -*- Mode: Lisp; indent-tabs-mode: nil -*-
3 (in-package :it.bese.fiveam)
5 (in-suite :it.bese.fiveam)
7 (def-suite test-suite :description "Suite for tests which should fail.")
9 (defmacro with-test-results ((results test-name) &body body)
10 `(let ((,results (with-*test-dribble* nil (run ',test-name))))
13 (def-fixture null-fixture ()
18 (def-test is1 (:suite test-suite)
26 (def-test is2 (:suite test-suite :fixture null-fixture)
34 (def-test is (:profile t)
35 (with-test-results (results is1)
36 (is (= 6 (length results)))
37 (is (every #'test-passed-p results)))
38 (with-test-results (results is2)
39 (is (= 6 (length results)))
40 (is (every #'test-failure-p results))))
42 (def-test signals/finishes ()
52 (def-test fail1 (:suite test-suite)
53 (fail "This is supposed to fail"))
56 (with-test-results (results fail1)
57 (is (= 1 (length results)))
58 (is (test-failure-p (first results)))))
60 ;;;; non top level checks
65 (is (= 1 (incf state)))))
67 ;;;; Test dependencies
69 (def-test ok (:suite test-suite)
72 (def-test not-ok (:suite test-suite)
73 (fail "This is supposed to fail."))
75 (def-test and1 (:depends-on (and ok not-ok) :suite test-suite)
78 (def-test and2 (:depends-on (and ok) :suite test-suite)
82 (with-test-results (results and1)
83 (is (= 3 (length results)))
84 ;; we should have one skippedw one failed and one passed
85 (is (some #'test-passed-p results))
86 (is (some #'test-skipped-p results))
87 (is (some #'test-failure-p results)))
88 (with-test-results (results and2)
89 (is (= 2 (length results)))
90 (is (every #'test-passed-p results))))
92 (def-test or1 (:depends-on (or ok not-ok) :suite test-suite)
95 (def-test or2 (:depends-on (or not-ok ok) :suite test-suite)
99 (with-test-results (results or1)
100 (is (= 2 (length results)))
101 (is (every #'test-passed-p results)))
102 (with-test-results (results or2)
103 (is (= 3 (length results)))
104 (is (= 2 (length (remove-if-not #'test-passed-p results))))))
106 (def-test not1 (:depends-on (not not-ok) :suite test-suite)
109 (def-test not2 (:depends-on (not ok) :suite test-suite)
113 (with-test-results (results not1)
114 (is (= 2 (length results)))
115 (is (some #'test-passed-p results))
116 (is (some #'test-failure-p results)))
117 (with-test-results (results not2)
118 (is (= 2 (length results)))
119 (is (some #'test-passed-p results))
120 (is (some #'test-skipped-p results))))
122 (def-test nested-logic (:depends-on (and ok (not not-ok) (not not-ok))
126 (def-test dep-nested ()
127 (with-test-results (results nested-logic)
128 (is (= 3 (length results)))
129 (is (= 2 (length (remove-if-not #'test-passed-p results))))
130 (is (= 1 (length (remove-if-not #'test-failure-p results))))))
132 (def-test circular-0 (:depends-on (and circular-1 circular-2 or1)
134 (fail "we depend on a circular dependency, we should not be tested."))
136 (def-test circular-1 (:depends-on (and circular-2)
138 (fail "we have a circular depednency, we should not be tested."))
140 (def-test circular-2 (:depends-on (and circular-1)
142 (fail "we have a circular depednency, we should not be tested."))
144 (def-test circular ()
145 (signals circular-dependency
147 (signals circular-dependency
149 (signals circular-dependency
153 (def-suite before-test-suite :description "Suite for before test")
155 (def-test before-0 (:suite before-test-suite)
158 (def-test before-1 (:depends-on (:before before-0)
159 :suite before-test-suite)
162 (def-suite before-test-suite-2 :description "Suite for before test")
164 (def-test before-2 (:depends-on (:before before-3)
165 :suite before-test-suite-2)
168 (def-test before-3 (:suite before-test-suite-2)
172 (with-test-results (results before-test-suite)
173 (is (some #'test-skipped-p results)))
175 (with-test-results (results before-test-suite-2)
176 (is (every #'test-passed-p results))))
179 ;;;; dependencies with symbol
180 (def-test dep-with-symbol-first (:suite test-suite)
183 (def-test dep-with-symbol-dependencies-not-met (:depends-on (not dep-with-symbol-first)
185 (fail "Error in the test of the test, this should not ever happen"))
187 (def-test dep-with-symbol-depends-on-ok (:depends-on dep-with-symbol-first :suite test-suite)
190 (def-test dep-with-symbol-depends-on-failed-dependency (:depends-on dep-with-symbol-dependencies-not-met
192 (fail "No, I should not be tested becuase I depend on a test that in its turn has a failed dependecy."))
194 (def-test dependencies-with-symbol ()
195 (with-test-results (results dep-with-symbol-first)
196 (is (some #'test-passed-p results)))
198 (with-test-results (results dep-with-symbol-depends-on-ok)
199 (is (some #'test-passed-p results)))
201 (with-test-results (results dep-with-symbol-dependencies-not-met)
202 (is (some #'test-skipped-p results)))
204 ;; No failure here, because it means the test was run.
205 (with-test-results (results dep-with-symbol-depends-on-failed-dependency)
206 (is (not (some #'test-failure-p results)))))
211 (def-test gen-integer ()
212 (for-all ((a (gen-integer)))
215 (def-test for-all-guarded ()
216 (for-all ((less (gen-integer))
217 (more (gen-integer) (< less more)))
220 (def-test gen-float ()
221 (macrolet ((test-gen-float (type)
222 `(for-all ((unbounded (gen-float :type ',type))
223 (bounded (gen-float :type ',type :bound 42)))
224 (is (typep unbounded ',type))
225 (is (typep bounded ',type))
226 (is (<= (abs bounded) 42)))))
227 (test-gen-float single-float)
228 (test-gen-float short-float)
229 (test-gen-float double-float)
230 (test-gen-float long-float)
232 (for-all ((value (gen-float :type 'single-float :min 1 :max 2)))
233 (is (typep value 'single-float))
234 (is (<= (coerce 1 'single-float) value (coerce 2 'single-float))))))
236 (def-test gen-character ()
237 (for-all ((c (gen-character)))
239 (for-all ((c (gen-character :code (gen-integer :min 32 :max 40))))
241 (member c (list #\Space #\! #\" #\# #\$ #\% #\& #\' #\())))
243 (def-test gen-string ()
244 (for-all ((s (gen-string)))
246 (for-all ((s (gen-string :length (gen-integer :min 0 :max 2))))
247 (is (<= (length s) 2)))
248 (for-all ((s (gen-string :elements (gen-character :code (gen-integer :min 0 :max 0))
249 :length (constantly 2))))
250 (is (= 2 (length s)))
251 (is (every (curry #'char= #\Null) s))))
253 (defun dummy-mv-generator ()
257 (def-test for-all-destructuring-bind ()
258 (for-all (((a b) (dummy-mv-generator)))
262 (defvar *special-variable* nil)
264 (def-fixture fixture-for-suite (value)
266 (setf *special-variable* value)
269 (def-suite suite-with-fixture :fixture (fixture-for-suite 42) :in :it.bese.fiveam)
271 (def-test test-with-suite-fixture (:suite suite-with-fixture)
272 (is (= 42 *special-variable*)))