2 ;;;; dynamic-scop.test --- test suite for dynamic scoping constructs
4 ;;;; Copyright (C) 2001, 2006, 2009 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-dynamic-scope)
21 :use-module (test-suite lib))
24 (define exception:syntax-error
25 (cons 'syntax-error "failed to match"))
26 (define exception:duplicate-binding
27 (cons 'syntax-error "duplicate"))
30 (define (fetch-global-a) global-a)
32 (with-test-prefix "dynamic scope"
34 (pass-if "@bind binds"
35 (= (@bind ((global-a 1)) (fetch-global-a)) 1))
37 (pass-if "@bind unbinds"
40 (@bind ((global-a 1)) (fetch-global-a))
43 (pass-if-exception "duplicate @binds"
44 exception:duplicate-binding
45 (eval '(@bind ((a 1) (a 2)) (+ a a))
46 (interaction-environment)))
48 (pass-if-exception "@bind missing expression"
49 exception:syntax-error
50 (eval '(@bind ((global-a 1)))
51 (interaction-environment)))
53 (pass-if-exception "@bind bad bindings"
54 exception:syntax-error
56 (interaction-environment)))
58 (pass-if-exception "@bind bad bindings"
59 exception:syntax-error
60 (eval '(@bind ((a)) #f)
61 (interaction-environment)))
63 (pass-if "@bind and dynamic-wind"
64 (letrec ((co-routine #f)
66 (set! co-routine proc)))
68 (call-with-current-continuation
70 (let ((next co-routine))
75 (@bind ((global-a 'inside))
79 (set! global-a 'outside)
80 (let ((inside-a (yield #f)))
81 (let ((outside-a global-a))
82 (let ((inside-a2 (yield #f)))
83 (and (eq? inside-a 'inside)
84 (eq? outside-a 'outside)
85 (eq? inside-a2 'inside))))))))