source: project/release/5/sandbox/trunk/tests/run.scm @ 36055

Last change on this file since 36055 was 36055, checked in by Kooda, 14 months ago

Port the sandbox egg to CHICKEN 5

File size: 1.4 KB
Line 
1(import (chicken condition) sandbox) 
2
3(define-syntax assert-error
4  (syntax-rules ()
5    ((_ x)
6     (handle-exceptions ex 
7       (begin
8         (print-error-message ex)
9         #t)
10       x #f))))
11
12(assert (= 123 (safe-eval 123)))    ;-->   123
13
14(assert-error (safe-eval 'abc))   ;-->   error
15
16(define env (make-safe-environment))
17
18(assert-error (safe-eval '(+ 3 4) environment: env))   ;-->   error: environment is empty and has no parent
19
20(define env2 (make-safe-environment parent: default-safe-environment))
21
22(assert (= 7 (safe-eval '(+ 3 4) environment: env2)))  ;-->   7
23
24(assert-error (safe-eval '(define abc 99) environment: (make-safe-environment extendable: #f))) ;--> error
25(assert-error (safe-eval '(define abc 99) environment: env2)) ;--> error
26
27(assert-error (safe-eval '(set! + 100)))                     ;-->  error: binding not mutable
28(assert-error (safe-eval '(set! + 100) environment: env2))   ;-->  error: the same (binding is inherited)
29(assert-error (safe-eval '(set! abc 100) environment: env2))  ;-->  error
30
31;(safe-eval '(let loop () (loop)))             ;-->  never terminates
32(assert-error (safe-eval '(let loop () (loop)) fuel: 1000))  ;-->  signals error ("out of fuel")
33
34(assert (vector? (safe-eval '(make-vector 100))))                ;-->  a 100-element vector
35(assert-error (safe-eval '(make-vector 100) allocation-limit: 100))  ;--> error ("allocation limit exceeded")
Note: See TracBrowser for help on using the repository browser.