@@ -1,23 +1,38 @@
1−{-# LANGUAGE OverloadedStrings #-}
1+import Common
2−{-# LANGUAGE NamedFieldPuns #-}
4import Control.Exception (bracket)
2import Control.Exception (bracket)
5import Control.Monad (when)
3import Control.Monad (when)
6−import Database.PostgreSQL.Simple
7import System.Exit (exitFailure)
4import System.Exit (exitFailure)
8import System.IO
5import System.IO
11import Bytea
7import Bytea
13−tests :: Connection -> [Test]
10+tests :: [TestEnv -> Test]
14−tests conn =
11+tests =
15− [ TestLabel "Bytea" $ testBytea conn
12+ [ TestLabel "Bytea" . testBytea
13+ , TestLabel "Notify" . testNotify
16+-- | Action for connecting to the database that will be used for testing.
18+-- Note that some tests, such as Notify, use multiple connections, and assume
19+-- that 'testConnect' connects to the same database every time it is called.
20+testConnect :: IO Connection
21+testConnect = connectPostgreSQL ""
23+withTestEnv :: (TestEnv -> IO a) -> IO a
28+ , withConn = withConn
31+ withConn = bracket testConnect close
18main :: IO ()
33main :: IO ()
20 mapM_ (`hSetBuffering` LineBuffering) [stdout, stderr]
35 mapM_ (`hSetBuffering` LineBuffering) [stdout, stderr]
21− bracket (connectPostgreSQL "") close $ \conn -> do
22− Counts{cases, tried, errors, failures} <- runTestTT $ TestList $ tests conn
36+ Counts{cases, tried, errors, failures} <-
37+ withTestEnv $ \env -> runTestTT $ TestList $ map ($ env) tests
23− when (cases /= tried || errors /= 0 || failures /= 0) $ exitFailure
38+ when (cases /= tried || errors /= 0 || failures /= 0) $ exitFailure