-
-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathtester.lisp
170 lines (155 loc) · 6.88 KB
/
tester.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
(in-package #:org.shirakumo.parachute)
(defmacro true (form &optional description &rest format-args)
`(eval-in-context
*context*
(make-instance 'comparison-result
:expression '(true ,form)
:value-form ',form
:body (lambda () ,form)
:expected 'T
:comparison 'geq
,@(when description
`(:description (format NIL ,description ,@format-args))))))
(defmacro false (form &optional description &rest format-args)
`(eval-in-context
*context*
(make-instance 'comparison-result
:expression '(false ,form)
:value-form ',form
:body (lambda () ,form)
:expected 'NIL
:comparison 'geq
,@(when description
`(:description (format NIL ,description ,@format-args))))))
(defmacro is (comp expected form &optional description &rest format-args)
`(eval-in-context
*context*
(make-instance 'comparison-result
:expression '(is ,comp ,expected ,form)
:value-form ',form
:body (lambda () ,form)
:expected ,expected
:comparison ,(maybe-quote comp)
,@(when description
`(:description (format NIL ,description ,@format-args))))))
(defmacro isnt (comp expected form &optional description &rest format-args)
`(eval-in-context
*context*
(make-instance 'comparison-result
:expression '(isnt ,comp ,expected ,form)
:value-form ',form
:body (lambda () ,form)
:expected ,expected
:comparison ,(maybe-quote comp)
:comparison-geq NIL
,@(when description
`(:description (format NIL ,description ,@format-args))))))
(defun destructure-is-values-body (body)
(let ((expected ()) (comparison ()) (description NIL) (format-args ()))
(values (loop for (expr . rest) on body
do (when (stringp expr)
(setf description expr)
(setf format-args rest)
(loop-finish))
(push (first expr) comparison)
(push (second expr) expected)
collect expr)
(nreverse expected)
(mapcar #'maybe-quote (nreverse comparison))
description format-args)))
(defmacro is-values (form &body body)
(multiple-value-bind (comp-expected expected comparison description format-args)
(destructure-is-values-body body)
`(eval-in-context
*context*
(make-instance 'multiple-value-comparison-result
:expression '(is-values ,form ,@comp-expected)
:value-form ',form
:body (lambda () ,form)
:expected (list ,@expected)
:comparison (list ,@comparison)
,@(when description
`(:description (format NIL ,description ,@format-args)))))))
(defmacro isnt-values (form &body body)
(multiple-value-bind (comp-expected expected comparison description format-args)
(destructure-is-values-body body)
`(eval-in-context
*context*
(make-instance 'multiple-value-comparison-result
:expression '(isnt-values ,form ,@comp-expected)
:value-form ',form
:body (lambda () ,form)
:expected (list ,@expected)
:comparison (list ,@comparison)
:comparison-geq NIL
,@(when description
`(:description (format NIL ,description ,@format-args)))))))
(defmacro fail (form &optional (type 'error) description &rest format-args)
`(eval-in-context
*context*
(make-instance 'comparison-result
:expression '(fail ,form ,type)
:value-form '(capture-error ,form)
:body (lambda () (capture-error ,form ,(maybe-unquote type)))
:expected ',(maybe-unquote type)
:comparison 'typep
,@(when description
`(:description (format NIL ,description ,@format-args))))))
(defmacro fail-compile (form &optional (type 'error) description &rest format-args)
`(eval-in-context
*context*
(make-instance 'comparison-result
:expression '(fail-expansion ,form)
:value-form '(nth-value 3 (try-compile ',form ',type))
:body (lambda () (nth-value 3 (try-compile ',form ',type)))
:expected ',(maybe-unquote type)
:comparison 'typep
,@(when description
`(:description (format NIL ,description ,@format-args))))))
(defmacro of-type (type form &optional description &rest format-args)
`(eval-in-context
*context*
(make-instance 'comparison-result
:expression '(of-type ,type ,form)
:value-form ',form
:body (lambda () ,form)
:expected ',(maybe-unquote type)
:comparison 'typep
,@(when description
`(:description (format NIL ,description ,@format-args))))))
(defmacro finish (form &optional description &rest format-args)
`(eval-in-context
*context*
(make-instance 'finishing-result
:expression '(finish ,form)
:body (lambda () ,form)
,@(when description
`(:description (format NIL ,description ,@format-args))))))
(defmacro with-forced-status ((status &optional description &rest format-args) &body tests)
`(eval-in-context
*context*
(make-instance 'controlling-result
:expression ,status
:child-status ,status
:body (lambda () ,@tests)
,@(when description
`(:description (format NIL ,description ,@format-args))))))
(defmacro skip (desc &body tests)
`(with-forced-status (:skipped ,@(if (listp desc) desc (list desc)))
,@tests))
(defmacro skip-on (features desc &body tests)
(let ((thunk (gensym "THUNK")))
`(flet ((,thunk ()
,@tests))
(if (featurep '(or ,@features))
(with-forced-status (:skipped ,@(if (listp desc) desc (list desc)))
(,thunk))
(,thunk)))))
(defmacro group ((name &optional description &rest format-args) &body tests)
`(eval-in-context
*context*
(make-instance 'group-result
:expression ',name
:body (lambda () ,@tests)
,@(when description
`(:description (format NIL ,description ,@format-args))))))