File: FileLocation.hs

package info (click to toggle)
haskell-file-location 0.4.9.1-4
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 112 kB
  • sloc: haskell: 282; ansic: 13; makefile: 2; sh: 1
file content (35 lines) | stat: -rw-r--r-- 978 bytes parent folder | download | duplicates (4)
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
26
27
28
29
30
31
32
33
34
35
{-# LANGUAGE TemplateHaskell #-}
module Test.FileLocation where

import qualified Test.HUnit as HUnit
import Language.Haskell.TH
import FileLocation (locationToString)
import Control.Monad.IO.Class (liftIO)

-- | A version of assertEqual that gives location information.
assertEq :: Q Exp
assertEq = do
  loc <- location
  let prefix = locationToString loc ++ " "
  [|(\x -> HUnit.assertEqual prefix x)|]

-- | a MonadIO version of assertBool that gives location information.
assertB :: Q Exp
assertB = do
  loc <- location
  let prefix = locationToString loc ++ "assertB "
  [|(HUnit.assertBool prefix)|]

-- | Same as 'assertEq', but uses 'liftIO'
assertEq' :: Q Exp
assertEq' = do
  loc <- location
  let prefix = locationToString loc ++ " "
  [|(\x -> liftIO . HUnit.assertEqual prefix x)|]

-- | Same as 'assertB, but uses 'liftIO'
assertB' :: Q Exp
assertB' = do
  loc <- location
  let prefix = locationToString loc ++ "assertB "
  [|(liftIO . HUnit.assertBool prefix)|]