Created
January 10, 2017 15:57
-
-
Save mwotton/775c01670e3844ba0ac596f0ae689d22 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| module Main where | |
| import Control.Exception (AsyncException (..), | |
| SomeAsyncException (..)) | |
| import GHC.Stack (currentCallStack) | |
| import qualified Rerun | |
| import qualified Spec | |
| import Test.Hspec.Core.Spec | |
| import Test.Hspec.Runner | |
| import Test.Import | |
| main :: IO () | |
| main = Rerun.main $ hspecWith defaultConfig (mapSpecItem_ overflowExplainer Spec.spec) | |
| overflowExplainer :: Item a -> Item a | |
| overflowExplainer item = | |
| item { itemExample = \params func -> (itemExample item) params (overflowCatcher . func)} | |
| newtype VerboseOverflowException | |
| = VerboseOverflowException [String] | |
| deriving (Eq) | |
| instance Exception VerboseOverflowException | |
| instance Show VerboseOverflowException where | |
| show (VerboseOverflowException cb) = "\n\n" ++ unlines cb | |
| overflowCatcher :: IO a -> IO a | |
| overflowCatcher f = | |
| catchJust (\e -> guard (e ==StackOverflow)) | |
| f | |
| (\_ -> throwM . SomeAsyncException . VerboseOverflowException . drop 1 . dropWhile (not . (isInfixOf ".overflowCatcher")) =<< currentCallStack) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment