2 ;;;; dynamic-scop.test --- test suite for dynamic scoping constructs
4 ;;;; Copyright (C) 2001, 2006 Free Software Foundation, Inc.
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.
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.
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
21 (define-module (test-suite test-dynamic-scope)
22 :use-module (test-suite lib))
25 (define exception:missing-expr
26 (cons 'syntax-error "Missing expression"))
27 (define exception:bad-binding
28 (cons 'syntax-error "Bad binding"))
29 (define exception:duplicate-binding
30 (cons 'syntax-error "Duplicate binding"))
33 (define (fetch-global-a) global-a)
35 (with-test-prefix "dynamic scope"
37 (pass-if "@bind binds"
38 (= (@bind ((global-a 1)) (fetch-global-a)) 1))
40 (pass-if "@bind unbinds"
43 (@bind ((global-a 1)) (fetch-global-a))
46 (pass-if-exception "duplicate @binds"
47 exception:duplicate-binding
48 (eval '(@bind ((a 1) (a 2)) (+ a a))
49 (interaction-environment)))
51 (pass-if-exception "@bind missing expression"
52 exception:missing-expr
53 (eval '(@bind ((global-a 1)))
54 (interaction-environment)))
56 (pass-if-exception "@bind bad bindings"
59 (interaction-environment)))
61 (pass-if-exception "@bind bad bindings"
63 (eval '(@bind ((a)) #f)
64 (interaction-environment)))
66 (pass-if "@bind and dynamic-wind"
67 (letrec ((co-routine #f)
69 (set! co-routine proc)))
71 (call-with-current-continuation
73 (let ((next co-routine))
78 (@bind ((global-a 'inside))
82 (set! global-a 'outside)
83 (let ((inside-a (yield #f)))
84 (let ((outside-a global-a))
85 (let ((inside-a2 (yield #f)))
86 (and (eq? inside-a 'inside)
87 (eq? outside-a 'outside)
88 (eq? inside-a2 'inside))))))))