-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathcatch.lsp
109 lines (89 loc) · 2.01 KB
/
catch.lsp
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
;-*- Mode: Lisp -*-
;;;; Author: Paul Dietz
;;;; Created: Sat Oct 12 13:04:02 2002
;;;; Contains: Tests of CATCH and THROW
(in-package :cl-test)
(deftest catch.1
(catch 'foo)
nil)
(deftest catch.2
(catch 'foo 'a)
a)
(deftest catch.3
(catch 'foo (values)))
(deftest catch.4
(catch 'foo (values 1 2 3))
1 2 3)
(deftest catch.5
(catch 'foo 'a (throw 'foo 'b) 'c)
b)
;;
;; The test below is wrong:
;; Numbers can't be assumed to be EQ at
;; any time by conforming programs.
;;
;; (deftest catch.6
;; (let ((tag1 (1+ most-positive-fixnum))
;; (tag2 (1+ most-positive-fixnum)))
;; (if (eqt tag1 tag2)
;; 'good
;; (catch tag1
;; (catch tag2 (throw tag1 'good))
;; 'bad)))
;; good)
(deftest catch.7
(catch 'foo 'a (throw 'foo (values)) 'c))
(deftest catch.8
(catch 'foo 'a (throw 'foo (values 1 2 3)) 'c)
1 2 3)
(deftest catch.9
(let ((i 0))
(catch (progn (incf i) 'foo)
(assert (eql i 1))
(throw (progn (incf i 2) 'foo) i)))
3)
(deftest catch.10
(flet ((%f (x) (throw 'foo x)))
(catch 'foo
(%f 'good)
'bad))
good)
(defun catch.11-fn (x) (throw 'foo x))
(deftest catch.11
(catch 'foo
(catch.11-fn 'good)
'bad)
good)
(deftest catch.12
(labels ((%f (x) (throw 'foo x)))
(catch 'foo
(%f 'good)
'bad))
good)
;;; No implicit tagbody
(deftest catch.13
(block done
(tagbody
(catch 'foo
(go 10)
10
(return-from done 'bad))
10
(return-from done 'good)))
good)
;;; Macros are expanded in the appropriate environment
(deftest catch.14
(macrolet ((%m (z) z))
(catch 'foo (expand-in-current-env (%m :good))))
:good)
(deftest catch.15
(macrolet ((%m (z) z))
(catch 'foo (throw (expand-in-current-env (%m 'foo)) :good) :bad))
:good)
(deftest catch.16
(macrolet ((%m (z) z))
(catch 'foo (throw 'foo (expand-in-current-env (%m :good))) :bad))
:good)
(deftest throw-error
(signals-error (throw (gensym) nil) control-error)
t)