Skip to content

Commit

Permalink
Add missing HasCallStack to writeGoldenFile, reportGoldenFileMissin…
Browse files Browse the repository at this point in the history
…g, checkAgainstGoldenFile
  • Loading branch information
carbolymer authored and newhoggy committed May 16, 2024
1 parent 4614d65 commit 93b7480
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/Hedgehog/Extras/Test/Golden.hs
Original file line number Diff line number Diff line change
Expand Up @@ -58,22 +58,24 @@ recreateGoldenFiles = IO.unsafePerformIO $ do
return $ value == Just "1"

writeGoldenFile :: ()
=> HasCallStack
=> MonadIO m
=> MonadTest m
=> FilePath
-> String
-> m ()
writeGoldenFile goldenFile actualContent = do
writeGoldenFile goldenFile actualContent = GHC.withFrozenCallStack $ do
H.note_ $ "Creating golden file " <> goldenFile
H.createDirectoryIfMissing_ (takeDirectory goldenFile)
H.writeFile goldenFile actualContent

reportGoldenFileMissing :: ()
=> HasCallStack
=> MonadIO m
=> MonadTest m
=> FilePath
-> m ()
reportGoldenFileMissing goldenFile = do
reportGoldenFileMissing goldenFile = GHC.withFrozenCallStack $ do
H.note_ $ unlines
[ "Golden file " <> goldenFile <> " does not exist."
, "To create it, run with CREATE_GOLDEN_FILES=1."
Expand All @@ -82,20 +84,21 @@ reportGoldenFileMissing goldenFile = do
H.failure

checkAgainstGoldenFile :: ()
=> HasCallStack
=> MonadIO m
=> MonadTest m
=> FilePath
-> [String]
-> m ()
checkAgainstGoldenFile goldenFile actualLines = do
checkAgainstGoldenFile goldenFile actualLines = GHC.withFrozenCallStack $ do
referenceLines <- List.lines <$> H.readFile goldenFile
let difference = getGroupedDiff actualLines referenceLines
case difference of
[] -> pure ()
[Both{}] -> pure ()
_ -> do
H.note_ $ unlines
[ "Golden test failed against golden file: " <> goldenFile
[ "Golden test failed against the golden file."
, "To recreate golden file, run with RECREATE_GOLDEN_FILES=1."
]
failMessage callStack $ ppDiff difference
Expand Down

0 comments on commit 93b7480

Please sign in to comment.