1 ;;;; eval.test --- tests guile's evaluator -*- scheme -*-
2 ;;;; Copyright (C) 2000, 2001 Free Software Foundation, Inc.
4 ;;;; This library is free software; you can redistribute it and/or
5 ;;;; modify it under the terms of the GNU Lesser General Public
6 ;;;; License as published by the Free Software Foundation; either
7 ;;;; version 2.1 of the License, or (at your option) any later version.
9 ;;;; This library is distributed in the hope that it will be useful,
10 ;;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
11 ;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 ;;;; Lesser General Public License for more details.
14 ;;;; You should have received a copy of the GNU Lesser General Public
15 ;;;; License along with this library; if not, write to the Free Software
16 ;;;; Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 (define-module (test-suite test-eval)
19 :use-module (test-suite lib)
20 :use-module (ice-9 documentation))
23 (define exception:bad-expression
24 (cons 'syntax-error "Bad expression"))
31 (define (documented? object)
32 (not (not (object-documentation object))))
39 (with-test-prefix "memoization"
41 (with-test-prefix "copy-tree"
43 (pass-if "(#t . #(#t))"
44 (let* ((foo (cons #t (vector #t)))
45 (bar (copy-tree foo)))
46 (vector-set! (cdr foo) 0 #f)
47 (equal? bar '(#t . #(#t)))))
49 (pass-if-exception "circular lists in forms"
50 exception:bad-expression
51 (let ((foo (list #f)))
55 (pass-if "transparency"
57 (eval x (current-module))
58 (equal? '(begin 1) x))))
65 (with-test-prefix "evaluator"
67 (with-test-prefix "symbol lookup"
69 (with-test-prefix "top level"
71 (with-test-prefix "unbound"
73 (pass-if-exception "variable reference"
77 (pass-if-exception "procedure"
81 (with-test-prefix "parameter error"
83 ;; This is currently a bug in guile:
84 ;; Macros are accepted as function parameters.
85 ;; Functions that 'apply' macros are rewritten!!!
87 (expect-fail-exception "macro as argument"
88 exception:wrong-type-arg
89 (let ((f (lambda (p a b) (p a b))))
92 (expect-fail-exception "passing macro as parameter"
93 exception:wrong-type-arg
94 (let* ((f (lambda (p a b) (p a b)))
95 (foo (procedure-source f)))
97 (equal? (procedure-source f) foo)))
105 (with-test-prefix "application"
107 (with-test-prefix "wrong number of arguments"
109 (pass-if-exception "((lambda () #f) 1)"
110 exception:wrong-num-args
113 (pass-if-exception "((lambda (x) #f))"
114 exception:wrong-num-args
117 (pass-if-exception "((lambda (x) #f) 1 2)"
118 exception:wrong-num-args
119 ((lambda (x) #f) 1 2))
121 (pass-if-exception "((lambda (x y) #f))"
122 exception:wrong-num-args
125 (pass-if-exception "((lambda (x y) #f) 1)"
126 exception:wrong-num-args
127 ((lambda (x y) #f) 1))
129 (pass-if-exception "((lambda (x y) #f) 1 2 3)"
130 exception:wrong-num-args
131 ((lambda (x y) #f) 1 2 3))
133 (pass-if-exception "((lambda (x . rest) #f))"
134 exception:wrong-num-args
135 ((lambda (x . rest) #f)))
137 (pass-if-exception "((lambda (x y . rest) #f))"
138 exception:wrong-num-args
139 ((lambda (x y . rest) #f)))
141 (pass-if-exception "((lambda (x y . rest) #f) 1)"
142 exception:wrong-num-args
143 ((lambda (x y . rest) #f) 1))))
149 (with-test-prefix "map"
151 ;; Is documentation available?
153 (expect-fail "documented?"
156 (with-test-prefix "argument error"
158 (with-test-prefix "non list argument"
161 (with-test-prefix "different length lists"
163 (pass-if-exception "first list empty"
164 exception:out-of-range
167 (pass-if-exception "second list empty"
168 exception:out-of-range
171 (pass-if-exception "first list shorter"
172 exception:out-of-range
175 (pass-if-exception "second list shorter"
176 exception:out-of-range
184 (with-test-prefix "promises"
186 (with-test-prefix "basic promise behaviour"
188 (pass-if "delay gives a promise"
189 (promise? (delay 1)))
191 (pass-if "force evaluates a promise"
192 (eqv? (force (delay (+ 1 2))) 3))
194 (pass-if "a forced promise is a promise"
195 (let ((p (delay (+ 1 2))))
199 (pass-if "forcing a forced promise works"
200 (let ((p (delay (+ 1 2))))
204 (pass-if "a promise is evaluated once"
211 (pass-if "a promise may call itself"
217 (if (> x 1) x (force p))))))
220 (pass-if "a promise carries its environment"
223 (set! p (delay (+ x 1))))
226 (pass-if "a forced promise does not reference its environment"
227 (let* ((g (make-guardian))
229 (let* ((x (cons #f #f)))
231 (set! p (delay (car x))))
234 (if (not (equal? (g) (cons #f #f)))
238 (with-test-prefix "extended promise behaviour"
240 (pass-if-exception "forcing a non-promise object is not supported"
241 exception:wrong-type-arg
244 (pass-if-exception "implicit forcing is not supported"
245 exception:wrong-type-arg
246 (+ (delay (* 3 7)) 13))))
248 ;;; eval.test ends here