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 Jul 27, 2024
1 parent 34dc340 commit 4998ba6
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 9 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -92,4 +92,4 @@ jobs:
- name: Check for trailing whitespace
run: '! git grep -I "\s\+$"'
- run: curl -sSL https://raw.githubusercontent.com/sol/hpack/main/get-hpack.sh | bash
- run: hpack && git diff --exit-code
- run: hpack && git diff --color --exit-code
2 changes: 1 addition & 1 deletion .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
steps:
- uses: actions/checkout@v3

- run: cabal check
- run: cabal check --ignore=missing-upper-bounds

- uses: sol/haskell-autotag@v1
id: autotag
Expand Down
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: 3 additions & 3 deletions hspec-hedgehog.cabal

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
spec-version: 0.36.0

name: hspec-hedgehog
version: 0.1.1.0
version: 0.2.0.0
synopsis: Integrate Hedgehog and Hspec!
description: Please see the README on GitHub at <https://github.com/hspec/hspec-hedgehog#readme>
category: Testing
Expand All @@ -19,7 +19,7 @@ dependencies:
- base >= 4.7 && < 5
- hspec >= 2.11.0 && < 3
- hspec-core >= 2.11.0 && < 3
- hedgehog >= 1.0.2 && < 2
- hedgehog >= 1.5

library:
source-dirs: src
Expand Down
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 4998ba6

Please sign in to comment.