source: trunk/source/tests/ansi-tests/catch.lsp @ 8991

Last change on this file since 8991 was 8991, checked in by gz, 12 years ago

Check in the gcl ansi test suite (original, in preparation for making local changes)

File size: 1.8 KB
Line 
1;-*- Mode:     Lisp -*-
2;;;; Author:   Paul Dietz
3;;;; Created:  Sat Oct 12 13:04:02 2002
4;;;; Contains: Tests of CATCH and THROW
5
6(in-package :cl-test)
7
8(deftest catch.1
9  (catch 'foo)
10  nil)
11
12(deftest catch.2
13  (catch 'foo 'a)
14  a)
15
16(deftest catch.3
17  (catch 'foo (values)))
18
19(deftest catch.4
20  (catch 'foo (values 1 2 3))
21  1 2 3)
22
23(deftest catch.5
24  (catch 'foo 'a (throw 'foo 'b) 'c)
25  b)
26
27(deftest catch.6
28  (let ((tag1 (1+ most-positive-fixnum))
29        (tag2 (1+ most-positive-fixnum)))
30    (if (eqt tag1 tag2)
31        'good
32      (catch tag1
33        (catch tag2 (throw tag1 'good))
34        'bad)))
35  good)
36
37(deftest catch.7
38  (catch 'foo 'a (throw 'foo (values)) 'c))
39
40(deftest catch.8
41  (catch 'foo 'a (throw 'foo (values 1 2 3)) 'c)
42  1 2 3)
43
44(deftest catch.9
45  (let ((i 0))
46    (catch (progn (incf i) 'foo)
47      (assert (eql i 1))
48      (throw (progn (incf i 2) 'foo) i)))
49  3)
50
51(deftest catch.10
52  (flet ((%f (x) (throw 'foo x)))
53    (catch 'foo
54      (%f 'good)
55      'bad))
56  good)
57
58(defun catch.11-fn (x) (throw 'foo x))
59
60(deftest catch.11
61  (catch 'foo
62    (catch.11-fn 'good)
63    'bad)
64  good)
65
66(deftest catch.12
67  (labels ((%f (x) (throw 'foo x)))
68    (catch 'foo
69      (%f 'good)
70      'bad))
71  good)
72
73;;; No implicit tagbody
74(deftest catch.13
75  (block done
76    (tagbody
77     (catch 'foo
78       (go 10)
79       10
80       (return-from done 'bad))
81     10
82     (return-from done 'good)))
83  good)
84
85;;; Macros are expanded in the appropriate environment
86
87(deftest catch.14
88  (macrolet ((%m (z) z))
89            (catch 'foo (expand-in-current-env (%m :good))))
90  :good)
91
92(deftest catch.15
93  (macrolet ((%m (z) z))
94            (catch 'foo (throw (expand-in-current-env (%m 'foo)) :good) :bad))
95  :good)
96
97(deftest catch.16
98  (macrolet ((%m (z) z))
99            (catch 'foo (throw 'foo (expand-in-current-env (%m :good))) :bad))
100  :good)
101
102(deftest throw-error
103  (signals-error (throw (gensym) nil) control-error)
104  t)
Note: See TracBrowser for help on using the repository browser.