~ chicken-core (chicken-5) /tests/condition-tests.scm
Trap1(import (chicken condition))23(define condition1 (make-property-condition 'exn 'message "foo" 'arguments '("bar") 'location 'test))4(define condition2 (make-property-condition 'sam 'age 23 'partner "max"))5(define condition3 (make-composite-condition (make-property-condition 'exn 'message "foo" 'arguments '("bar") 'location 'test)(make-property-condition 'sam 'age 23 'partner "max")))67(define conditions (list condition1 condition2 condition3))89; testing type predicate10(for-each (lambda (c) (assert (condition? c))) conditions)1112;testing slot allocations13; slot 1 should be the kind key14; slot 2 should hold all properties1516(assert (and (equal? '(exn) (##sys#slot condition1 1))17 (equal? '(sam) (##sys#slot condition2 1))18 (equal? '(exn sam) (##sys#slot condition3 1))))1920(assert (equal? (##sys#slot condition1 2)21 '((exn . message) "foo" (exn . arguments) ("bar") (exn . location) test)))2223(assert (equal? (##sys#slot condition3 2)24 '((exn . message) "foo" (exn . arguments) ("bar") (exn . location) test25 (sam . age) 23 (sam . partner) "max")))2627;testing condition conversion2829(assert (equal? (condition->list condition1)30 '((exn message "foo" arguments ("bar") location test))))3132(assert (equal? (condition->list condition3)33 '((exn message "foo" arguments ("bar") location test)34 (sam age 23 partner "max"))))3536;; testing errno in condition objects3738(import (chicken errno)39 (chicken file)40 (chicken process-context))4142(let ((nonexistent-path "this/path/does/not/exist/,hopefully"))43 (assert (not (file-exists? nonexistent-path)))4445 (handle-exceptions exn46 (assert (= (get-condition-property exn 'exn 'errno) errno/noent))47 (delete-file nonexistent-path))4849 (handle-exceptions exn50 (assert (= (get-condition-property exn 'exn 'errno) errno/noent))51 (change-directory nonexistent-path)))