source: project/wiki/eggref/5/simple-tests @ 39186

Last change on this file since 39186 was 39186, checked in by juergen, 5 months ago

simple-tests 2.3.1 docu

File size: 6.3 KB
Line 
1[[tags: egg]]
2[[toc:]]
3
4== simple-tests
5
6This module exports some macros and procedures which help in debugging
7and testing. Two interfaces are supplied.
8The old interface is a straight-forward port of Peter
9Seibel's test suite in "Practical Common Lisp" to Chicken Scheme.
10
11Notice the special meaning of dots and colons in the documentation.
12Two dots: Repeat the form to the left zero or one times,
13three dots: zero or many times
14four dots: one or many times.
15Colons to the left of dots group forms: the dots refer to as many forms
16as are enclosed by colons.
17
18=== Common
19
20==== simple-tests
21
22<procedure>(simple-tests ..)</procedure>
23
24documentation-procedure; returns the list of exported symbols if called
25with no symbol, otherwise the signature of that exported symbol sym.
26
27==== and?
28
29<procedure>(and? xpr . xprs)</procedure>
30
31non-short-circuated and, which executes all side-effects.
32
33==== writeln
34
35<procedure>(writeln xpr . xprs)</procedure>
36
37like print, but writes expressions separated by a space in one line.
38
39==== pe
40
41<procedure>(pe macro-code)</procedure>
42
43pretty-prints expanded macro-code.
44
45==== ppp
46
47<macro>(ppp xpr ...)</macro>
48
49print each xpr quoted in a headline and pretty-print its computed value.
50
51==== ppp*
52
53<macro>(ppp* xpr ypr . xpr-yprs)</macro>
54
55print each xpr quoted in a headline, and pretty-print xpr's computed as well as
56its expected value, ypr.
57
58==== ppp**
59
60<macro>(ppp** ((var val) ...) xpr ypr . xpr-yprs)
61
62wrap ppp* into a let.
63
64==== xpr:val
65
66<macro>(xpr:val xpr ...)</macro>
67
68print each xpr quoted in a headline and pretty-print its computed value,
69alias to ppp.
70
71==== xpr:val*
72
73<macro>(xpr:val* xpr ypr . xpr-yprs)</macro>
74
75alias to ppp*
76
77==== ==
78
79<procedure>(==)</procedure>
80<procedure>(== x)</procedure>
81<procedure>(== type? type-equal?)</procedure>
82
83generic procedure.
84The first resets the local database,
85the second returns the curried equality operator, corresponding to x,
86and the third adds a new pair to the local database.
87Using (== x) for comparison, you needn't supply a special comparison
88operator, (== x) will do it for you.
89
90=== Old interface
91
92==== compound-test
93
94<macro>(compound-test (name) test ...)</macro>
95
96This is the obligatory wrapper around each individual test predicate.
97Runs each test (usually created by define-test) in sequence and
98prints the results of each as well as a combined result.
99Exits with 0 or 1 depending on success or failure.
100
101==== define-test
102
103<macro>(define-test (name . parameters) form . forms)</macro>
104
105creates a test predicate, (name . parameters), to be called within
106compound-test. That predicate will test and report the results of all of
107its form arguments.
108
109==== *locations*
110
111global dynamic variable controlling location of possibly nested tests.
112
113==== *failures*
114
115global variable collecting failure information
116
117=== New interface
118
119==== check
120
121<macro>(check ((var val) ...) xpr ypr . xpr-yprs)</macro>
122
123compares xpr and ypr .... with == in the environment
124defined by (var val)
125
126==== define-checks
127
128<macro>(define-checks (name? verbose? var val . var-vals) xpr ypr .  xpr-yprs)</macro>
129
130defines a unary predicate, name?, with argument verbose?, which compares
131all pairs xpr ypr and prints a list of failures, if verbose? is
132#t or not given.  Otherwise simply returns #t or #f, depending on the
133comparison of the pairs' items.
134If the verbose? argument in the generated predicate is missing, it's #t,
135so the output is verbose.  Inside another check-predicate, it's usually
136#f, cf. arithmetic? below.
137
138Comparison is done by the generic procedure ==.
139Each var val pair is translated into a let,  supplying values to be used in test pairs.
140
141==== do-checks
142
143<macro>(do-checks (name? verbose? var val . var-vals) xpr ypr .  xpr-yprs)</macro>
144
145alias to define-checks
146
147==== check-all
148
149<macro>(check-all name check ...)</macro>
150
151tests each check in sequence and names it.
152
153=== Examples
154
155<enscript highlight=scheme>
156
157(import simple-tests)
158
159(define-test (+?)
160  (= (+ 1 2) 3)
161  (= (+ 1 2 3) 6))
162
163(define-test (*?)
164  (= (* 1 2) 2)
165  (= (* 1 2 3) 6))
166
167(define-test (arithmetic?)
168  (+?)
169  (*?))
170
171(compound-test (simple-tests)
172  (arithmetic?))
173
174or, ALTERNATIVELY
175
176(check ((lst '(0 1 2 3)))
177  lst
178  '(0 1 2 3)
179  (car lst)
180  0
181  (cadr lst)
182  1
183  (cddr lst)
184  '(2 3)
185  )
186
187(define-checks (+? verbose?)
188  (+ 1 2) 3
189  (+ 1 2 3) 6)
190
191(define-checks (*? verbose?)
192  (* 1 2) 2
193  (* 1 2 3) 6)
194
195(define-checks (arithmetic? verbose?)
196  (+? #f) #t
197  (*? #f) #t)
198
199(check-all SIMPLE (+?) (*?) (arithmetic?))
200
201</enscript>
202
203== Last update
204
205Nov 09, 2020
206
207== Author
208
209[[/users/juergen-lorenz|Juergen Lorenz]]
210
211== License
212
213 Copyright (c) 2013-2020, Juergen Lorenz
214 All rights reserved.
215
216 Redistribution and use in source and binary forms, with or without
217 modification, are permitted provided that the following conditions are
218 met:
219 
220 Redistributions of source code must retain the above copyright
221 notice, this list of conditions and the following disclaimer.
222 
223 Redistributions in binary form must reproduce the above copyright
224 notice, this list of conditions and the following disclaimer in the
225 documentation and/or other materials provided with the distribution.
226 Neither the name of the author nor the names of its contributors may be
227 used to endorse or promote products derived from this software without
228 specific prior written permission.
229   
230 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
231 IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
232 TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
233 PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
234 HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
235 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
236 TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
237 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
238 LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
239 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
240 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
241
242== Version History
243
244; 2.3.1 : aesthetic changes
245; 2.3 : check added
246; 2.2 : ppp** added
247; 2.1 : do-checks as an alias to define-checks added
248; 2.0.3 : bugfix: protect state changing functions
249; 2.0.1 : test-predicates without verbose? argument are verbose by default
250; 2.0 : added a second testing interface
251; 1.1 : ppp* added
252; 1.0 : port with modifications from chicken-4, version 2.6, to chicken-5
Note: See TracBrowser for help on using the repository browser.