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