File: TestUtils.hs

package info (click to toggle)
haskell-hsopenssl 0.11.7.8-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 556 kB
  • sloc: haskell: 1,562; ansic: 451; makefile: 16
file content (25 lines) | stat: -rw-r--r-- 799 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
module TestUtils where

import qualified Control.Exception as E
import Control.Monad

assertBool :: String -> Bool -> IO ()
assertBool n ok =
    unless ok $ E.throw $ E.AssertionFailed $ "Assertion failed: " ++ n

assertEqual :: (Show a, Eq a) => String -> a -> a -> IO ()
assertEqual n a b =
    assertBool (n ++ "\n" ++ show a ++ " /= " ++ show b) (a == b)

assertFunction
    :: (Show x, Show y, Eq y) => String -> (x -> y) -> [(x, y)] -> IO ()
assertFunction n f points =
    forM_ points $ \ (x, y) ->
        let r = f x in
        assertBool
            (n ++ " " ++ showsPrec 11 x "" ++ " == " ++ show r
             ++ " /= " ++ show y)
            (r == y)

--  assertFunction "asdf" (fmap (+1)) [(Just 1, Nothing)]
--  *** Exception: Assertion failed: asdf (Just 1) == Just 2 /= Nothing