how do i use quickcheck in the IO monad?

If i have functions in the IO monad, is there a way to use quickcheck to test them? I have a bunch of C bindings that unfortunately are not "safe". But i would like to be able to use QuickCheck to test them. Thanks, Anatoly

aeyakovenko:
If i have functions in the IO monad, is there a way to use quickcheck to test them? I have a bunch of C bindings that unfortunately are not "safe". But i would like to be able to use QuickCheck to test them.
Typically, via unsafePerformIO, and check the invariants that need to hold for that to be safe by hand. E.g. prop_foo x = unsafePerformIO $ do writeFile "f" x y <- readFile "f" return (x == y) -- Don

On Mon, 2008-09-22 at 12:35 -0700, Anatoly Yakovenko wrote:
If i have functions in the IO monad, is there a way to use quickcheck to test them? I have a bunch of C bindings that unfortunately are not "safe". But i would like to be able to use QuickCheck to test them.
Hi Anatoly, If you want to test some sequential properties then you might use QuickCheck to generate sequences of actions that the library will perform and check if the outcomes are correct. If there is no easy way to verify the results then you may create a model of your library and compare the results. This approach is demonstrated in this talk: http://ulf.wiger.net/weblog/2008/02/29/john-hughes-testing-with-quickcheck/ where John Hughes tests fread()/fwrite()/fseek() unix functions. He uses the Erlang version of QuickCheck, but using a Haskell one should allow you to do the same thing in the IO monad. There are probably some papers that deal with what you want to do as well, like this one: http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.19.9275 (I haven't read it though). Best, Michał

On Mon, Sep 22, 2008 at 9:35 PM, Anatoly Yakovenko
If i have functions in the IO monad, is there a way to use quickcheck to test them?
Maybe you can use Test.QuickCheck.Monadic in QuickCheck 2.1. I never used it so I can't explain how it works. However there are some examples that seem to use it. See: http://code.haskell.org/QuickCheck Bas
participants (4)
-
Anatoly Yakovenko
-
Bas van Dijk
-
Don Stewart
-
Michał Pałka