@@ -9,15 +9,27 @@ import System.IO
9import Test.HUnit
9import Test.HUnit
11import Bytea
11import Bytea
14+-- | Action for connecting to the database that will be used for testing.
16+-- Note that some tests, such as Notify, use multiple connections, and assume
17+-- that 'testConnect' connects to the same database every time it is called.
18+testConnect :: IO Connection
19+testConnect = connectPostgreSQL ""
21+withConn :: (Connection -> IO a) -> IO a
22+withConn = bracket testConnect close
13tests :: Connection -> [Test]
24tests :: Connection -> [Test]
14tests conn =
25tests conn =
15− [ TestLabel "Bytea" $ testBytea conn
26+ [ TestLabel "Bytea" $ testBytea conn
27+ , TestLabel "Notify" $ testNotify conn withConn
18main :: IO ()
30main :: IO ()
20 mapM_ (`hSetBuffering` LineBuffering) [stdout, stderr]
32 mapM_ (`hSetBuffering` LineBuffering) [stdout, stderr]
21− bracket (connectPostgreSQL "") close $ \conn -> do
22− Counts{cases, tried, errors, failures} <- runTestTT $ TestList $ tests conn
33+ Counts{cases, tried, errors, failures} <-
34+ withConn $ runTestTT . TestList . tests
23− when (cases /= tried || errors /= 0 || failures /= 0) $ exitFailure
35+ when (cases /= tried || errors /= 0 || failures /= 0) $ exitFailure