In Rackunit, I know how to assert that an exception is thrown:
#lang racket
(module+ test
(require rackunit)
(check-exn exn:fail:contract? (lambda () (3 + 4))))
However, I cannot find a way to assert something more specific. Looking at the exception hierarchy in Racket, exn:fail:contract could mean a number of things: a wrong arity, a division by zero ...
I would like to assert in the test that this particular exception is one that reads:
; application: not a procedure;
; expected a procedure that can be applied to arguments
in its printed message. How do you accomplish this?
The predicate doesn't have to be a built-in exception predicate. You can use your own, like this:
Rackunit's
check-exnalso accepts a regexp in place of an exception predicate. In that case, it checks for anexn:fail(or any of its subtypes) whose message matches the regexp. So you could also write this: