]> git.donarmstrong.com Git - lilypond.git/blob - guile18/test-suite/tests/continuations.test
New upstream version 2.19.65
[lilypond.git] / guile18 / test-suite / tests / continuations.test
1 ;;;;                                                          -*- scheme -*-
2 ;;;; continuations.test --- test suite for continutations
3 ;;;;
4 ;;;; Copyright (C) 2003, 2006 Free Software Foundation, Inc.
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
18 ;;;; the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19 ;;;; Boston, MA 02110-1301 USA
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"
54     (eq? (dont-crash-please) 'no-reentry))
55
56   (with-debugging-evaluator
57
58     (pass-if "make a stack from a continuation"
59       (stack? (call-with-current-continuation make-stack)))
60
61     (pass-if "get a continuation's stack ID"
62       (let ((id (call-with-current-continuation stack-id)))
63         (or (boolean? id) (symbol? id))))
64
65     (pass-if "get a continuation's innermost frame"
66       (pair? (call-with-current-continuation last-stack-frame))))
67
68 )