Skip to content

Commit

Permalink
Get arguments of error conditions for Chicken.
Browse files Browse the repository at this point in the history
  • Loading branch information
codecop committed Feb 14, 2019
1 parent 4a026af commit 9c8087b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 14 deletions.
12 changes: 8 additions & 4 deletions assert-chicken.scm
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,15 @@
(include "assert-r5rs.scm")

(define (-error->string ex)
(cond ((symbol? ex) (symbol->string ex))
((string? ex) ex)
(cond ((null? ex) "")
((string? ex) ex)
((symbol? ex) (symbol->string ex))
((list? ex) (string-append " (" (apply string-append (map -error->string ex)) ")"))
;; SRFI-12/Chicken specific code
((condition? ex) (-error->string ((condition-property-accessor 'exn 'message) ex)))
(else "<unknown exception type>")))
((condition? ex) (string-append (-error->string ((condition-property-accessor 'exn 'message) ex))
(-error->string ((condition-property-accessor 'exn 'arguments) ex))))
(else (pp ex)
"<unknown exception type>")))

(define (-run-with-exception-handler handler body)
;; SRFI-12 specific code
Expand Down
20 changes: 10 additions & 10 deletions assert-test-chicken.scm
Original file line number Diff line number Diff line change
Expand Up @@ -123,13 +123,13 @@
"expected:<not null> but was:<null>"
(assert-not-null '()))

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

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

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

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

(test-failure "(assert-raise) fails when no raise"
"raise expected:<a> but was:<no raise in body>"
(assert-raise 'a (lambda ()
(+ 1 1))))

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

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

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

0 comments on commit 9c8087b

Please sign in to comment.