;;;; condition-utils-test.scm -*- Scheme -*- ;;;; Kon Lovett, Jul '18 (import test) (import (only (chicken format) format) (test-utils gloss)) (test-begin "Condition Utils") ;;; (import condition-utils exn-condition) (import (chicken condition) (chicken port)) (define testc (make-exn-condition+ 'test "test" '(test) 'misc '(extra test 23))) (define testc? (make-condition-predicate exn misc extra)) (test-assert "composite of exn test extra" (testc? testc)) (test "test property of extra component of (exn test extra)" 23 ((condition-property-accessor 'extra 'test) testc)) (define testc-extra-test (make-condition-property-accessor extra test)) (define testc-extra-foo (make-condition-property-accessor extra foo 'foobar)) (test 23 (testc-extra-test testc)) (test 'foobar (testc-extra-foo testc)) (test-assert (call-chain? (get-call-chain 1))) (test-assert (call-chain? (get-call-chain 0))) (define testcc) (let ((chn (get-call-chain 1))) (set! testcc (make-exn-condition+ 'test "test" '(test) ;std chn ;+ 1 'misc '(extra test 23))) ) ;cnds (test-assert "composite of exn test extra (set!)" (testc? testcc)) ;C5 is a plist (define wr-exn-res "\nError: (test) test: test\n +: misc:\n +: extra: test 23\n") (test "may fail - order an issue" wr-exn-res (with-output-to-string (lambda () (write-exn-condition testc)))) (test-assert (exn-condition? testc)) (test 'test (exn-location testc)) (test "test" (exn-message testc)) (test '(test) (exn-arguments testc)) (test #f (exn-call-chain testc)) (import standard-conditions) (import http-client-conditions) (import intarweb-conditions) (define thttpc (make-exn-condition+ 'test "test" '(test) 'http '(extra test 23))) (test-assert (http-condition? thttpc)) ;C5 is a plist (define irr-res '(location test message "test" arguments (test) test 23)) (test irr-res (condition-irritants thttpc)) (gloss) (gloss "Writing exn condition") (gloss " (expect an \"error\")") (gloss "---------------------") (gloss (call-with-output-string (lambda (port) (write-exn-condition testcc port)))) (test "write exn-condition" (cond-expand (compiling " Error: (test) test: test +: misc: +: extra: test 23 " ) (else " Error: (test) test: test +: misc: +: extra: test 23 \tCall history: \t\t (let ((chn (get-call-chain 1))) (set! testcc (make-exn-condition+ (quote test) \"test\" (quote (test))... \t\t (##core#let ((chn (get-call-chain 1))) (set! testcc (make-exn-condition+ (quote test) \"test\" (quote ... \t\t (##core#begin (##core#set! testcc (make-exn-condition+ (quote test) \"test\" (quote (test)) chn (quote... \t\t (##core#set! testcc (make-exn-condition+ (quote test) \"test\" (quote (test)) chn (quote misc) (quote ... \t\t (make-exn-condition+ (quote test) \"test\" (quote (test)) chn (quote misc) (quote (extra test 23))) \t\t (quote test) \t\t (##core#quote test) \t\t (quote (test)) \t\t (##core#quote (test)) \t\t (quote misc) \t\t (##core#quote misc) \t\t (quote (extra test 23)) \t\t (##core#quote (extra test 23)) \t\t (get-call-chain 1) \t\t (get-call-chain 1)\t<-- " ) ) (with-output-to-string (lambda () (write-exn-condition testcc)))) ;;; (test-end "Condition Utils") (test-exit)