Can anyone give me a brief example of testing IO actions using Monadic QuickCheck?
Can anyone give me a brief example of testing IO actions using Monadic QuickCheck?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The Test.QuickCheck.Monadic module lets you test monadic code, even things that run in
IO.A monadic property test is of type
PropertyM m a, wheremis the monad the test runs in andais ultimately ignored. In the case ofPropertyM IO a, you convert the monadic test to aPropertyby usingmonadicIO; for all other monads, you usemonadicinstead (which takes a function to run the monad, somethingIOdoesn’t have).In a monadic test, the value
returned out of the monad is ignored. To check an expression, useassert;asserting a false value will fail the test. Userunto execute the code in the monad being tested.There are other monadic actions at your disposal. For example,
pickwill generate new test inputs out of aGen a, andprewill check test preconditions. These are useful if the test inputs or preconditions themselves depend on values computed via the monad being tested, in which case the normal way of generating inputs or checking precontions won’t work.Here’s an example of testing some
IOcode: we check that after writing something to a temporary file, we can read that same data back. For demonstration purposes, we’ll impose the precondition that we write at least one byte to the file. The two test properties do the same thing; one usespickandpreunnecessarily while the other does not.