Skip to content

Commit

Permalink
Improved testing logic - throwing functions are handled better now
Browse files Browse the repository at this point in the history
  • Loading branch information
gcnew committed Nov 3, 2016
1 parent fb51e26 commit a5d7cbd
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions exercises/lists/Testing.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit a5d7cbd

Please sign in to comment.