mardi 19 juin 2018

How can I test a program reading from stdin in GHCi?

My program has a bug I want to see within GHCi:

$ ./my-program < ./my-data
Prelude.foldl1: empty list

I tried changing stdin or getLine in GHCi but it doesn't seem to affect the getLine my program uses, even if I load afterwards:

$ ghci
Prelude> import System.IO
Prelude System.IO> getLine <- fmap hGetLine $ openFile "my-data" ReadMode
:l "my-program.hs"
:main

Do I need to rewrite all my IOs to take an explicit handle to be able to test them in GHCi?

Aucun commentaire:

Enregistrer un commentaire