@@ -1,15 +1,14 @@
1{-# LANGUAGE OverloadedStrings #-}
1{-# LANGUAGE OverloadedStrings #-}
2{-# LANGUAGE NamedFieldPuns #-}
2{-# LANGUAGE NamedFieldPuns #-}
4import Control.Exception (bracket)
8import Control.Exception (bracket)
5import Control.Monad (when)
9import Control.Monad (when)
6−import Database.PostgreSQL.Simple
7import System.Exit (exitFailure)
10import System.Exit (exitFailure)
8import System.IO
11import System.IO
14-- | Action for connecting to the database that will be used for testing.
13-- | Action for connecting to the database that will be used for testing.
@@ -18,18 +17,25 @@ import Notify
18testConnect :: IO Connection
17testConnect :: IO Connection
19testConnect = connectPostgreSQL ""
18testConnect = connectPostgreSQL ""
21−withConn :: (Connection -> IO a) -> IO a
20+withTestEnv :: (TestEnv -> IO a) -> IO a
25+ , withConn = withConn
22−withConn = bracket testConnect close
28+ withConn = bracket testConnect close
24−tests :: Connection -> [Test]
30+tests :: [TestEnv -> Test]
25−tests conn =
31+tests =
26− [ TestLabel "Bytea" $ testBytea conn
32+ [ TestLabel "Bytea" . testBytea
27− , TestLabel "Notify" $ testNotify conn withConn
33+ , TestLabel "Notify" . testNotify
30main :: IO ()
36main :: IO ()
32 mapM_ (`hSetBuffering` LineBuffering) [stdout, stderr]
38 mapM_ (`hSetBuffering` LineBuffering) [stdout, stderr]
33 Counts{cases, tried, errors, failures} <-
39 Counts{cases, tried, errors, failures} <-
34− withConn $ runTestTT . TestList . tests
40+ withTestEnv $ \env -> runTestTT $ TestList $ map ($ env) tests
35 when (cases /= tried || errors /= 0 || failures /= 0) $ exitFailure
41 when (cases /= tried || errors /= 0 || failures /= 0) $ exitFailure