1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-05-04 05:50:26 +02:00
guile/test-suite/tests/dynamic-scope.test
Dirk Herrmann d6e04e7c4a * lib.scm (exception:missing-expression): New.
* tests/dynamic-scope.test, tests/eval.test,
	tests/r5rs_pitfall.test, tests/srfi-17.test, tests/syncase.test:
	Wrap tests in module (test-suite test-<file-name without .test>),
	following a practice that was used on a couple of files already.

	* tests/dynamic-scope.test (exception:duplicate-binding,
	exception:bad-binding): New.

	* tests/dynamic-scope.test, tests/srfi-17.test, tests/syntax.test:
	Execute syntactically wrong tests using eval.  With the upcoming
	new memoizer this is necessary in order to postpone the syntax
	check to the actual evaluation of the syntactically wrong form.

	* tests/syntax.test: Added some test cases and modified one test
	case.
2003-10-07 22:00:05 +00:00

89 lines
2.6 KiB
Scheme

;;;; -*- scheme -*-
;;;; dynamic-scop.test --- test suite for dynamic scoping constructs
;;;;
;;;; Copyright (C) 2001 Free Software Foundation, Inc.
;;;;
;;;; This program is free software; you can redistribute it and/or modify
;;;; it under the terms of the GNU General Public License as published by
;;;; the Free Software Foundation; either version 2, or (at your option)
;;;; any later version.
;;;;
;;;; This program is distributed in the hope that it will be useful,
;;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;;;; GNU General Public License for more details.
;;;;
;;;; You should have received a copy of the GNU General Public License
;;;; along with this software; see the file COPYING. If not, write to
;;;; the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
;;;; Boston, MA 02111-1307 USA
(define-module (test-suite test-dynamic-scope)
:use-module (test-suite lib))
(define exception:duplicate-binding
(cons 'misc-error "^duplicate bindings"))
(define exception:bad-binding
(cons 'misc-error "^bad bindings"))
(define global-a 0)
(define (fetch-global-a) global-a)
(with-test-prefix "dynamic scope"
(pass-if "@bind binds"
(= (@bind ((global-a 1)) (fetch-global-a)) 1))
(pass-if "@bind unbinds"
(begin
(set! global-a 0)
(@bind ((global-a 1)) (fetch-global-a))
(= global-a 0)))
(pass-if-exception "duplicate @binds"
exception:duplicate-binding
(eval '(@bind ((a 1) (a 2)) (+ a a))
(interaction-environment)))
(pass-if-exception "@bind missing expression"
exception:missing-expression
(eval '(@bind ((global-a 1)))
(interaction-environment)))
(pass-if-exception "@bind bad bindings"
exception:bad-binding
(eval '(@bind (a) #f)
(interaction-environment)))
(pass-if-exception "@bind bad bindings"
exception:bad-binding
(eval '(@bind ((a)) #f)
(interaction-environment)))
(pass-if "@bind and dynamic-wind"
(letrec ((co-routine #f)
(spawn (lambda (proc)
(set! co-routine proc)))
(yield (lambda (val)
(call-with-current-continuation
(lambda (k)
(let ((next co-routine))
(set! co-routine k)
(next val)))))))
(spawn (lambda (val)
(@bind ((global-a 'inside))
(yield global-a)
(yield global-a))))
(set! global-a 'outside)
(let ((inside-a (yield #f)))
(let ((outside-a global-a))
(let ((inside-a2 (yield #f)))
(and (eq? inside-a 'inside)
(eq? outside-a 'outside)
(eq? inside-a2 'inside))))))))