Commit | Line | Data |
---|---|---|
dab514a8 MV |
1 | ;;;; -*- scheme -*- |
2 | ;;;; continuations.test --- test suite for continutations | |
3 | ;;;; | |
6e7d5622 | 4 | ;;;; Copyright (C) 2003, 2006 Free Software Foundation, Inc. |
dab514a8 | 5 | ;;;; |
53befeb7 NJ |
6 | ;;;; This library is free software; you can redistribute it and/or |
7 | ;;;; modify it under the terms of the GNU Lesser General Public | |
8 | ;;;; License as published by the Free Software Foundation; either | |
9 | ;;;; version 3 of the License, or (at your option) any later version. | |
dab514a8 | 10 | ;;;; |
53befeb7 | 11 | ;;;; This library is distributed in the hope that it will be useful, |
dab514a8 | 12 | ;;;; but WITHOUT ANY WARRANTY; without even the implied warranty of |
53befeb7 NJ |
13 | ;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
14 | ;;;; Lesser General Public License for more details. | |
dab514a8 | 15 | ;;;; |
53befeb7 NJ |
16 | ;;;; You should have received a copy of the GNU Lesser General Public |
17 | ;;;; License along with this library; if not, write to the Free Software | |
18 | ;;;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | |
dab514a8 MV |
19 | |
20 | (define-module (test-suite test-continuations) | |
21 | :use-module (test-suite lib)) | |
22 | ||
23 | (define (block-reentry body) | |
24 | (let ((active #f)) | |
25 | (dynamic-wind | |
26 | (lambda () | |
27 | (if active | |
28 | (throw 'no-reentry))) | |
29 | (lambda () | |
30 | (set! active #t) | |
31 | (body)) | |
32 | (lambda () #f)))) | |
33 | ||
34 | (define (catch-tag body) | |
35 | (catch #t | |
36 | body | |
37 | (lambda (tag . args) tag))) | |
38 | ||
39 | (define (check-cont) | |
40 | (catch-tag | |
41 | (lambda () | |
42 | (block-reentry (lambda () (call/cc identity)))))) | |
43 | ||
44 | (define (dont-crash-please) | |
45 | (let ((k (check-cont))) | |
46 | (if (procedure? k) | |
47 | (k 12) | |
48 | k))) | |
49 | ||
50 | (with-test-prefix "continuations" | |
51 | ||
52 | (pass-if "throwing to a rewound catch context" | |
d241f86a NJ |
53 | (eq? (dont-crash-please) 'no-reentry)) |
54 | ||
2d04022c | 55 | (with-debugging-evaluator |
d241f86a NJ |
56 | |
57 | (pass-if "make a stack from a continuation" | |
58 | (stack? (call-with-current-continuation make-stack))) | |
59 | ||
60 | (pass-if "get a continuation's stack ID" | |
61 | (let ((id (call-with-current-continuation stack-id))) | |
62 | (or (boolean? id) (symbol? id)))) | |
63 | ||
64 | (pass-if "get a continuation's innermost frame" | |
2d04022c | 65 | (pair? (call-with-current-continuation last-stack-frame)))) |
d241f86a NJ |
66 | |
67 | ) |