Skip to content

Instantly share code, notes, and snippets.

@etrepum
Created June 7, 2014 20:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save etrepum/d450420a7fd8c2e73aec to your computer and use it in GitHub Desktop.
Save etrepum/d450420a7fd8c2e73aec to your computer and use it in GitHub Desktop.
QCFail.hs
import Data.Either (isLeft)
import Control.Exception (try, evaluate, SomeException)
import Test.QuickCheck (Property, quickCheck)
import Test.QuickCheck.Monadic (monadicIO, run, assert)
isFailure :: a -> IO Bool
isFailure = fmap isLeft . tryEval
where
tryEval :: a -> IO (Either SomeException a)
tryEval = try . evaluate
prop_empty_list :: Int -> Property
prop_empty_list idx = monadicIO (run (isFailure ([] !! idx)) >>= assert)
prop_unexpected_success :: Int -> Property
prop_unexpected_success idx = monadicIO (run (isFailure ([()] !! idx)) >>= assert)
main :: IO ()
main = mapM_ quickCheck [ prop_empty_list, prop_unexpected_success ]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment