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 (rem-fixture 'null-fixture)
14 (def-fixture null-fixture ()
19 (def-test is1 (:suite test-suite)
27 (def-test is2 (:suite test-suite :fixture null-fixture)
35 (def-test is (:profile t)
36 (with-test-results (results is1)
37 (is (= 6 (length results)))
38 (is (every #'test-passed-p results)))
39 (with-test-results (results is2)
40 (is (= 6 (length results)))
41 (is (every #'test-failure-p results))))
43 (def-test signals/finishes ()
53 (def-test fail1 (:suite test-suite)
54 (fail "This is supposed to fail"))
57 (with-test-results (results fail1)
58 (is (= 1 (length results)))
59 (is (test-failure-p (first results)))))
61 ;;;; non top level checks
66 (is (= 1 (incf state)))))
68 ;;;; Test dependencies
70 (def-test ok (:suite test-suite)
73 (def-test not-ok (:suite test-suite)
74 (fail "This is supposed to fail."))
76 (def-test and1 (:depends-on (and ok not-ok) :suite test-suite)
79 (def-test and2 (:depends-on (and ok) :suite test-suite)
83 (with-test-results (results and1)
84 (is (= 3 (length results)))
85 ;; we should have one skippedw one failed and one passed
86 (is (some #'test-passed-p results))
87 (is (some #'test-skipped-p results))
88 (is (some #'test-failure-p results)))
89 (with-test-results (results and2)
90 (is (= 2 (length results)))
91 (is (every #'test-passed-p results))))
93 (def-test or1 (:depends-on (or ok not-ok) :suite test-suite)
96 (def-test or2 (:depends-on (or not-ok ok) :suite test-suite)
100 (with-test-results (results or1)
101 (is (= 2 (length results)))
102 (is (every #'test-passed-p results)))
103 (with-test-results (results or2)
104 (is (= 3 (length results)))
105 (is (= 2 (length (remove-if-not #'test-passed-p results))))))
107 (def-test not1 (:depends-on (not not-ok) :suite test-suite)
110 (def-test not2 (:depends-on (not ok) :suite test-suite)
114 (with-test-results (results not1)
115 (is (= 2 (length results)))
116 (is (some #'test-passed-p results))
117 (is (some #'test-failure-p results)))
118 (with-test-results (results not2)
119 (is (= 2 (length results)))
120 (is (some #'test-passed-p results))
121 (is (some #'test-skipped-p results))))
123 (def-test nested-logic (:depends-on (and ok (not not-ok) (not not-ok))
127 (def-test dep-nested ()
128 (with-test-results (results nested-logic)
129 (is (= 3 (length results)))
130 (is (= 2 (length (remove-if-not #'test-passed-p results))))
131 (is (= 1 (length (remove-if-not #'test-failure-p results))))))
133 (def-test circular-0 (:depends-on (and circular-1 circular-2 or1)
135 (fail "we depend on a circular dependency, we should not be tested."))
137 (def-test circular-1 (:depends-on (and circular-2)
139 (fail "we have a circular depednency, we should not be tested."))
141 (def-test circular-2 (:depends-on (and circular-1)
143 (fail "we have a circular depednency, we should not be tested."))
145 (def-test circular ()
146 (signals circular-dependency
148 (signals circular-dependency
150 (signals circular-dependency
154 (def-suite before-test-suite :description "Suite for before test")
156 (def-test before-0 (:suite before-test-suite)
159 (def-test before-1 (:depends-on (:before before-0)
160 :suite before-test-suite)
163 (def-suite before-test-suite-2 :description "Suite for before test")
165 (def-test before-2 (:depends-on (:before before-3)
166 :suite before-test-suite-2)
169 (def-test before-3 (:suite before-test-suite-2)
173 (with-test-results (results before-test-suite)
174 (is (some #'test-skipped-p results)))
176 (with-test-results (results before-test-suite-2)
177 (is (every #'test-passed-p results))))
180 ;;;; dependencies with symbol
181 (def-test dep-with-symbol-first (:suite test-suite)
184 (def-test dep-with-symbol-dependencies-not-met (:depends-on (not dep-with-symbol-first)
186 (fail "Error in the test of the test, this should not ever happen"))
188 (def-test dep-with-symbol-depends-on-ok (:depends-on dep-with-symbol-first :suite test-suite)
191 (def-test dep-with-symbol-depends-on-failed-dependency (:depends-on dep-with-symbol-dependencies-not-met
193 (fail "No, I should not be tested becuase I depend on a test that in its turn has a failed dependecy."))
195 (def-test dependencies-with-symbol ()
196 (with-test-results (results dep-with-symbol-first)
197 (is (some #'test-passed-p results)))
199 (with-test-results (results dep-with-symbol-depends-on-ok)
200 (is (some #'test-passed-p results)))
202 (with-test-results (results dep-with-symbol-dependencies-not-met)
203 (is (some #'test-skipped-p results)))
205 ;; No failure here, because it means the test was run.
206 (with-test-results (results dep-with-symbol-depends-on-failed-dependency)
207 (is (not (some #'test-failure-p results)))))
212 (def-test gen-integer ()
213 (for-all ((a (gen-integer)))
216 (def-test for-all-guarded ()
217 (for-all ((less (gen-integer))
218 (more (gen-integer) (< less more)))
221 (def-test gen-float ()
222 (macrolet ((test-gen-float (type)
223 `(for-all ((unbounded (gen-float :type ',type))
224 (bounded (gen-float :type ',type :bound 42)))
225 (is (typep unbounded ',type))
226 (is (typep bounded ',type))
227 (is (<= (abs bounded) 42)))))
228 (test-gen-float single-float)
229 (test-gen-float short-float)
230 (test-gen-float double-float)
231 (test-gen-float long-float)))
233 (def-test gen-character ()
234 (for-all ((c (gen-character)))
236 (for-all ((c (gen-character :code (gen-integer :min 32 :max 40))))
238 (member c (list #\Space #\! #\" #\# #\$ #\% #\& #\' #\())))
240 (def-test gen-string ()
241 (for-all ((s (gen-string)))
243 (for-all ((s (gen-string :length (gen-integer :min 0 :max 2))))
244 (is (<= (length s) 2)))
245 (for-all ((s (gen-string :elements (gen-character :code (gen-integer :min 0 :max 0))
246 :length (constantly 2))))
247 (is (= 2 (length s)))
248 (is (every (curry #'char= #\Null) s))))
250 (defun dummy-mv-generator ()
254 (def-test for-all-destructuring-bind ()
255 (for-all (((a b) (dummy-mv-generator)))