Generalize assertion function types for return types and monad
osa1 opened this issue · comments
Literally every single test suite I work on needs these two:
-
Assertion functions that work in any
MonadIO
. With this I can use same assertion functions in different test monads, e.g. the monad inhspec-webdriver
. -
Assertion functions with generalized return value. Something like
type Assertion' a = IO a
assertFailure :: HasCallStack => String -> Assertion' a
Now I can use this in cases like
x <- case doX of
T1 -> assertFailure "doX returned T1!"
T2 x -> return x
Since these additions are so small I usually end up copying same code snippets to every single project I work on. I think these would be great additions to HUnit and other people would also benefit it.
For assertions/expectations generalized to MonadIO
you can use hspec-expectations-lifted
.
It's not suitable as a default because it hurts type inference in Hspec.
I'm ok with changing the type of assertFailure
:
assertFailure :: HasCallStack => String -> IO a
Nice, I didn't know about hspec-expectations-lifted
, thanks.
You originally wrote "PR please" but do you still want a PR or are you going to do this yourself?
Yes, PR please.