Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add missing HasCallStack to writeGoldenFile, reportGoldenFileMissing, checkAgainstGoldenFile #70

Merged
merged 1 commit into from
May 16, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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."
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The path is logged already by H.readFile above.

, "To recreate golden file, run with RECREATE_GOLDEN_FILES=1."
]
failMessage callStack $ ppDiff difference
Expand Down
Loading