-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add unwrapAnnotatedHUnitFailure (#194)
- Loading branch information
1 parent
1234576
commit dc0d3f5
Showing
4 changed files
with
35 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
freckle-app/library/Freckle/App/Test/Hspec/AnnotatedException.hs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
module Freckle.App.Test.Hspec.AnnotatedException | ||
( unwrapAnnotatedHUnitFailure | ||
) where | ||
|
||
import Freckle.App.Prelude | ||
|
||
import Control.Exception qualified | ||
import Freckle.App.Exception (AnnotatedException (..)) | ||
import Test.HUnit.Lang (HUnitFailure) | ||
import Test.Hspec | ||
|
||
-- | An hspec hook that lets hspec catch and pretty-print 'HUnitFailure', the | ||
-- exception that is thrown when a test assertion fails | ||
-- | ||
-- Tests for any code that might throw 'AnnotatedException' (which includes anything | ||
-- that uses freckle-app) should add this hook to their test suite. Without it, if | ||
-- you end up with an @'AnnotatedException' 'HUnitFailure'@, hspec doesn't recognize | ||
-- it as an assertion failure and you get ugly output instead of nice output. | ||
unwrapAnnotatedHUnitFailure :: Spec -> Spec | ||
unwrapAnnotatedHUnitFailure = around_ $ | ||
Control.Exception.handle $ \AnnotatedException {exception = e} -> | ||
Control.Exception.throw (e :: HUnitFailure) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters