test: freeze the callstack for better failure messages (#1)

This would make the function `shouldLexTo` be transparent in the error reporting! Before all errors would point to this line.

Reviewed-on: elland/haddock2#1
Co-authored-by: Léana 江 <leana.jiang+git@icloud.com>
Co-committed-by: Léana 江 <leana.jiang+git@icloud.com>
This commit is contained in:
Primrose 2025-09-24 11:01:52 +00:00 committed by elland
parent 00a6e11f67
commit 39cfe2035d

View file

@ -11,6 +11,7 @@ import Types
import Data.String (IsString (..)) import Data.String (IsString (..))
import Data.Text (Text) import Data.Text (Text)
import Text.Parsec.Pos import Text.Parsec.Pos
import GHC.Stack
main :: IO () main :: IO ()
main = hspec $ do main = hspec $ do
@ -185,6 +186,7 @@ instance IsString (Doc String) where
shouldLexTo :: String -> [(Int, Int, Token)] -> Expectation shouldLexTo :: String -> [(Int, Int, Token)] -> Expectation
shouldLexTo input expected = shouldLexTo input expected =
withFrozenCallStack $
case lexer input of case lexer input of
Right tokens -> do Right tokens -> do
let actual = map (\(pos, tok) -> (sourceLine pos, sourceColumn pos, tok)) tokens let actual = map (\(pos, tok) -> (sourceLine pos, sourceColumn pos, tok)) tokens