source: project/wiki/eggref/4/simple-tests @ 33726

Last change on this file since 33726 was 33726, checked in by svnwiki, 5 years ago

Anonymous wiki edit for IP [76.103.99.21]: Indentation in example.

File size: 4.2 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. Most of the code is a straight-forward port of Peter
8Seibel's test suite in "Practical Common Lisp" to Chicken Scheme.
9
10=== The routines
11
12==== simple-tests
13
14<procedure>(simple-tests [sym])</procedure>
15
16documentation-procedure; returns the list of exported symbols if called
17with no symbol, otherwise the signature of that exported symbol sym.
18
19==== compound-test
20
21<macro>(compound-test (name) test ...)</macro>
22
23This is the obligatory wrapper around each individual test predicate.
24Runs each test (usually created by define-test) in sequence and
25prints the results of each as well as a combined result.
26Exits with 0 or 1 depending on success or failure.
27
28==== simple-test
29
30<macro>(simple-test (name) xpr ...)</macro>
31
32runs each test expression, xpr, and prints success or failure as well as
33a summary, all prefixed with name.
34This macro is deprecated. Use compound-test instead.
35
36==== define-test
37
38<macro>(define-test (name . parameters) . forms)</macro>
39
40creates a test predicate, (name . parameters), to be called within
41compound-test. That predicate will test and report the results of all of
42its form arguments.
43
44==== check
45
46<macro>(check xpr . xprs)</macro>
47
48returns a unary procedure with location argument,
49which checks each of its xpr arguments and reports it.
50
51==== xpr:val
52
53<macro>(xpr:val xpr . xprs)</macro>
54
55prints each xpr and its value in interpreted code only.
56
57==== and?
58
59<macro>(and? xpr . xprs)</macro>
60
61non-short-circuated and, which executes all side-effects.
62
63==== pe
64
65<procedure>(pe macro-code)</procedure>
66
67pretty-prints expanded macro-code.
68
69==== *locations*
70
71global dynamic variable controlling location of possibly nested tests.
72
73==== *failures*
74
75global variable collecting failure information
76
77=== Example
78
79<enscript highlight=scheme>
80
81(use simple-tests)
82
83(define-test (+?)
84        (check
85                (= (+ 1 2) 3)
86                (= (+ 1 2 3) 6)))
87
88(define-test (*?)
89        (check
90                (= (* 1 2) 2)
91                (= (* 1 2 3) 6)))
92
93(define-test (arithmetic?)
94        (check
95                (x?)
96                (*?)))
97
98(compound-test (simple-tests)
99  (arithmetic?))
100
101</enscript>
102
103== Last update
104
105May 03, 2014
106
107== Author
108
109[[/users/juergen-lorenz|Juergen Lorenz]]
110
111== License
112
113 Copyright (c) 2013-2016, Juergen Lorenz
114 All rights reserved.
115
116 Redistribution and use in source and binary forms, with or without
117 modification, are permitted provided that the following conditions are
118 met:
119 
120 Redistributions of source code must retain the above copyright
121 notice, this list of conditions and the following disclaimer.
122 
123 Redistributions in binary form must reproduce the above copyright
124 notice, this list of conditions and the following disclaimer in the
125 documentation and/or other materials provided with the distribution.
126 Neither the name of the author nor the names of its contributors may be
127 used to endorse or promote products derived from this software without
128 specific prior written permission.
129   
130 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
131 IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
132 TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
133 PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
134 HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
135 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
136 TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
137 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
138 LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
139 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
140 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
141
142== Version History
143
144; 2.3 : empty arglists handled in xpr:val and check
145; 2.2 : cond-expand replaces eval-when in xpr:val, group-on-cdrs removed
146; 2.1 : failure reports improved
147; 2.0.1 : exit calls added to compund-test
148; 2.0 : Complete rewrite
149; 1.4 : simple-test and compound-test added
150; 1.3 : dependency on multi-methods removed
151; 1.2 : dependency changed from dbc to multi-methods
152; 1.1 : bugfix
153; 1.0.3 : display of run-tests improved
154; 1.0.2 : xpr:val prettified
155; 1.0.1 : run-tests changed
156; 1.0 : initial import
Note: See TracBrowser for help on using the repository browser.