-
Notifications
You must be signed in to change notification settings - Fork 1
/
assert.scm
39 lines (35 loc) · 1.73 KB
/
assert.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
;;;
;;; assert-scm - Minimalist xUnit test framework for Scheme R5RS, Gambit extension.
;;; https://github.com/codecop/assert-scm
;;; Copyright (c) 2015, Peter Kofler, BSD 3-Clause License
;;;
(include "assert-r5rs.scm")
(define (-error->string ex)
(cond ((null? ex) "")
((string? ex) ex)
((symbol? ex) (symbol->string ex))
((list? ex) (string-append " (" (apply string-append (map -error->string ex)) ")"))
;; Gambit specific code
((error-exception? ex) (-error->string (error-exception-message ex)))
((unbound-global-exception? ex) (-error->string (unbound-global-exception-variable ex))) ; variable name
((type-exception? ex) (string-append "expected " (-error->string (type-exception-type-id ex)))) ; type name
(else (pp ex)
"<unknown exception type>")))
(define (-run-with-exception-handler handler body)
;; Gambit specific code
(with-exception-catcher handler body))
(define (assert-raise expected-ex body)
(define (ex-handler ex)
(let ((expected-message (-error->string expected-ex))
(actual-message (-error->string ex)))
(check (-make-string-message "raise " -error->string expected-ex ex)
(string=? expected-message actual-message))))
(define (ex-body)
(body)
(error "no raise in body"))
(lambda ()
(-run-with-exception-handler ex-handler ex-body)))
(define-macro (ignored-test-case name . assertions)
`(begin
(-test-case-name ,name)
(-test-case-ignored)))