ac2a606e6bd5e26e5c11969204d7a2f52ef51695
[fiveam.git] / t / tests.lisp
1 ;;;; -*- lisp -*-
2
3 (in-package :it.bese.FiveAM)
4
5 (in-suite :it.bese.FiveAM)
6
7 (def-suite test-suite :description "Suite for tests which should fail.")
8
9 (defmacro with-test-results ((results test-name) &body body)
10   `(let ((,results (with-*test-dribble* nil (run ',test-name))))
11      ,@body))
12
13 ;;;; Test the checks
14
15 (test (is1 :suite test-suite)
16   (is (plusp 1))
17   (is (< 0 1))
18   (is (not (plusp -1)))
19   (is (not (< 1 0)))
20   (is-true t)
21   (is-false nil))
22
23 (test (is2 :suite test-suite)
24   (is (plusp 0))
25   (is (< 0 -1))
26   (is (not (plusp 1)))
27   (is (not (< 0 1)))
28   (is-true nil)
29   (is-false t))
30
31 (test is
32   (with-test-results (results is1)
33     (is (= 6 (length results)))
34     (is (every #'test-passed-p results)))
35   (with-test-results (results is2)
36     (is (= 6 (length results)))
37     (is (every #'test-failure-p results))))
38
39 (test signals/finishes
40   (signals error
41     (error "an error"))
42   (finishes
43    (signals error
44     (error "an error"))))
45
46 (test pass
47   (pass))
48
49 (test (fail1 :suite test-suite)
50   (fail "This is supposed to fail"))
51
52 (test fail
53   (with-test-results (results fail1)
54     (is (= 1 (length results)))
55     (is (test-failure-p (first results)))))
56
57 ;;;; non top level checks
58
59 (test foo-bar
60   (let ((state 0))
61     (is (= 0 state))
62     (is (= 1 (incf state)))))
63
64 ;;;; Test dependencies
65
66 (test (ok :suite test-suite)
67   (pass))
68
69 (test (not-ok :suite test-suite)
70   (fail "This is supposed to fail."))
71
72 (test (and1 :depends-on (and ok not-ok) :suite test-suite)
73   (fail))
74
75 (test (and2 :depends-on (and ok) :suite test-suite)
76   (pass))
77
78 (test dep-and 
79   (with-test-results (results and1)
80     (is (= 3 (length results)))
81     ;; we should have one skippedw one failed and one passed
82     (is (some #'test-passed-p results))
83     (is (some #'test-skipped-p results))
84     (is (some #'test-failure-p results)))
85   (with-test-results (results and2)
86     (is (= 2 (length results)))
87     (is (every #'test-passed-p results))))
88
89 (test (or1 :depends-on (or ok not-ok) :suite test-suite)
90   (pass))
91
92 (test (or2 :depends-on (or not-ok ok) :suite test-suite)
93   (pass))
94
95 (test dep-or
96   (with-test-results (results or1)
97     (is (= 2 (length results)))
98     (is (every #'test-passed-p results)))
99   (with-test-results (results or2)
100     (is (= 3 (length results)))
101     (is (= 2 (length (remove-if-not #'test-passed-p results))))))
102
103 (test (not1 :depends-on (not not-ok) :suite test-suite)
104   (pass))
105
106 (test (not2 :depends-on (not ok) :suite test-suite)
107   (fail))
108
109 (test not
110   (with-test-results (results not1)
111     (is (= 2 (length results)))
112     (is (some #'test-passed-p results))
113     (is (some #'test-failure-p results)))
114   (with-test-results (results not2)
115     (is (= 2 (length results)))
116     (is (some #'test-passed-p results))
117     (is (some #'test-skipped-p results))))
118
119 (test (nested-logic :depends-on (and ok (not not-ok) (not not-ok))
120                     :suite test-suite)
121   (pass))
122
123 (test dep-nested
124   (with-test-results (results nested-logic)
125     (is (= 3 (length results)))
126     (is (= 2 (length (remove-if-not #'test-passed-p results))))
127     (is (= 1 (length (remove-if-not #'test-failure-p results))))))
128
129 (test (circular-0 :depends-on (and circular-1 circular-2 or1) 
130                   :suite test-suite)
131   (fail "we depend on a circular dependency, we should not be tested."))
132
133 (test (circular-1 :depends-on (and circular-2)
134                   :suite test-suite)
135   (fail "we have a circular depednency, we should not be tested."))
136
137 (test (circular-2 :depends-on (and circular-1)
138                   :suite test-suite)
139   (fail "we have a circular depednency, we should not be tested."))
140
141 (test circular
142   (signals circular-dependency
143     (run 'circular-0))
144   (signals circular-dependency
145     (run 'circular-1))
146   (signals circular-dependency
147     (run 'circular-2)))