Skip to content

Commit

Permalink
Make Chicken/SRFI 12 code work.
Browse files Browse the repository at this point in the history
  • Loading branch information
codecop committed Feb 14, 2019
1 parent 93559be commit 1f2a171
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 18 deletions.
18 changes: 7 additions & 11 deletions assert-chicken.scm
Original file line number Diff line number Diff line change
@@ -1,23 +1,19 @@
;;;
;;; Unit test framework for Scheme R5RS, Chicken extension.
;;; Unit test framework for Scheme R5RS, SRFI-12 extension (e.g. Chicken)
;;; Copyright (c) 2015, Peter Kofler, http://www.code-cop.org/
;;; BSD licensed.
;;;
(include "assert-r5rs.scm")

(define (-error->string ex)
(cond ((symbol? ex) (symbol->string ex))
((string? ex) ex)
;; Chicken specific code
;; TODO Chicken Scheme exception types
;; ((type-exception? ex) (string-append "expected " (-error->string (type-exception-type-id ex)))) ; type name
;; ((exn ex) "xxx")
;; see https://wiki.call-cc.org/man/4/Exceptions#exception-handlers
(else (pp ex)
"<unknown exception type>")))
(cond ((symbol? ex) (symbol->string ex))
((string? ex) ex)
;; SRFI-12/Chicken specific code
((condition? ex) (-error->string ((condition-property-accessor 'exn 'message) ex)))
(else "<unknown exception type>")))

(define (-run-with-exception-handler handler body)
;; Chicken specific code
;; SRFI-12 specific code
(let ((exn-message-comparison '()))
(handle-exceptions exn
(set! exn-message-comparison (handler exn))
Expand Down
14 changes: 7 additions & 7 deletions assert-test-chicken.scm
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
(assert-inexact= 1. 1.1 0.11))

(test-failure "(assert-inexact=) fails"
"in range expected:<[.99-1.01]> but was:<1.1>"
"in range expected:<[0.99-1.01]> but was:<1.1>"
(assert-inexact= 1. 1.1 0.01))

(test-case "(assert-list=)"
Expand Down Expand Up @@ -124,12 +124,12 @@
(assert-not-null '()))

(test-case "(assert-raise) on raise symbol"
(assert-raise 'a (lambda ()
(assert-raise "unbound variable" (lambda ()
(raise 'a))))

(test-case "(assert-raise) on raise string"
(assert-raise "a" (lambda ()
(raise 'a))))
(assert-raise "unbound variable" (lambda ()
(raise "a"))))

(test-case "(assert-raise) on error symbol"
(assert-raise 'a (lambda ()
Expand All @@ -140,7 +140,7 @@
(error "a"))))

(test-failure "(assert-raise) fails"
"raise expected:<a> but was:<b>"
"raise expected:<a> but was:<unbound variable>"
(assert-raise 'a (lambda ()
(raise 'b))))

Expand All @@ -150,11 +150,11 @@
(+ 1 1))))

(test-case "(assert-raise) on unbound global variable"
(assert-raise 'unbound-global-variable (lambda ()
(assert-raise "unbound variable" (lambda ()
(unbound-global-variable))))

(test-case "(assert-raise) on type error"
(assert-raise "expected number" (lambda ()
(assert-raise "bad argument type" (lambda ()
(+ 1 "1"))))

(test-case "(assert-all) allows several assertions"
Expand Down

0 comments on commit 1f2a171

Please sign in to comment.