using quickcheck for blackbox testing for 3rd party apps.

Hi All, I am exploring use of quickCheck to define the test-specification for a 3rd party component. The component is basically an Command/Response type of application. Hence to validate it, I thought that the best way might be to take the following approach(based on the quickCheckM paper) a. describe the component in a purely functional way. The functions would take the "AppState", "Command" as parameters and would return a Response. Let me call this the "Abstract Application" The signature for this would therefore be of the form abstract_App :: AppState -> Command -> Response b. define an agent (Let me call it as Real_App) that that would (i) take a initial State, "Command" and send it to the "Application Under test" using some IPC mechanisms(probably socket or FIFO files) (ii) parse the received response and send it back as "Response". As a result the the API for the agent would be of the form real_APP :: AppState -> Command -> IO Response c. write a quick-check specification that would send a bunch of commands to the "Abstract Application" and check for equivalence with the value returned by the "real_App" However, being a newbie, I am not able to understand how I can extract the "Response" part from the IO Response. I want something as follows prop_App state_x command_y = (abstract_App state_x command_y ) == (real_App state_x command_y) The issue here is that since the reall_App would return a "IO Response" and not "Response" I cannot really compare the abstract_App with the real_App. Any thought on how I can extract the value from the "IO Response" so that I can compare the the two implementations for equvivalence. FYI, I have gone through the various quickcheck related docs like http://www.cs.chalmers.se/~rjmh/QuickCheck/ http://www.haskell.org/haskellwiki/QuickCheck_as_a_test_set_generator Thanks - Srikanth

On Mon, Oct 12, 2009 at 11:51:49AM +0530, Srikanth K wrote:
However, being a newbie, I am not able to understand how I can extract the "Response" part from the IO Response.
I want something as follows prop_App state_x command_y = (abstract_App state_x command_y ) == (real_App state_x command_y)
The issue here is that since the reall_App would return a "IO Response" and not "Response" I cannot really compare the abstract_App with the real_App.
Any thought on how I can extract the value from the "IO Response" so that I can compare the the two implementations for equvivalence.
Hi Srikanth, The short answer is: you can't extract a Response from an IO Response. Once something is infected with IO, there's no cure!* However, you can compare the responses if you make the result of prop_App an IO action itself: prop_App :: State -> Command -> IO Bool prop_App state_x command_y = do realResponse <- real_App state_x command_y return $ abstract_App state_x command_y == realResponse Off the top of my head I'm not sure of the proper way to run such monadic tests with QuickCheck, but it can definitely be done. -Brent * Some smart-alecks might pipe up with something about unsafePerformIO here. But that's not a cure, it's more like performing an emergency tracheotomy with a ballpoint pen.

Thanks. unsafePerformIO seems to suffice me for the moment...
However, I am ignorant about what would happen when multiple such
unsafePerformIO are done inside one function.
On Tue, Oct 13, 2009 at 11:04 PM, Daniel Fischer
Am Dienstag 13 Oktober 2009 18:04:52 schrieb Brent Yorgey:
Brent
* Some smart-alecks might pipe up with something about unsafePerformIO here. But that's not a cure, it's more like performing an emergency tracheotomy with a ballpoint pen.
Quote of the month! _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
participants (3)
-
Brent Yorgey
-
Daniel Fischer
-
Srikanth K