<div dir="ltr">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 not? <br></div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Nov 25, 2014 at 5:55 AM, Julian Arni <span dir="ltr"><<a href="mailto:jkarni@gmail.com" target="_blank">jkarni@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">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. <br><br>[0] <a href="http://www.haskellforall.com/2012/07/purify-code-using-free-monads.html" target="_blank">http://www.haskellforall.com/2012/07/purify-code-using-free-monads.html</a><br>[1] <a href="https://hackage.haskell.org/package/silently-1.2.4.1" target="_blank">https://hackage.haskell.org/package/silently-1.2.4.1</a><br>[2] <a href="http://hackage.haskell.org/package/knob-0.1.1/docs/Data-Knob.html" target="_blank">http://hackage.haskell.org/package/knob-0.1.1/docs/Data-Knob.html</a><br></div>
<br>_______________________________________________<br>
Haskell-Cafe mailing list<br>
<a href="mailto:Haskell-Cafe@haskell.org">Haskell-Cafe@haskell.org</a><br>
<a href="http://www.haskell.org/mailman/listinfo/haskell-cafe" target="_blank">http://www.haskell.org/mailman/listinfo/haskell-cafe</a><br>
<br></blockquote></div><br></div>