nick8325 / quickcheck

Automatic testing of Haskell programs.
Other
713 stars 119 forks source link

QuickCheck's `within` not timing out on infinite lists #337

Closed tomdjong closed 2 years ago

tomdjong commented 2 years ago

I don't understand why QuickCheck's within is not timing out on infinite lists. To illustrate this, consider the following MWE.

import Test.QuickCheck

timeout :: Int
timeout = 10000

prop_length :: Property
prop_length = within timeout $ length (repeat 1) >= 0

repeat' :: a -> [a]
repeat' x = take maxBound (repeat x)

prop_length' :: Property
prop_length' = within timeout $ length (repeat' 1) >= 0

Now quickCheck prop_length' times out as expected, but quickCheck prop_length hangs.

Is this a bug or is there a good reason for this phenomenon?

phadej commented 2 years ago

length and repeat probably compile to a non-allocating loop which base timeout is not able to interrupt.

See

tomdjong commented 2 years ago

I see, so it's a ghc problem. Thanks a lot for the quick and helpful reply!