Skip to content

Commit

Permalink
add unwrapAnnotatedHUnitFailure (#194)
Browse files Browse the repository at this point in the history
  • Loading branch information
chris-martin authored Sep 19, 2024
1 parent 1234576 commit dc0d3f5
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 5 deletions.
11 changes: 8 additions & 3 deletions freckle-app/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
## [_Unreleased_](https://github.com/freckle/freckle-app/compare/freckle-app-v1.20.0.2...main)
## [_Unreleased_](https://github.com/freckle/freckle-app/compare/freckle-app-v1.20.1.0...main)

## [v1.20.0.2](https://github.com/freckle/freckle-app/compare/freckle-app-v1.20.0.1...freckle-app-v1.20.0.2)
## [v1.20.1.0](https://github.com/freckle/freckle-app/compare/freckle-app-v1.20.0.1...freckle-app-v1.20.1.0)

Modules moving between packages:

- `Freckle.App.Prelude` has moved to the `freckle-prelude` package
- `Freckle.App.Exception(.*)` has moved to the `freckle-exception` package
- All moved modules are re-exported from `freckle-app`.

All moved modules are re-exported from `freckle-app`.
- Added `Freckle.App.Test.Hspec.AnnotatedException` (`unwrapAnnotatedHUnitFailure`).
It is recommended that all hspec test suites for packages that use `freckle-prelude`
add this spec hook.

## [v1.20.0.1](https://github.com/freckle/freckle-app/compare/freckle-app-v1.20.0.0...freckle-app-v1.20.0.1)

Expand Down
4 changes: 3 additions & 1 deletion freckle-app/freckle-app.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ cabal-version: 1.22
-- see: https://github.com/sol/hpack

name: freckle-app
version: 1.20.0.1
version: 1.20.1.0
synopsis: Haskell application toolkit used at Freckle
description: Please see README.md
category: Utils
Expand Down Expand Up @@ -46,6 +46,7 @@ library
Freckle.App.Stats.Rts
Freckle.App.Test
Freckle.App.Test.DocTest
Freckle.App.Test.Hspec.AnnotatedException
Freckle.App.Test.Hspec.Runner
Freckle.App.Test.Properties.JSON
Freckle.App.Test.Properties.PathPiece
Expand Down Expand Up @@ -97,6 +98,7 @@ library
Blammo
, Blammo-wai
, Glob
, HUnit
, MonadRandom
, QuickCheck
, aeson
Expand Down
22 changes: 22 additions & 0 deletions freckle-app/library/Freckle/App/Test/Hspec/AnnotatedException.hs
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)
3 changes: 2 additions & 1 deletion freckle-app/package.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: freckle-app
version: 1.20.0.1
version: 1.20.1.0
maintainer: Freckle Education
category: Utils
github: freckle/freckle-app
Expand Down Expand Up @@ -77,6 +77,7 @@ library:
- Blammo
- Blammo-wai
- Glob
- HUnit
- MonadRandom
- QuickCheck
- autodocodec
Expand Down

0 comments on commit dc0d3f5

Please sign in to comment.