-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmitscheme-conditions.scm
71 lines (64 loc) · 3.23 KB
/
mitscheme-conditions.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
;;; ----------------------------------------------------------------------
;;; Copyright 2007-2008 Alexey Radul.
;;; ----------------------------------------------------------------------
;;; This file is part of Test Manager.
;;;
;;; Test Manager is free software; you can redistribute it and/or modify
;;; it under the terms of the GNU General Public License as published by
;;; the Free Software Foundation, either version 3 of the License, or
;;; (at your option) any later version.
;;;
;;; Test Manager is distributed in the hope that it will be useful,
;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;;; GNU General Public License for more details.
;;;
;;; You should have received a copy of the GNU General Public License
;;; along with Test Manager. If not, see <http://www.gnu.org/licenses/>.
;;; ----------------------------------------------------------------------
;;; These are the definitions that are actively intertwined with MIT
;;; Scheme's condition system, which this test manager originally
;;; used. They are replaced by equivalent (I hope) domain-specific
;;; definitions tailored for other condition systems in other
;;; *-conditions.scm files.
(define condition-type:test-failure
(make-condition-type 'test-failure condition-type:error
'(message) (lambda (condition port)
(display (access-condition condition 'message) port))))
(define condition/test-failure?
(condition-predicate condition-type:test-failure))
(define test-fail
(condition-signaller condition-type:test-failure
'(message) standard-error-handler))
;;; Gaah! The signaling of a condition in a flexible language like
;;; Scheme does not, unlike the raising of an exception in Java,
;;; entail that the code signaling the condition failed. In fact, it
;;; is quite possible that the condition will be handled by some
;;; toplevel condition handler in a manner that will cause the
;;; underlying code to continue, and eventually produce a normal
;;; return. For example, Mechanics allows vectors to be applied by
;;; just such a mechanism. The unit test framework must,
;;; consequently, try its best to allow such shenanigans to succeed,
;;; without disrupting the operation of the test framework itself.
;;; Hence the ugliness below.
;;; TODO Port this crap to Guile
(define (capture-unhandled-errors thunk)
(if (lexical-unbound? system-global-environment 'let-fluids)
(capture-unhandled-errors-pre-let-fluids thunk)
(capture-unhandled-errors-post-let-fluids thunk)))
(define (capture-unhandled-errors-pre-let-fluids thunk)
(if standard-error-hook
;; Fix this for the test-within-a-test case.
(warn "If the standard error hook is already bound, I can't be sure which errors are unhandled."))
(call-with-current-continuation
(lambda (k)
(fluid-let ((standard-error-hook k))
(thunk)))))
(define (capture-unhandled-errors-post-let-fluids thunk)
(if (fluid standard-error-hook)
;; Fix this for the test-within-a-test case.
(warn "If the standard error hook is already bound, I can't be sure which errors are unhandled."))
(call-with-current-continuation
(lambda (k)
(let-fluids standard-error-hook k
thunk))))