From a5d7cbdae95acc686191049f83a4edddb530f329 Mon Sep 17 00:00:00 2001 From: gcnew Date: Thu, 3 Nov 2016 02:47:17 +0200 Subject: [PATCH] Improved testing logic - throwing functions are handled better now --- exercises/lists/Testing.hs | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/exercises/lists/Testing.hs b/exercises/lists/Testing.hs index 940995e..1c8b230 100644 --- a/exercises/lists/Testing.hs +++ b/exercises/lists/Testing.hs @@ -35,15 +35,18 @@ ptrEq x y = isTrue# (reallyUnsafePtrEquality# x y) throwsError :: a throwsError = error "throwsError" -testEq :: Eq a => a -> a -> Bool -testEq arg res - | not (res `ptrEq` throwsError) = arg == res - - | otherwise = unsafePerformIO $ +isError :: a -> Bool +isError x = unsafePerformIO $ handle (\(_ :: SomeException) -> return True) $ do - let !_ = arg == res + let !_ = x return False +testEq :: Eq a => a -> a -> Bool +testEq res xpect = unsafePerformIO $ + handle (\(_ :: SomeException) -> return (xpect `ptrEq` throwsError && isError res)) $ do + let !rtv = res == xpect + return rtv + runTest :: Test -> Maybe Failure runTest (Test s f as) = case filter (not . f) as of [] -> Nothing