[Haskell-cafe] Test command line programs
corentin.dupont at gmail.com
Thu Oct 28 09:28:47 EDT 2010
Thanks for your responses.
Of course I already test every pure parts of my program easily.
For now, user input is treated in 2 different ways:
- direct IO with hgetLine and like functions (blocking)
- the same but I directly push the strings on a TChan for another thread to
treat them (not blocking).
The second is easy to test, since all I have to do is to insert test strings
on the TChan to simulate user's input.
Maybe I can do everything this way.
But for example I had a bug of two threads inter-blocked on the handle.
These tests were not able to show it, since the test takes place not on the
handle itself but a little after.
Maybe "mock handle" can help.
On Tue, Oct 26, 2010 at 11:32 PM, Antoine Latter <aslatter at gmail.com> wrote:
> On Tue, Oct 26, 2010 at 11:11 AM, Dupont Corentin
> <corentin.dupont at gmail.com> wrote:
> > Hello again café,
> > I have a command line program that takes input from various handles
> > (actually network sockets) like this:
> >> s <- hGetLine h
> >> etc.
> > I'd like to unit test this. How can I do?
> > I'd like to inject data on the handle so that all the input chain is
> I haven't tested it yet, but this "mock handle" will eventually work in GHC
> At least, the bug report about how it didn't work has now been closed :-)
> I don't remember which operations worked and which didn't - getChar
> would work, but getContents would fail.
> The others have great advice, that you should try to isolate the logic
> of your code from IO for precisely this reason - so it is easily
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Haskell-Cafe