-
Notifications
You must be signed in to change notification settings - Fork 1
Description
I wrote this in a test:
assert {allEven [1, 2, 3]} shouldRaise "TypeError" mentioning "does not have type List”
and got the following failure message:
wrong type: code raised exception TypeError: "argument to request of `allEven(_)`
does not have type List. ..." instead of TypeError
This confused me: why was a TypeError not being recognized as a TypeError? It took me quite a long time to notice that I had written “TypeError” rather than TypeError, i.e, I had used a string rather than an ExceptionKind.
So, I though: I can stop that from happening again. All I need do is to annotate the assert (_) shouldRaise(_)... method in gUnit with the type ExceptionKind. I did this, and the test now failed, complaining that the wrong type of argument was provided to assert(_)shouldRaise(_)
Unfortunately, a few other tests also failed. For example:
testDictionaryRemove5: TypeError: argument 2 in request of
`assert(_)shouldRaise(_)mentioning(_)and(_)` does not have type ExceptionKind.
It is an OrPattern.new(_,_) (defined in module standardGrace, line 88), which is missing
methods parent, raise(_), raise(_)with(_), and refine(_).
The test in question is written like this:
assert {evens.removeKey 5} shouldRaise (NoSuchObject | TypeError)
// TypeError if the type parameters are checked, NoSuchObejct otherwise
Nothing wrong with that test. Obviously, this was my mistake; I need to annotate the shouldRaise parameter with Pattern, not ExceptionKind.
Unfortunately, that doesn’t help, because a string is a Pattern, and my original error is no longer caught. Indeed, all the primitive objects are patterns. I can't think of a type annotation that would catch this error.
Is this a design issue with Patterns?