Skip to content

Commit

Permalink
Show less context on failure (fixes #26)
Browse files Browse the repository at this point in the history
  • Loading branch information
sol committed May 11, 2024
1 parent 8ec73d7 commit 52b3d99
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
4 changes: 4 additions & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog for hspec-hedgehog

## 0.2.0.0
- [#29](https://github.com/parsonsmatt/hspec-hedgehog/pull/29) @sol
- Show less context on failure.

## 0.1.1.0
- [#30](https://github.com/parsonsmatt/hspec-hedgehog/pull/30) @sol
- Show classification on success
Expand Down
6 changes: 6 additions & 0 deletions cabal.project
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,9 @@ package hspec-hedgehog
ghc-options: -Werror

tests: True

source-repository-package
type: git
location: https://github.com/hedgehogqa/haskell-hedgehog
tag: fd182bf670abe554a7bebd34a0cac42e7bb07846
subdir: hedgehog
19 changes: 17 additions & 2 deletions src/Test/Hspec/Hedgehog.hs
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ module Test.Hspec.Hedgehog
) where

import Control.Monad.IO.Class (liftIO)
import Data.Char (isSpace)
import Data.Coerce (coerce)
import Data.IORef (newIORef, readIORef, writeIORef)
import GHC.Stack (withFrozenCallStack)
Expand All @@ -105,7 +106,6 @@ import Hedgehog.Internal.Property (DiscardLimit (..), Property (..),
TerminationCriteria (..),
TestCount (..), TestLimit (..))
import Hedgehog.Internal.Report hiding (renderResult)
import qualified Hedgehog.Internal.Report as Hedge
import Hedgehog.Internal.Runner (checkReport)
import qualified Hedgehog.Internal.Seed as Seed
import Hedgehog.Internal.Source (ColumnNo (..), LineNo (..),
Expand Down Expand Up @@ -203,7 +203,14 @@ instance (m ~ IO) => Example (a -> PropertyT m ()) where
Just (rng, _) -> pure (uncurry Seed (unseedSMGen (coerce rng)))
hedgeResult <- checkReport propConfig size seed (propertyTest prop) cb

let renderResult color = Hedge.renderResult color (Just "property") hedgeResult
let
config = defaultConfig {
configContext = Context 0
, configPrintFailedAtLocation = False
, configPrintReproduceMessage = False
, configPrintPrefixIcons = DisablePrefixIcons
}
renderResult color = unlines . unindent . lines . dropWhileEnd isSpace <$> renderResultWith config color (Just "") hedgeResult

case reportStatus hedgeResult of
Failed FailureReport{..} -> do
Expand All @@ -223,3 +230,11 @@ instance (m ~ IO) => Example (a -> PropertyT m ()) where
ppresult <- renderResult DisableColor
writeIORef ref $ Result ppresult Success
readIORef ref

dropWhileEnd :: (a -> Bool) -> [a] -> [a]
dropWhileEnd p = reverse . dropWhile p . reverse

unindent :: [String] -> [String]
unindent xs = map (drop indentation) xs
where
indentation = minimum $ map (length . takeWhile (== ' ')) xs

0 comments on commit 52b3d99

Please sign in to comment.