-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathunit-test-framework.lisp
57 lines (44 loc) · 1.28 KB
/
unit-test-framework.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
(defun test-+ ()
(and
(= (+ 1 2) 3)
(= (+ 1 2 3) 6)
(= (+ -1 -3) -4)))
(defun test-+with-format ()
(report-result (= (+ 1 2) 3) '(= (+ 1 2) 3))
(report-result (= (+ 1 2 3) 6) '(= (+ 1 2 3) 6))
(report-result (= (+ -1 -3) -4) '(= (+ -1 -3) -4)))
(defun report-result (result form)
(format t "~:[FAIL~;pass~] ... ~a; ~a~%" result *test-name* form)
result)
;(defmacro check (form)
; `(report-result ,form ',form))
;(defun test-* ()
; (check (= (* 1 2) 2))
; (check (= (* 2 3) 6))
; (check (= (* 3 4) 12)))
(defmacro with-gensyms ((&rest names) &body body)
`(let ,(loop for n in names collect `(,n (gensym)))
,@body))
(defmacro combine-results (&body forms)
(with-gensyms (result)
`(let ((,result t))
,@(loop for f in forms collect `(unless ,f (setf ,result nil)))
,result)))
(defmacro check (&body forms)
`(combine-results
,@(loop for f in forms collect `(report-result ,f ',f))))
(deftest test-* ()
(check
(= (* 2 2) 4)
(= (* 3 3) 9)))
(deftest test-arithemetic ()
(combine-results
(test-+)
(test-*)))
(defvar *test-name* nil)
(defmacro deftest (name parameters &body body)
`(defun ,name ,parameters
(let ((*test-name* (append *test-name* (list ',name)))) ,@body)))
(deftest test-+-new ()
(check
(= (+ 1 1) 2)))