Source

missbehave / missbehave.scm

  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
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
;; 
;; %%HEADER%%
;;
;;
;;
;;

(module missbehave
(
  run-specification behave call-with-specification make-empty-specification    
  describe context run-context call-with-context add-context-to-specification
  context-description create-context context? context-parent
  
  add-hook-to-context before after
  subject-set! subject 
 
  it create-example example-description run-example 
  add-example-to-context pending 

  example-result? example? example-result-example example-result-messages
  example-failed? example-pending? example-result-spec-file
  example-spec-file 
 
  expect run-expectation  to
  make-matcher
  matcher
 
  current-context context-subject-set!
  $ reset-state!
  current-spec-file
  negative-expectation
  do-not
  unspecified

  )

(import chicken scheme extras data-structures ports)
(require-extension
  srfi-1 regex
  (only srfi-69 hash-table-set! hash-table-ref/default hash-table-clear! make-hash-table))

(require-library matchable)
(import-for-syntax matchable)

(define-syntax returning
  (syntax-rules ()
    ((_ object code more-code ...)
     (let ((return-later object))
       code more-code ...
       return-later))))

(define (unspecified)
  (let ((intern 1))
    (set! intern 2)))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Specification
;;
;; A specification is the sum of all contexts/description with all
;; their examples. It's basically everything you have to say about the
;; behaviour of a particular object or system.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(define (make-empty-specification) (list))

(define current-specification    (make-parameter (make-empty-specification)))

(define current-spec-file (make-parameter ""))

(define (call-with-specification specification thunk)
  (parameterize ((current-specification specification))
    (thunk)
    (current-specification)))

(define (run-specification specification #!key (include #f) (exclude #f) (reporter (make-standard-reporter)))
  (let ((contexts (filter-contexts specification include exclude)))
    (for-each (cut run-context <> reporter include exclude) contexts)
    (reporter #f mode: 'summary)))

(define (behave thunk)
  (if (run-specification
       (call-with-specification
        (make-empty-specification)
        thunk))
      0 1))

(define (filter-contexts contexts include exclude)
  (cond
   ((and (not include) (not exclude)) contexts)
   ((not exclude)
    (filter
     (lambda (ctx)
       (or
        (meta-matches? (context-meta ctx) include)
        (context-has-matching-examples? ctx include: include))) contexts))
   ((not include)
    (filter
     (lambda (ctx)
       (not (meta-matches? (context-meta ctx) exclude))) contexts))
   (else
    (filter
     (lambda (ctx)
       (let ((meta (context-meta ctx)))
         (and (meta-matches? meta include)
              (not (meta-matches? meta exclude)))))
     contexts))))

(define (context-has-matching-examples? context #!key (include #f) (exclude #f))
  (not (null? (filter-examples context include exclude))))

(define (add-context-to-specification context)
  (returning context
    (current-specification
      (cons context (current-specification)))))

(define (filter-examples context include exclude)  
  (let ((examples (context-examples context)))
    (cond
     ((and (not include) (not exclude)) examples)
     ((not exclude)
      (filter
       (lambda (example)
         (meta-matches? (example-meta example) include))
       examples))
     ((not include)
      (filter
       (lambda (example)
         (not (meta-matches? (example-meta example) exclude)))
       examples))
     (else
      (filter (lambda (example)
                (let ((meta (example-meta example)))
                  (and (meta-matches? meta include)
                       (not (meta-matches? meta exclude)))))
              examples)))))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Contexts
;;
;; A context is means to scope your descriptions to a subsystem or a
;; specific aspect of the object you're describing.
;; Contexts can be nested. They can be decorated with meta-data which
;; can be used to filter them during execution. You can thus
;; selectively run specific contexts.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(define-record context description examples hooks meta subject parent)

(define current-context   (make-parameter #f))

(define (create-context description #!key (examples (list)) (meta (list)))
  (make-context description examples (list) meta #f (current-context)))

(define-record-printer (context ctx out)
  (fprintf
      out
      "#<context '~A' parent: ~A subject: ~A meta: ~A examples: ~A>"
    (context-description ctx)
    (context-parent ctx)
    (context-subject ctx)
    (context-meta ctx)
    (length (context-examples ctx))))

(define-syntax context
  (syntax-rules ()
    ((_ argument more-arguments ...)
     (describe argument more-arguments ...))))

(define-syntax describe
  (syntax-rules (meta)
    ((_ what)
     (add-context-to-specification
      (create-context what)))
    ((_ what (meta (tag value ...) ...))
     (add-context-to-specification
      (create-context what meta: '((tag value ...) ...))))
    ((_ what (meta (tag value ...) ...) example examples+ ...)
     (add-context-to-specification
      (call-with-context
       (create-context what meta: '((tag value ...) ...))
       (lambda () example examples+ ...))))
    ((_ what example examples+ ...)
     (add-context-to-specification
      (call-with-context
       (create-context what)
       (lambda ()  example examples+ ...))))))

(define (call-with-context context thunk)
  (parameterize ((current-context context))
    (returning (current-context)
       (thunk))))

(define (run-context context #!optional (reporter values) (include #f) (exclude #f))
  (reporter context mode: 'adhoc)
  (run-context-with-hooks context reporter include exclude))

(define (run-context-with-hooks context reporter include exclude)
  (let ((before-all  (find-context-hooks 'before 'all: context ))
        (after-all   (find-context-hooks 'after  'all: context ))
        (context-result #t))
    (parameterize (( current-context context))
      (call-with-hooks
       (lambda ()
         (for-each-example-in-context
          (lambda (example)
            (unless (run-example-with-hooks example context reporter)
              (set! context-result #f)))
          context
          include
          exclude))
       before-all
       after-all))
    context-result))

(define (for-each-example-in-context callback context include exclude)
  (for-each
   callback
   (reverse
    (cond
     ((and exclude include)
      (if (meta-matches? (context-meta context) include)
          (filter-examples context  #f exclude)
          (filter-examples context include exclude)))
     (include
      (if (meta-matches? (context-meta context) include)
          (filter-examples context #f exclude)
          (filter-examples context include #f)))
     (exclude     
      (filter-examples context #f exclude))
     (else  (context-examples context))))))

(define (run-example-with-hooks example context reporter)
  (reporter example mode: 'adhoc) 
  (let ((before-hooks-for-example (find-context-hooks-for-example 'before example context))
        (after-hooks-for-example  (find-context-hooks-for-example 'after  example context)))
    (call-with-hooks
     (lambda ()
       (let ((result (run-example example)))
         (reporter result mode: 'adhoc)
         (not (example-failed? result))))
     before-hooks-for-example
     after-hooks-for-example)))

(define (find-context-hooks type filter-exp context)
  (let ((hooks (all-hooks-with-parent-traversal context)))
    (map context-hook-hook
         (filter
          (lambda (hook)
            (and (eq? (context-hook-type hook) type )
                 (eq? (context-hook-filter hook) filter-exp)))
          hooks))))

(define (context-ancestors context)
  (let loop ((parent (context-parent context)) (ancestors '()))
    (cond
     ((not parent)  (append ancestors (list context)))
     (else (loop (context-parent parent) (cons parent ancestors))))))

(define (all-hooks-with-parent-traversal context)
  (append-map context-hooks (context-ancestors context)))

(define (subject-set! subject #!optional (context (current-context)))
  (when context
    (context-subject-set! context subject)))
                    
(define (subject)
  (when (current-context)
    (context-subject (current-context))))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Context-Hooks
;;
;; Hooks are procedures that are called at specific times
;; during the run of a context (before,after,...).
;; They typically hold setup and teardown code
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(define-record context-hook hook filter type)

(define-record-printer (context-hook hook out)
  (fprintf out
      "#<context-hook type(~A) filter(~A) hook(~A)>"
    (context-hook-type hook)
    (context-hook-filter hook)
    (context-hook-hook hook)))

(define-syntax before
  (syntax-rules (each: all:)
    ((_ each: code more-code ...)
     (add-hook-to-context (lambda () code more-code ...) type: 'before filter: 'each:))
    ((_ all: code more-code ...)
     (add-hook-to-context (lambda () code more-code ...) type: 'before filter: 'all:))
    ((_ filter code more-code ...)
     (add-hook-to-context (lambda () code more-code ...) type: 'before filter: '(filter)))))

(define-syntax after
  (syntax-rules (each: all:)
    ((_ each: code more-code ...)
     (add-hook-to-context (lambda () code more-code ...) type: 'after filter: 'each:))
    ((_ all: code more-code ...)
     (add-hook-to-context (lambda () code more-code ...) type: 'after filter: 'all:))
    ((_ filter code more-code ...)
     (add-hook-to-context (lambda () code more-code ...) type: 'after filter: '(filter)))))

(define (add-hook-to-context hook  #!key (filter each:) (type 'before) (context (current-context)))
  (context-hooks-set! context
                      (cons
                       (make-context-hook hook filter type)
                       (context-hooks context))))

(define (call-with-hooks thunk before after)
  (dynamic-wind
      (lambda () (for-each (cut apply <> (list)) before))
      thunk
      (lambda () (for-each (cut apply <> (list)) after))))

(define (find-context-hooks-for-example type example context)
  (let ((hooks (all-hooks-with-parent-traversal context))
        (meta  (example-meta example)))
    (map context-hook-hook
         (filter
          (lambda (hook)
            (and (eq? (context-hook-type hook) type)
                 (meta-matches? meta (context-hook-filter hook))))
          hooks))))

(define (meta-matches? meta tags)
  (or (eq? tags each:)
      ((tag-expression->filter tags) meta)))

(define ((tag-expression->filter tags) meta)
  (every (lambda (tag) (member tag meta)) tags))


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Examples
;;
;; Examples are pieces of behaviour you want to describe for a given
;; object or system. Use them to specify how your "subject" should
;; behave like. An example is usually set of expecations that are run
;; against the parts of your code you want to specify.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(define current-exit-continuation (make-parameter #f))

(define-record example description behaviour pending meta spec-file)

(define (create-example description behaviour #!key (pending #f) (meta (list)) (context #f))
  (make-example  description behaviour pending  meta context))

(define-record-printer (example ex out)
  (fprintf out "#<example '~A' meta(~A)>" (example-description ex) (example-meta ex)))

(define-syntax it
  (syntax-rules (meta should not)
    ((_ should matcher)
     (add-example-to-context
      (create-example (sprintf "should ~S" (quote matcher))
                      (lambda ()
                        (expect (subject) matcher)))))
    ((_ (matcher arguments ...))
     (add-example-to-context
      (create-example (sprintf "~S" (quote (matcher arguments ...)))
                      (lambda ()
                        (expect (subject) (matcher arguments ...))))))
    ((_ description)
     (add-example-to-context (create-example description #f pending: #t)))
    ((_ description (meta (tag value ...) ...))
     (add-example-to-context (create-example description #f pending: #t meta: '((tag value ...) ...))))
    ((_ description (meta (tag value ...) ...) code more-code ...)
     (add-example-to-context (create-example description
                                             (lambda () code more-code ...)
                                             meta: '((tag value ...) ...))))
    ((_ description code more-code ...)
     (add-example-to-context (create-example description
                                             (lambda () code more-code ...))))))

(define (add-example-to-context example #!optional (context (current-context)))
  (returning example
    (when context
      (example-spec-file-set! example (current-spec-file))
      (context-examples-set! context (cons example (context-examples context))))))

(define (format-condition-properties exn without)
  (let* ((cps (condition->list exn))
         (eps (remove (lambda (x) (memq (car x) without))
                      (or (alist-ref 'exn cps) '())))
         (cps (alist-update! 'exn eps cps)))
    (with-output-to-string
        (lambda ()
          (for-each 
           (lambda (cp)
             (printf "~A:~%" (car cp))
             (for-each (lambda (p)
                         (printf "  ~A: ~S~%" (car p) (cadr p)))
                       (cdr cp)))
           cps)))))

(define (run-example example)
  (let((behaviour (example-behaviour example))
       (result    (make-example-result 'succeeded '() example (example-spec-file example))))
    (parameterize ((current-example-result result))
      (cond
       ((example-pending example)
        (example-result-status-set! result 'pending))
       (else
        (call-with-current-continuation
         (lambda (exit)
           (handle-exceptions exn
               (begin
                 ;(signal exn)
                 (fail-current-example-with! (sprintf "Error: ~S~%~A"
                                                      ((condition-property-accessor 'exn 'message) exn)
                                                      (format-condition-properties exn '(message call-chain)))))
             (call-with-exit-handler behaviour (make-exit-handler exit result)))))))
       result)))

(define (call-with-exit-handler code handler)
  (parameterize ((current-exit-continuation handler))
    (code)))

(define (make-exit-handler exit result)
  (lambda (status)
    (example-result-status-set! result status)
    (exit #f)))

(define (pending)
  (when (current-exit-continuation)
    ((current-exit-continuation) 'pending)))

(define (fail-current-example-with! message)
  (let ((result (current-example-result)))
    (when result
      (example-result-status-set! result 'failed)
      (add-failure-to-example-result result message)
      (when (current-exit-continuation)
        ((current-exit-continuation) 'failed)))))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Example-Result
;;
;; This is the result of an example run.
;; It holds statistics about the example run that is used by the
;; reporting-module
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(define-record example-result status messages example spec-file)

(define current-example-result (make-parameter #f))

(define (example-failed? result)
  ;(printf "~A~%" (example-result-messages result))
  (eq? 'failed (example-result-status result)))

(define (example-pending? result)
  (eq? 'pending (example-result-status result)))

(define (add-failure-to-example-result result message)
  (let ((messages (example-result-messages result)))
    (example-result-messages-set! result (append messages message))))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Expectation
;;
;; Expectations are the heart of your descriptions
;; they allow you to formulate assertions that make up your example
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(define negative-expectation (make-parameter #f))
(define-for-syntax current-shorthand-matcher (make-parameter #f))

(define-syntax expect
  (syntax-rules ()
    ((_ form)
     (run-expectation
      (quote form)
      (delay #f)
      (make-matcher
       (lambda (_) form)
       (lambda (_ subject negate)
         (if negate
             (sprintf "Expected ~S not to evaluate to true but it did" (quote form))
             (sprintf "Expected ~S to be true but was false" (quote form)))))
      (negative-expectation)))
    ((_ subject matcher)
     (run-expectation
      (quote subject)
      (delay subject) matcher
      (negative-expectation)))))

(define (run-expectation form subject matcher #!optional (negate #f))
  (let ((check (matcher-check matcher)))
    (cond
     (negate
      (when (check subject)
        (fail-current-example-with! (generate-failure-message matcher form subject #t))))
     (else
      (unless (check subject)
        (fail-current-example-with! (generate-failure-message matcher form subject #f)))))))

;;
;; TODO finish this so that we can set the short-hand later
;; sth like
;; (define-for-syntax +default-shorthand-matcher+ #f)
;; (define-syntax expect
;;   (lambda (form rename env)
;;     (let ((%run-expectation (rename 'run-expectation))
;;           (%delay (rename 'delay))
;;           (%make-matcher (rename 'make-matcher))
;;           (%quote (rename 'quote))
;;           (%negative-expectation (rename 'negative-expectation)))
;;       (match form
;;         (
;;          (_ subject => a0 a1 ...)
;;           (if +default-shorthand-matcher+
;;           `(,%expect ,subject (,+default-shorthand-matcher+ a0 a1 ...))
;;            (syntax-error "You need to set the +default-shorthand-matcher+" )))
;;          (_ frm)
;;          `(,%run-expectation
;;            (,%quote ,frm)
;;            (,%delay #f)
;;            (,%make-matcher
;;             (lambda (s) ,frm)
;;             (lambda
;;              (f subject negate)
;;              (if negate
;;                  (sprintf "Expected ~S not to evaluate to true but it did" (,%quote ,frm))
;;                  (sprintf "Expected ~S to be true but was false" (,%quote ,frm)))))))
;;         ((_ subject matcher)
;;          `(,%run-expectation (,%quote subject) (,%delay subject) ,matcher (,%negative-expectation)))))))





(define-syntax do-not
  (syntax-rules ()
    ((_ expectation)
     (parameterize ((negative-expectation #t))
       expectation))))

(define-syntax to
  (syntax-rules ()
    ((_ form)
     form)))


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Matcher
;; 
;; A matcher is responsible to check if a certain behaviour
;; is present. It's a check agains the existing behaviour.
;; Matchers do generate failure-messages if the expectation is not met
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(define-record matcher check failure-message-generator)

(define (generate-failure-message matcher form subject #!optional (negate #f))
  (let ((message-generator (matcher-failure-message-generator matcher)))
    (message-generator form subject negate)))

(define-syntax matcher
  (syntax-rules (check message)
    ((_ (check (subject) code more-code ...)
        (message (form message-subject negate) msg-code more-msg-code ...))
     (make-matcher
      (lambda (subject) code more-code ...)
      (lambda (form message-subject negate) msg-code more-msg-code ...)))))


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; State
;;
;; This is a simple mechanism to maintain state between examples. It
;; can be used in situations where a simple let over the examples
;; doesn't suffice. 
;; This will most likely be used in setup/teardown code.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(define *state* (make-hash-table))

(define ($ variable #!key (default #f))
  (hash-table-ref/default *state* variable default))

(define (reset-state!)
  (hash-table-clear! *state*))

(define (set-state! key value)
  (hash-table-set! *state* key value))

(set! (setter $) set-state!)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Reporting
;; 
;; At some point we need to notify the programmer about the state of her expectations.
;; The reporter is responsible for presenting the result to the user.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(define (make-standard-reporter #!key (report-port (current-output-port)))
  (let ((failed 0)
        (successful 0)
        (pending 0))
    (lambda (data #!key (mode 'adhoc))
      (cond
       ((eq? mode 'summary)
        (fprintf report-port "~%~%Total: ~A Successful: ~A Failed: ~A Pending: ~A ~%"
                 (+ failed successful pending) successful failed pending)
        (= failed 0))
       ((context? data) #t)
       ((example? data) #t)
       ((example-result? data)
        (let ((example (example-result-example data)))
          (cond
           ((example-failed? data)
            (set! failed (+ 1 failed))
            (fprintf report-port "Failure: ~A~%" (example-result-messages data)))
           ((example-pending? data)
            (set! pending (+ 1 pending))
            (fprintf report-port "Pending: ~A~%"  (example-description example)))
           (else
            (set! successful (+ 1 successful))
            (fprintf report-port "Success: ~A~%" (example-description example))))
          (flush-output report-port)))))))

)