Note that there are some explanatory texts on larger screens.

plurals
  1. POHow can I prevent QuickCheck from catching all exceptions?
    primarykey
    data
    text
    <p>The QuickCheck library seems to catch all exceptions that are thrown when testing a property. In particular, this behavior prevents me from putting a time limit on the entire QuickCheck computation. For example:</p> <pre><code>module QuickCheckTimeout where import System.Timeout (timeout) import Control.Concurrent (threadDelay) import Test.QuickCheck (quickCheck, within, Property) import Test.QuickCheck.Monadic (monadicIO, run, assert) -- use threadDelay to simulate a slow computation prop_slow_plus_zero_right_identity :: Int -&gt; Property prop_slow_plus_zero_right_identity i = monadicIO $ do run (threadDelay (100000 * i)) assert (i + 0 == i) runTests :: IO () runTests = do result &lt;- timeout 3000000 (quickCheck prop_slow_plus_zero_right_identity) case result of Nothing -&gt; putStrLn "timed out!" Just _ -&gt; putStrLn "completed!" </code></pre> <p>Because QuickCheck catches all the exceptions, <code>timeout</code> breaks: it doesn't actually abort the computation! Instead, QuickCheck treats the property as having failed, and tries to shrink the input that caused the failure. This shrinking process is then not run with a time bound, causing the total time used by the computation to exceed the prescribed time limit.</p> <p>One might think I could use QuickCheck's <code>within</code> combinator to bound the computation time. (<code>within</code> treats a property as having failed if it doesn't finish within the given time limit.) However, <code>within</code> doesn't quite do what I want, since QuickCheck still tries to shrink the input that caused the failure, a process that can take far too long. (What could alternatively work for me is a version of <code>within</code> that prevents QuickCheck from trying to shrink the inputs to a property that failed because it didn't finish within the given time limit.)</p> <p>How can I prevent QuickCheck from catching all exceptions?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload