-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathst-conditions-tests.scm
79 lines (66 loc) · 1.99 KB
/
st-conditions-tests.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
;;; IMPLEMENTS: Unit tests for st-conditions.scm
;;; AUTHOR: Ken Dickey
;;; DATE: 16 January 2017
;; (require 'st-conditions)
(define zero-divide #f)
(define frob-error #f)
(define write-to-non-port #f)
;; (define-syntax capture-condition ;; to explore
;; (syntax-rules ()
;; ((capture-condition form)
;; ;;==>
;; (call/cc
;; (lambda (exit)
;; (with-exception-handler
;; (lambda (c) (exit c))
;; (lambda () form))))
;; ) ) )
(define (setup-st-conditions)
(set! zero-divide
(capture-condition (/ 3 0)))
(set! frob-error
(capture-condition
(error "frob" 'a "bee" #\c 47)))
(set! write-to-non-port
(capture-condition (write 3 0)))
)
(define (cleanup-st-conditions)
(set! zero-divide #f)
(set! frob-error #f)
(set! write-to-non-port #f)
)
(add-test-suite 'st-conditions
setup-st-conditions
cleanup-st-conditions)
(add-equivalent-alist-test 'st-conditions
;;(add-equal-test 'st-conditions
'((isMessage . #t)
(message . "/: zero divisor: 3 0 \n")
(isWho . #t)
(isAssertion . #t)
(who . "/"))
(dict->alist (condition->dictionary zero-divide))
"zero-divide condition asDictionary")
(add-equivalent-alist-test 'st-conditions
'((isMessage . #t)
(isError . #t)
(message . "frob")
(irritants a "bee" #\c 47)
(isIrritants . #t))
(dict->alist (condition->dictionary frob-error))
"Scheme error condition asDictionary")
(add-equivalent-alist-test 'st-conditions
'((isMessage . #t)
(isError . #t)
(message . "not a textual output port")
(isWho . #t)
(who . write-char)
(irritants 0)
(isIrritants . #t))
(dict->alist (condition->dictionary write-to-non-port))
"write-to-non-port condition asDictionary")
;; (ensure-exception-raised 'st-conditions
;; (make-error-string-predicate "Failed message send: #glerph to ")
;; (perform: %%test-object 'glerph)
;; "obj glerph -> doesNotUnderstand")
;;; --- E O F --- ;;;