2 ;;;; continuations.test --- test suite for continutations
4 ;;;; Copyright (C) 2003, 2006, 2009, 2011 Free Software Foundation, Inc.
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.
11 ;;;; This library 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 GNU
14 ;;;; Lesser General Public License for more details.
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
20 (define-module (test-suite test-continuations)
21 :use-module (test-suite lib))
23 (define (block-reentry body)
34 (define (catch-tag body)
37 (lambda (tag . args) tag)))
42 (block-reentry (lambda () (call/cc identity))))))
44 (define (dont-crash-please)
45 (let ((k (check-cont)))
50 (with-test-prefix "continuations"
52 (pass-if "throwing to a rewound catch context"
53 (eq? (dont-crash-please) 'no-reentry))
55 (pass-if "can print a continuation"
56 (let ((s (with-output-to-string
58 (call-with-current-continuation write)))))
59 (string=? "#<continuation " (substring s 0 15))))
61 (pass-if "blocked attempt to cross a continuation barrier"
62 (call-with-current-continuation
64 (with-continuation-barrier
73 (pass-if "uncaught exception is handled by continuation barrier"
75 (s (with-error-to-string
78 (not (with-continuation-barrier
80 (error "Catch me if you can!")))))))))
83 (pass-if "exit unwinds dynwinds inside a continuation barrier"
84 (let ((s (with-error-to-string
86 (with-continuation-barrier
91 (lambda () (throw 'abcde)))))))))
92 (and (string-contains s "abcde") #t)))
94 (with-debugging-evaluator
96 (pass-if "make a stack from a continuation"
97 (stack? (call-with-current-continuation make-stack)))
99 (pass-if "get a continuation's stack ID"
100 (let ((id (call-with-current-continuation stack-id)))
101 (or (boolean? id) (symbol? id)))))