-
Notifications
You must be signed in to change notification settings - Fork 19
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use displayException for HUnitFailure #55
Comments
|
Yes. Here's an example: #!/usr/bin/env cabal
{- cabal:
build-depends: base, HUnit
-}
import Control.Exception
import Test.HUnit
-- User code defines an exception type, with a displayException implementation
-- that explains how it should be presented to users
data MyException = MyException String
deriving Show
instance Exception MyException where
displayException (MyException _) = "Some nice message"
-- HUnit test suite where one of the tests accidentally throws an error
main = runTestTT $ TestCase (throwIO (MyException "Some tedious internal details")) At the moment, this test suite fails with
whereas (I claim) it would be better to see "Some nice message" instead. The point here is that |
Is this motivated by practical need for it. Say, did you run into a situation where you would have preferred the internal details to be omitted. I would be very interested to learn in what kind of situation one would not want to know all the details that led to a test failure. |
The practical motivation arises from refactoring a commercial Haskell codebase, where we're trying to make test failure messages easier to diagnose. One aspect of this includes attaching backtraces to exceptions (using Note that |
@adamgundry ok, for exceptions that provide a lot of context, like failed HTTP requests, I see how that can be convenient in some situations. Now, what are the cons? Let’s assume, you write some code and you have a test case that fails with an exception. If you want to handle that exception in your code then you need to know the type of that exception. Your best bet is to rely on the So this is a trade-off where I’m not exactly sure where the sweet spot is. Hspec does not use As for ** This works with most third-party libraries, but not so much for exceptions from |
The
Exception HUnitFailure
instance does not currently implementdisplayException
. It would be nice if it did, and ifperformTestCase
calleddisplayException
rather thanshow
when rendering an exception.Related
tasty
issue: UnkindPartition/tasty#327The text was updated successfully, but these errors were encountered: