Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
Pretty-printers for reports in Tasty logs.
Synopsis
- data Line = Line {
- lineText :: Text
- lineNumber :: Int
- formatError :: Natural -> CallStack -> String -> IO Doc
- getLocation :: CallStack -> Maybe SrcLoc
- numbered :: [Text] -> [Line]
- linesAround :: Natural -> SrcLoc -> [Line] -> ([Line], NonEmpty Line, [Line])
- verticalBorder :: Doc
- headerF :: Int -> FilePath -> Doc
- srcLineF :: Int -> Line -> Doc
- errorMsgF :: Int -> SrcLoc -> NonEmpty Line -> String -> [Doc]
- caretColumns :: SrcLoc -> NonEmpty Line -> (Int, Int)
Documentation
:: Natural | The number of source code lines to print before and after the location of the error |
-> CallStack | The error's callstack |
-> String | The error message to display below the expression that caused the error |
-> IO Doc |
Pretty-prints an error by displaying:
- the source code where the error occurred
- the expression that threw the error
- an associated error message below said expression
- the error's callstack
linesAround :: Natural -> SrcLoc -> [Line] -> ([Line], NonEmpty Line, [Line]) Source #
Given a list of source code lines, returns:
- the
n
lines that preceed the location of the error - the line(s) where the error occurred
- the
n
lines that follow the location of the error
verticalBorder :: Doc Source #
caretColumns :: SrcLoc -> NonEmpty Line -> (Int, Int) Source #
Calculates the start and end columns for drawing carets (^).
If the expression that caused the error is in a single line,
then we can simply use the column numbers from SrcLoc
.
However, if the expression spans 2 or more lines, then it's a bit more complicated. For example, say we have this expression:
someFunc arg
Then SrcLoc
's start column will be 1 and end column will be 5.
However, we actually want the carets to be displayed from columns 1 to 9, like so:
someFunc arg ^^^^^^^^
See more examples in the TestSuite.Cleveland.Tasty.Report.Examples
module.