rackunit
rackunit copied to clipboard
check-exn should not fail on opaque value
> (require typed/rackunit)
> (struct opaque ())
> (check-exn (lambda (e) (println e) #t) (lambda () (opaque)))
(exn:fail:contract:blame "check-exn-imp: contract violation\n any-wrap/c: Unable to protect opaque value passed as `Any`\n value: #<opaque>\n in: the range of\n the 2nd argument of\n the range of\n (->\n #:expression\n Any\n #:location\n Any\n (->*\n ((or/c\n pregexp?\n (and/c regexp? (not/c pregexp?))\n (or/c\n struct-predicate-procedure?\n struct-type-property-predicate-procedure?\n (-> any/c any)))\n (-> Any))\n (any/c)\n void?))\n contract from: (interface for check-exn-imp)\n blaming: <pkgs>/rackunit-typed/rackunit/main.rkt\n (assuming the contract is correct)\n at: <pkgs>/rackunit-typed/rackunit/main.rkt" #<continuation-mark-set> #<blame-no-swap>)
This should not occur. Since check-exn doesn't care about the result, one possible fix is to wrap the thunk so that it always return a non-opaque value. E.g.:
> (check-exn (lambda (e) (println e) #t) (lambda () (opaque) #t))
--------------------
FAILURE [,bt for context]
name: check-exn
location: string:1:0
params: '(#<procedure> #<procedure>)
message: "No exception raised"
--------------------
works as expected.
We should just change typed/rackunit to use unsafe-require/typed in a bunch of places.