sol / doctest

An implementation of Python's doctest for Haskell
https://hackage.haskell.org/package/doctest
MIT License
373 stars 73 forks source link

more comfortable testing of non-ascii output ? #457

Closed simonmichael closed 1 month ago

simonmichael commented 1 month ago

Thanks for doctest!

I have a test whose output appears like this in GHCI:

ghci> currencyCodeToSymbol $ T.pack "CZK"
Just "Kč"

But in the doctest comment I must write it like this:

-- >>> currencyCodeToSymbol "CZK"
-- Just "K\269"

or it would fail:

expected: Just "Kč"
 but got: Just "K\269"
                 ^

Why is this happening, and would it be possible to support this instead ?

-- >>> currencyCodeToSymbol "CZK"
-- Just "Kč"
sol commented 1 month ago
$ ghci -ignore-dot-ghci
GHCi, version 9.10.1: https://www.haskell.org/ghc/  :? for help
ghci> Just "Kč"
Just "K\269"
  1. The Show instance of String shows č as \269.
  2. ghci uses show by default.
  3. Are you passing -interactive-print to ghci? If yes, you can try to pass the same option to doctest.
simonmichael commented 1 month ago

Aha, you're right; I have a .ghci containing

:set -interactive-print=Text.Pretty.Simple.pPrintNoColor

I think keeping my doctests aligned with the default GHCI behaviour is best, even if they're a little less pretty/readable. Thank you for the insight.