git.iko.soy/typeable/postgresql-simple
on master help sign in
test: Update WRITING-TESTS document
8c153c4Joey Adams
test/Main.hs+9−9
@@ -1,12 +1,18 @@
1import Common
1import Common
2−import Bytea
3−import Notify
4−
5import Control.Exception (bracket)
2import Control.Exception (bracket)
6import Control.Monad (when)
3import Control.Monad (when)
7import System.Exit (exitFailure)
4import System.Exit (exitFailure)
8import System.IO
5import System.IO
9
6
7+import Bytea
8+import Notify
9+
10+tests :: [TestEnv -> Test]
11+tests =
12+ [ TestLabel "Bytea" . testBytea
13+ , TestLabel "Notify" . testNotify
14+ ]
15+
10-- | Action for connecting to the database that will be used for testing.
16-- | Action for connecting to the database that will be used for testing.
11--
17--
12-- Note that some tests, such as Notify, use multiple connections, and assume
18-- Note that some tests, such as Notify, use multiple connections, and assume
@@ -24,12 +30,6 @@ withTestEnv cb =
24 where
30 where
25 withConn = bracket testConnect close
31 withConn = bracket testConnect close
26
32
27−tests :: [TestEnv -> Test]
28−tests =
29− [ TestLabel "Bytea" . testBytea
30− , TestLabel "Notify" . testNotify
31− ]
32−
33main :: IO ()
33main :: IO ()
34main = do
34main = do
35 mapM_ (`hSetBuffering` LineBuffering) [stdout, stderr]
35 mapM_ (`hSetBuffering` LineBuffering) [stdout, stderr]
test/WRITING-TESTS+21−2
@@ -3,9 +3,28 @@ starts the HUnit text-based test controller.
3
3
4To add a new module to the test suite, do the following:
4To add a new module to the test suite, do the following:
5
5
6− * Create a new module that exports a function of type Connection -> Test.
6+ * Create a new module that exports a function of type TestEnv -> Test.
7+ For example:
8+
9+ module Foo (testFoo) where
10+
11+ import Common
12+
13+ testFoo :: TestEnv -> Test
14+ testFoo TestEnv{..} = ...
15+
16+ 'TestEnv' (defined in Common.hs) contains information for accessing the
17+ database. `TestEnv{..}` is a record wildcard which brings the following
18+ definitions into scope:
19+
20+ conn :: Connection
21+ withConn :: (Connection -> IO a) -> IO a
22+
23+ 'conn' is a database connection shared by all the tests.
24+ 'withConn' can be used to open additional connections (to the same database).
25+
7 'Test' is basically a tree of 'Assertion's, where 'Assertion' is just a type
26 'Test' is basically a tree of 'Assertion's, where 'Assertion' is just a type
8− alias for IO (). See Bytea.hs for reference.
27+ alias for IO (). See the HLint documentation for more information.
9
28
10 * Add an entry to 'tests' in Main.hs (along with the corresponding
29 * Add an entry to 'tests' in Main.hs (along with the corresponding
11 module import) so the test driver will know about the new module.
30 module import) so the test driver will know about the new module.