git.iko.soy/typeable/postgresql-simple
on 8c153c4 help sign in
38 lines 1.1 kB history raw
1import Common
2import Control.Exception (bracket)
3import Control.Monad (when)
4import System.Exit (exitFailure)
5import System.IO
7import Bytea
8import Notify
10tests :: [TestEnv -> Test]
11tests =
12 [ TestLabel "Bytea" . testBytea
13 , TestLabel "Notify" . testNotify
14 ]
16-- | Action for connecting to the database that will be used for testing.
17--
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.
20testConnect :: IO Connection
21testConnect = connectPostgreSQL ""
23withTestEnv :: (TestEnv -> IO a) -> IO a
24withTestEnv cb =
25 withConn $ \conn ->
26 cb TestEnv
27 { conn = conn
28 , withConn = withConn
29 }
30 where
31 withConn = bracket testConnect close
33main :: IO ()
34main = do
35 mapM_ (`hSetBuffering` LineBuffering) [stdout, stderr]
36 Counts{cases, tried, errors, failures} <-
37 withTestEnv $ \env -> runTestTT $ TestList $ map ($ env) tests
38 when (cases /= tried || errors /= 0 || failures /= 0) $ exitFailure