[Haskell-cafe] Replacing IO with pure values

Jeffrey Brown jeffbrown.the at gmail.com
Wed Nov 26 19:59:21 UTC 2014

It seems like it ought to be possible to manually test some IO once, record
the user input, and automate future testing by using that record. Is it

On Tue, Nov 25, 2014 at 5:55 AM, Julian Arni <jkarni at gmail.com> wrote:

> Besides, the aforementioned IOSpec, I would also suggest taking a look at
> "Purify Code Using Free Monads" [0], which gives a nice introduction to a
> general approach. If you're faced with library functions (i.e., ones you
> haven't written yourself) that do IO, it can become a little onerous to
> mock them all, though. In case the IO you're interested in testing is
> mostly stdin/stderr/stdout related, you could also look at the 'silently'
> package [1]. Finally, the 'knob' package [2] allows you to use in-memory
> file handles, so it helps if your tack ends up being passing Handles to
> pure functions (so that in the executable, those handles are
> stdin/stderr/stdout + files etc, but in the test they're just in-memory
> handles provided by 'knob'). 'System.Environment' has 'withArgs', which
> provides for the case of testing command-line args.
> [0]
> http://www.haskellforall.com/2012/07/purify-code-using-free-monads.html
> [1] https://hackage.haskell.org/package/silently-
> [2] http://hackage.haskell.org/package/knob-0.1.1/docs/Data-Knob.html
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20141126/5f1e8706/attachment.html>

More information about the Haskell-Cafe mailing list