@@ -1,15 +1,14 @@
11{-# LANGUAGE OverloadedStrings #-}
22{-# LANGUAGE NamedFieldPuns #-}
33
4+import Common
5+import Bytea
6+import Notify
7+
48import Control.Exception (bracket)
59import Control.Monad (when)
6−import Database.PostgreSQL.Simple
710import System.Exit (exitFailure)
811import System.IO
9−import Test.HUnit
10−
11−import Bytea
12−import Notify
1312
1413-- | Action for connecting to the database that will be used for testing.
1514--
@@ -18,18 +17,25 @@ import Notify
1817testConnect :: IO Connection
1918testConnect = connectPostgreSQL ""
2019
21−withConn :: (Connection -> IO a) -> IO a
22−withConn = bracket testConnect close
20+withTestEnv :: (TestEnv -> IO a) -> IO a
21+withTestEnv cb =
22+ withConn $ \conn ->
23+ cb TestEnv
24+ { conn = conn
25+ , withConn = withConn
26+ }
27+ where
28+ withConn = bracket testConnect close
2329
24−tests :: Connection -> [Test]
25−tests conn =
26− [ TestLabel "Bytea" $ testBytea conn
27− , TestLabel "Notify" $ testNotify conn withConn
30+tests :: [TestEnv -> Test]
31+tests =
32+ [ TestLabel "Bytea" . testBytea
33+ , TestLabel "Notify" . testNotify
2834 ]
2935
3036main :: IO ()
3137main = do
3238 mapM_ (`hSetBuffering` LineBuffering) [stdout, stderr]
3339 Counts{cases, tried, errors, failures} <-
34− withConn $ runTestTT . TestList . tests
40+ withTestEnv $ \env -> runTestTT $ TestList $ map ($ env) tests
3541 when (cases /= tried || errors /= 0 || failures /= 0) $ exitFailure