(import test) (import type-checks) (import variable-item) (define (with-error-to-string thunk) (parameterize ((current-error-port (open-output-string))) (thunk) (get-output-string (current-error-port)) ) ) (test-group "Make Variable Item" (define t (make-variable 23 (lambda (x) (check-integer 't x)))) (test-error "Not an Integer" (t 'foo)) (test-assert "An Integer" (t 8)) (test "Value" 8 (t)) (test-assert "SRFI 17" (set! (t) 32)) (test "Value Set" 32 (t)) ) (test-group "Variable Item Warn" (define-warning-variable tw 23 integer) (test "Not an Integer" "\nWarning: (tw) bad argument type - not an integer: foo\n" (with-error-to-string (lambda () (tw 'foo)))) ) (test-group "Variable Item Error" (define-checked-variable tc 23 integer) (test-error "Not an Integer" (tc 'foo)) ) (test-group "Variable Item Error 2" (define *flag* #f) (define (flagger) (set! *flag* #t)) (define-checked-variable tc 23 integer (flagger)) (set! *flag* #f) ;guard is used on init so must reset (test-error "Not an Integer" (tc 'foo)) (test-assert (not *flag*)) (test-assert "Is an Integer" (tc 23)) (test-assert *flag*) ) #; ;NOT READY (test-group "fluid variable" (define-checked-variable tc 23 integer) (fluid-variable ((tc 1)) (test "current value" 1 (tc)) ) (test "original value" 23 (tc)) ) (test-exit)