Skip to content

Commit

Permalink
Use displayException instead of show for showing exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
adamgundry committed Apr 28, 2022
1 parent 16289a7 commit 4c87d84
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 6 deletions.
2 changes: 1 addition & 1 deletion core/Test/Tasty/Core.hs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ resultSuccessful r =
exceptionResult :: SomeException -> Result
exceptionResult e = Result
{ resultOutcome = Failure $ TestThrewException e
, resultDescription = "Exception: " ++ show e
, resultDescription = "Exception: " ++ displayException e
, resultShortDescription = "FAIL"
, resultTime = 0
, resultDetailsPrinter = noResultDetails
Expand Down
3 changes: 2 additions & 1 deletion hunit/Test/Tasty/HUnit/Orig.hs
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,8 @@ instance (AssertionPredicable t) => AssertionPredicable (IO t)
-- | Exception thrown by 'assertFailure' etc.
data HUnitFailure = HUnitFailure (Maybe SrcLoc) String
deriving (Eq, Show, Typeable)
instance E.Exception HUnitFailure
instance E.Exception HUnitFailure where
displayException (HUnitFailure mbloc s) = prependLocation mbloc s

prependLocation :: Maybe SrcLoc -> String -> String
prependLocation mbloc s =
Expand Down
6 changes: 2 additions & 4 deletions hunit/Test/Tasty/HUnit/Steps.hs
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,8 @@ instance IsTest TestCaseSteps where
tme <- getTime
atomicModifyIORef ref (\l -> ((tme,msg):l, ()))

hunitResult <- (Right <$> assertionFn stepFn) `catches`
[ Handler (\(HUnitFailure mbloc errMsg) -> return $ Left (prependLocation mbloc errMsg))
, Handler (\(SomeException ex) -> return $ Left (show ex))
]
hunitResult <- (Right <$> assertionFn stepFn) `catch`
\(SomeException ex) -> return $ Left (displayException ex)

endTime <- getTime

Expand Down

0 comments on commit 4c87d84

Please sign in to comment.