Thanks for your responses.<br>Of course I already test every pure parts of my program easily.<br><br>For now, user input is treated in 2 different ways:<br>- direct IO with hgetLine and like functions (blocking)<br>- the same but I directly push the strings on a TChan for another thread to treat them (not blocking).<br>
<br>The second is easy to test, since all I have to do is to insert test strings on the TChan to simulate user&#39;s input.<br>Maybe I can do everything this way.<br><br>But for example I had a bug of two threads inter-blocked on the handle.<br>
These tests were not able to show it, since the test takes place not on the handle itself but a little after.<br>Maybe &quot;mock handle&quot; can help.<br><br>Corentin<br><br><br><div class="gmail_quote">On Tue, Oct 26, 2010 at 11:32 PM, Antoine Latter <span dir="ltr">&lt;<a href="mailto:aslatter@gmail.com">aslatter@gmail.com</a>&gt;</span> wrote:<br>
<blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">On Tue, Oct 26, 2010 at 11:11 AM, Dupont Corentin<br>
<div class="im">&lt;<a href="mailto:corentin.dupont@gmail.com">corentin.dupont@gmail.com</a>&gt; wrote:<br>
</div><div class="im">&gt; Hello again café,<br>
&gt;<br>
&gt; I have a command line program that takes input from various handles<br>
&gt; (actually network sockets) like this:<br>
&gt;<br>
&gt;&gt; s &lt;- hGetLine h<br>
&gt;&gt; etc.<br>
&gt;<br>
&gt; I&#39;d like to unit test this. How can I do?<br>
&gt; I&#39;d like to inject data on the handle so that all the input chain is tested.<br>
<br>
</div>I haven&#39;t tested it yet, but this &quot;mock handle&quot; will eventually work in GHC 7:<br>
<br>
<a href="http://hackage.haskell.org/trac/ghc/attachment/ticket/4144/ByteStringHandle.hs" target="_blank">http://hackage.haskell.org/trac/ghc/attachment/ticket/4144/ByteStringHandle.hs</a><br>
<br>
At least, the bug report about how it didn&#39;t work has now been closed :-)<br>
<br>
I don&#39;t remember which operations worked and which didn&#39;t - getChar<br>
would work, but getContents would fail.<br>
<br>
The others have great advice, that you should try to isolate the logic<br>
of your code from IO for precisely this reason - so it is easily<br>
testable.<br>
<font color="#888888"><br>
Antoine<br>
</font></blockquote></div><br>