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

Include location of failed assertion in report #308

Merged
merged 2 commits into from
Jun 21, 2019
Merged
Changes from 1 commit
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
18 changes: 14 additions & 4 deletions hedgehog/src/Hedgehog/Internal/Report.hs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ import System.Directory (makeRelativeToCurrentDirectory)
import System.IO (hSetEncoding, stdout, stderr, utf8)
#endif

import Text.PrettyPrint.Annotated.WL (Doc, (<+>))
import Text.PrettyPrint.Annotated.WL (Doc, (<#>), (<+>))
import qualified Text.PrettyPrint.Annotated.WL as WL
import Text.Printf (printf)

Expand Down Expand Up @@ -714,7 +714,8 @@ ppProgress name (Report tests discards coverage status) =
Shrinking failure ->
pure . icon ShrinkingIcon '↯' . WL.annotate ShrinkingHeader $
ppName name <+>
"failed after" <+>
"failed" <+> ppFailedAtLocation (failureLocation failure) <#>
"after" <+>
ppTestCount tests <>
ppShrinkDiscard (failureShrinks failure) discards <+>
"(shrinking)"
Expand All @@ -725,9 +726,10 @@ ppResult name (Report tests discards coverage result) = do
Failed failure -> do
pfailure <- ppFailureReport name tests failure
pure . WL.vsep $ [
icon FailedIcon '✗' . WL.annotate FailedText $
icon FailedIcon '✗' . WL.align . WL.annotate FailedText $
ppName name <+>
"failed after" <+>
"failed" <+> ppFailedAtLocation (failureLocation failure) <#>
"after" <+>
ppTestCount tests <>
ppShrinkDiscard (failureShrinks failure) discards <>
"."
Expand Down Expand Up @@ -757,6 +759,14 @@ ppResult name (Report tests discards coverage result) = do
] ++
ppCoverage tests coverage

ppFailedAtLocation :: Maybe Span -> Doc Markup
ppFailedAtLocation (Just span') =
"at" <+>
WL.text (spanFile span') <> ":" <>
WL.pretty (unLineNo (spanStartLine span')) <> ":" <>
WL.pretty (unColumnNo (spanStartColumn span'))
ppFailedAtLocation Nothing = mempty
owickstrom marked this conversation as resolved.
Show resolved Hide resolved

ppCoverage :: TestCount -> Coverage CoverCount -> [Doc Markup]
ppCoverage tests x =
if Map.null (coverageLabels x) then
Expand Down