Skip to content
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 instead of show for showing exceptions #330

Merged
merged 2 commits into from
Jul 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 5 additions & 4 deletions core/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@ Unreleased

_YYYY-MM-DD_

* Dependency loop error now lists all test cases that formed a cycle
* `foldGroup` now takes `[b]` instead of `b` as its last argument to allow for custom fold strategies. This is a backwards incompatible change, but you can get the old behavior by applying `mconcat`.
* Dependencies can now be defined pattern-free with `sequentialTestGroup`. (#343)
* Added `--min-duration-to-report` flag that specifies the time a test must take before `tasty` outputs timing information ([#341](https://github.com/UnkindPartition/tasty/issues/341))
* Dependency loop error now lists all test cases that formed a cycle ([#340](https://github.com/UnkindPartition/tasty/issues/340)).
* `foldGroup` now takes `[b]` instead of `b` as its last argument to allow for custom fold strategies. This is a backwards incompatible change, but you can get the old behavior by applying `mconcat` ([#364](https://github.com/UnkindPartition/tasty/issues/364)).
* Dependencies can now be defined pattern-free with `sequentialTestGroup` ([#343](https://github.com/UnkindPartition/tasty/issues/343)).
* Added `--min-duration-to-report` flag that specifies the time a test must take before `tasty` outputs timing information ([#341](https://github.com/UnkindPartition/tasty/issues/341)).
* When a test failed with an exception, print it using `displayException` instead of `show` ([#330](https://github.com/UnkindPartition/tasty/issues/330)).

Version 1.4.3
---------------
Expand Down
2 changes: 1 addition & 1 deletion core/Test/Tasty/Core.hs
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,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
5 changes: 5 additions & 0 deletions hunit/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
Changes
=======

Unreleased
---------------

Provide an explicit implementation of `displayException` in `instance Exception HUnitFailure` ([#330](https://github.com/UnkindPartition/tasty/issues/330)).

Version 0.10.0.3
----------------

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