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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
|
# Cuprate
Cuprate is an experiment in providing a portable R6RS/R7RS testing
library. It uses purely functional data structures in a mutable parameter
object, allowing for procedural programming inside of a dynamic extent
to not affect the rest of the test system.
TODO: excise all conditional inclusion by turning them into library
forms. This will pave the way for porting to R6RS.
implementation-specific things (sans `define-test-application`, which is
a hack) are put into implementation libraries that export all relevant
identifiers. Rewriters take a first argument that is the rewritng closure,
that can do cycle detection.
Cuprate supports TR7, CHICKEN-5, Foment, Chibi, SKINT, Gauche, and
Sagittarius. STKLOS, Mosh, Chez, Guile, Racket, and Loko support soon.
## API
### `test-info` procedures
test-info
test-info?
test-dto
What SRFI-64 would call the "test runner" is in Cuprate the `test-info`,
which contains test-info record containing a pure SRFI-225 dictionary. The
dictionary must map at least symbols to values (including procedures).
Whenever a test group or a test is entered, a new dynamic extent is
entered with a new test-info object. Destructive updates to the new test
info are not reflected in the test info of the call.
When `test-info` is parameterized with a value satisfying `test-info?`,
then that test-info is used in the dynamic extent of the invocation of
`parameterize`. Otherwise, a new record is allocated, and the value passed
to `parameterize` is inserted into that record. This new record does not
share state with any other test-info.
The dictionary inside the `test-info` parameter must be a dictionary
according to the DTO in `test-dto`. The value in `test-dto` must be a DTO.
test-set!
test-update!
test-update/default!
test-delete-all!
test-contains?
test-ref
test-ref/default
test-update/default
These procedures are the same as their SRFI-225 equivalents, except
that the DTO and dictionary arguments are not needed, and that the
mutating procedures return unspecified values. For instance,
(test-set! key value)
is equivalent to `(dict-set! dto dict key value)`.
(modify-test-info! proc)
Evaluates `(proc dict)`, where `dict` is the current `test-info` dict. The
procedure must return a dict satisfying the same DTO. This dictionary
is set as the current `test-info` dictionary within the dynamic extent.
(inspect-test-info proc)
Evaluates `(proc dict)`, where `dict` is the current `test-info` dict,
and returns the result.
### `test-info` Standard Procedure Keys
before-test (default-before-test name)
A procedure with one argument (the name of the test).
Called in the dynamic extent of the caller of the test. If it returns
false, then the test is skipped.
test-setup (test-setup)
A procedure of zero arguments. Called in the dynamic extent of a
test. Used to set up parts of a test.
after-test (default-after-test dict)
A procedure of one argument (the dictionary of the test). Called
in the dynamic extent of the caller. Used to report information about
the test, and to merge desired information into the calling test info.
report-test (default-report-test dict)
A procedure of one argument (the dictionary of the test). Used by
`default-after-test` to report the result of the test to the user.
group-begin (default-group-begin name)
A procedure of one argument (the name of the group). Called in the dynamic
extent of the group. Used to set up common information for a whole group.
group-end (default-group-end dict)
A procedure of one (the dictionary of the test). Called in the dynamic
extent containing the group. Used to report information about the group
and merge it with the containing test info.
### `test-info` Standard Keys
* `success?`: Truthy if the test passed.
* `exception`: The caught exception, if any.
* `tests`: Number of run tests.
* `passed`: Number of passed tests.
* `failed`: Number of failed tests.
* `skipped`: Number of skipped tests.
* `verbose?`: Used by the default test setups. If false, only failures are
printed. Otherwise all test case information is printed.
### Test Procedures and Forms
If `test-name` is `#f`, then the test is not given a name. Every procedure
here is implemented using `call-as-test`.
(call-as-test test-name thunk)
Call `thunk` with the test name `test-name`.
First executes the procedure stored in `before-test` in the `test-info` of
the caller. If that returns non-false, then it creates a new `test-info`
inheriting from the `test-info` of the caller, and runs the procedure
stored in `test-setup` (in the new `test-info`). Then `thunk` will
be executed in this dynamic extent. If `thunk` throws an exception,
it will be caught. Afterwards, the procedure stored in `after-test`
will be run with the `test-info` of the caller.
The test will set
* `success?`: Will be set to `#f` if an exception was caught.
* `exception`: Only set if an exception was caught. The value is the
caught exception.
(test-application test-name (name expr) ...)
The `name` must be symbols that are mutually not `bound-identifier=?`.
Runs a test with `test-name` that evaluates `(expr ...)`.
The test will set (in addition to `call-as-test`):
* `form`: To be `(expr ...)`, quoted.
* `name ...`: To be the passed `expr ...` evaluated.
* `success?`: If `(expr ...)` evaluates to not false.
(with-test-assert test-name body ...)
Execute `body` in a test with `test-name`.
The test will set (in addition to `call-as-test`):
* `success?`: The returned value of `body` (if an exception is not caught).
(test-eq name %expected %actual)
(test-eqv name %expected %actual)
(test-equal name %expected %actual)
Convienence wrappers for
(test-application test-name ((procedure <procedure>)
(expected %expected)
(actual %actual)))
(test-approximate X Y eps)
Tests that
|X - Y| <= eps
(with-test-error name error-predicate body ...)
Evaluates `body ...` in a test. This test will set
* `success?`: False if evaluation does not throw an exception. Otherwise
the return value of `error-predicate` on the thrown exception.
(expect-to-fail body ...) ; syntax
Execute all tests in `body ...`, reporting a success if they fail and
reporting a failure if the succeed.
## Porting Guide
This library requires `make-parameter` and `parameterize` to work like
in R7RS. Most R6RS implementations should support dynamic parameters out
of the box.
The macro `define-test-application` uses the `letrec` trick to create
temporary variables in pure `syntax-rules` for use in the pattern side of
a generated `syntax-rules` macro. Some implementations, like CHICKEN 5.4.0
(kinda) and Foment, do not work correctly with this type of macro. If
the macro doesn't work in your implementation, you will probably need
to rewrite it in a low-level macro system. (If your implementation does
not offer a low-level macro system, then bug the maintainer of your
implementation to fix hygiene in their macro expander.)
This library requires SRFI-225. In the `compat` directory there is a
partial implementation of SRFI-225 that only works with alists, called
`micro-srfi-225`, that only requires base R6RS/R7RS. You can use this if
all you need is to run the tests.
## Instructions Per Implementation
### CHICKEN-5
There is an SRFI-225 port for CHICKEN-5, so just run `chicken-install
cuprate`. Because of a bug with compiled syntax-rules patterns,
`define-test-application` has limited support.
### Foment
Tested with the latest checkout as of 2025-11-03.
The reference implementation SRFI-225 will work out of the box. Test
bodies cannot return multiple values. Because of a bug with compiled
syntax-rules patterns, `define-test-application` has limited support.
### Chibi
Tested with 0.10.
The reference implementation of SRFI-225 will work out of the box.
### TR7
Tested to work with 2.0.7.
To use SRFI-225, you will also need SRFI-128. Mini-SRFI-225 will also
work here.
There is an issue with `call/cc` escaping out of `parameterize`d blocks.
This doesn't affect any of the test cases, but this may break some code.
### Gauche
Tested with 0.9.15.
I had to explicitly remove some of the conditional exports from the
reference implementation of SRFI 225 in order to get it to work.
### SKINT
Tested to work on SKINT 0.6.7, with SRFIs. SKINT bundles SRFI-225, so all
you need to do is point SKINT to `lib` to use `cuprate`.
### STKlos
STKlos currently does not include files from the directory of the library.
This will probably be fixed in 2.11, but that has not been released yet.
|