cleveland-0.3.2: Testing framework for Morley.
Safe HaskellSafe-Inferred
LanguageHaskell2010

Test.Cleveland.Tasty.Internal.Report

Description

Pretty-printers for reports in Tasty logs.

Synopsis

Documentation

data Line Source #

Constructors

Line 

Fields

formatError Source #

Arguments

:: 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

numbered :: [Text] -> [Line] Source #

Attach line numbers to each line of source code.

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

headerF :: Int -> FilePath -> Doc Source #

srcLineF :: Int -> Line -> 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.