This repository has been archived by the owner on Aug 13, 2020. It is now read-only.
/
tests.lisp
230 lines (180 loc) · 6.4 KB
/
tests.lisp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
;;;; -*- Mode: Lisp; Syntax: ANSI-Common-Lisp; indent-tabs-mode: nil -*-
(in-package :Eos)
(in-suite Eos)
(def-suite test-suite :description "Suite for tests which should fail.")
(defmacro with-test-results ((results test-name) &body body)
`(let ((,results (with-*test-dribble* nil (run ',test-name))))
,@body))
(rem-fixture 'null-fixture)
(def-fixture null-fixture ()
`(progn ,@(&body)))
;;;; Test the checks
(test (is1 :suite test-suite)
(is (plusp 1))
(is (< 0 1))
(is (not (plusp -1)))
(is (not (< 1 0)))
(is-true t)
(is-false nil))
(test (is2 :suite test-suite :fixture null-fixture)
(is (plusp 0))
(is (< 0 -1))
(is (not (plusp 1)))
(is (not (< 0 1)))
(is-true nil)
(is-false t))
(test is
(with-test-results (results is1)
(is (= 6 (length results)))
(is (every #'test-passed-p results)))
(with-test-results (results is2)
(is (= 6 (length results)))
(is (every #'test-failure-p results))))
(test signals/finishes
(signals error
(error "an error"))
(finishes
(signals error
(error "an error"))))
(test pass
(pass))
(test (fail1 :suite test-suite)
(fail "This is supposed to fail"))
(test fail
(with-test-results (results fail1)
(is (= 1 (length results)))
(is (test-failure-p (first results)))))
;;;; non top level checks
(test foo-bar
(let ((state 0))
(is (= 0 state))
(is (= 1 (incf state)))))
;;;; Test dependencies
(test (ok :suite test-suite)
(pass))
(test (not-ok :suite test-suite)
(fail "This is supposed to fail."))
(test (and1 :depends-on (and ok not-ok) :suite test-suite)
(fail))
(test (and2 :depends-on (and ok) :suite test-suite)
(pass))
(test dep-and
(with-test-results (results and1)
(is (= 3 (length results)))
;; we should have one skippedw one failed and one passed
(is (some #'test-passed-p results))
(is (some #'test-skipped-p results))
(is (some #'test-failure-p results)))
(with-test-results (results and2)
(is (= 2 (length results)))
(is (every #'test-passed-p results))))
(test (or1 :depends-on (or ok not-ok) :suite test-suite)
(pass))
(test (or2 :depends-on (or not-ok ok) :suite test-suite)
(pass))
(test dep-or
(with-test-results (results or1)
(is (= 2 (length results)))
(is (every #'test-passed-p results)))
(with-test-results (results or2)
(is (= 3 (length results)))
(is (= 2 (length (remove-if-not #'test-passed-p results))))))
(test (not1 :depends-on (not not-ok) :suite test-suite)
(pass))
(test (not2 :depends-on (not ok) :suite test-suite)
(fail))
(test not
(with-test-results (results not1)
(is (= 2 (length results)))
(is (some #'test-passed-p results))
(is (some #'test-failure-p results)))
(with-test-results (results not2)
(is (= 2 (length results)))
(is (some #'test-passed-p results))
(is (some #'test-skipped-p results))))
(test (nested-logic :depends-on (and ok (not not-ok) (not not-ok))
:suite test-suite)
(pass))
(test dep-nested
(with-test-results (results nested-logic)
(is (= 3 (length results)))
(is (= 2 (length (remove-if-not #'test-passed-p results))))
(is (= 1 (length (remove-if-not #'test-failure-p results))))))
(test (circular-0 :depends-on (and circular-1 circular-2 or1)
:suite test-suite)
(fail "we depend on a circular dependency, we should not be tested."))
(test (circular-1 :depends-on (and circular-2)
:suite test-suite)
(fail "we have a circular depednency, we should not be tested."))
(test (circular-2 :depends-on (and circular-1)
:suite test-suite)
(fail "we have a circular depednency, we should not be tested."))
(test circular
(signals circular-dependency
(run 'circular-0))
(signals circular-dependency
(run 'circular-1))
(signals circular-dependency
(run 'circular-2)))
;;;; dependencies with symbol
(test (dep-with-symbol-first :suite test-suite)
(pass))
(test (dep-with-symbol-dependencies-not-met :depends-on (not dep-with-symbol-first)
:suite test-suite)
(fail "Error in the test of the test, this should not ever happen"))
(test (dep-with-symbol-depends-on-ok :depends-on dep-with-symbol-first :suite test-suite)
(pass))
(test (dep-with-symbol-depends-on-failed-dependency :depends-on dep-with-symbol-dependencies-not-met
:suite test-suite)
(fail "No, I should not be tested becuase I depend on a test that in its turn has a failed dependecy."))
(test dependencies-with-symbol
(with-test-results (results dep-with-symbol-first)
(is (some #'test-passed-p results)))
(with-test-results (results dep-with-symbol-depends-on-ok)
(is (some #'test-passed-p results)))
(with-test-results (results dep-with-symbol-dependencies-not-met)
(is (some #'test-skipped-p results)))
;; No failure here, because it means the test was run.
(with-test-results (results dep-with-symbol-depends-on-failed-dependency)
(is (not (some #'test-failure-p results)))))
;;;; test for-all
(test gen-integer
(for-all ((a (gen-integer)))
(is (integerp a))))
(test for-all-guarded
(for-all ((less (gen-integer))
(more (gen-integer) (< less more)))
(is (< less more))))
(test gen-float
(macrolet ((test-gen-float (type)
`(for-all ((unbounded (gen-float :type ',type))
(bounded (gen-float :type ',type :bound 42)))
(is (typep unbounded ',type))
(is (typep bounded ',type))
(is (<= (abs bounded) 42)))))
(test-gen-float single-float)
(test-gen-float short-float)
(test-gen-float double-float)
(test-gen-float long-float)))
(test gen-character
(for-all ((c (gen-character)))
(is (characterp c)))
(for-all ((c (gen-character :code (gen-integer :min 32 :max 40))))
(is (characterp c))
(member c (list #\Space #\! #\" #\# #\$ #\% #\& #\' #\())))
(test gen-string
(for-all ((s (gen-string)))
(is (stringp s)))
(for-all ((s (gen-string :length (gen-integer :min 0 :max 2))))
(is (<= (length s) 2)))
(for-all ((s (gen-string :elements (constantly (code-char 0))
:length (constantly 2))))
(is (= 2 (length s)))
(is (every (curry #'char= #\Null) s))))
(defun dummy-mv-generator ()
(lambda ()
(list 1 1)))
(test for-all-destructuring-bind
(for-all (((a b) (dummy-mv-generator)))
(is (= 1 a))
(is (= 1 b))))