git.iko.soy/typeable/postgresql-simple
on master help sign in
test: Update WRITING-TESTS document

Also, rearrange Main.hs so test module imports and tests :: [TestEnv -> Test] are next to each other.

commit8c153c49bc7af30908180046ac6c3e9fc34db20e authorJoey Adams <joeyadams3.14159@gmail.com> dateFri 18 May 2012, 00:35 (14 years ago) parent2573d59
2 files changed+30−11
test/Main.hs+9−9 test/WRITING-TESTS+21−2
test/Main.hs+9−9
@@ -1,12 +1,18 @@
11import Common
2−import Bytea
3−import Notify
4−
52import Control.Exception (bracket)
63import Control.Monad (when)
74import System.Exit (exitFailure)
85import System.IO
96
7+import Bytea
8+import Notify
9+
10+tests :: [TestEnv -> Test]
11+tests =
12+ [ TestLabel "Bytea" . testBytea
13+ , TestLabel "Notify" . testNotify
14+ ]
15+
1016-- | Action for connecting to the database that will be used for testing.
1117--
1218-- Note that some tests, such as Notify, use multiple connections, and assume
@@ -24,12 +30,6 @@ withTestEnv cb =
2430 where
2531 withConn = bracket testConnect close
2632
27−tests :: [TestEnv -> Test]
28−tests =
29− [ TestLabel "Bytea" . testBytea
30− , TestLabel "Notify" . testNotify
31− ]
32−
3333main :: IO ()
3434main = do
3535 mapM_ (`hSetBuffering` LineBuffering) [stdout, stderr]
test/WRITING-TESTS+21−2
@@ -3,9 +3,28 @@ starts the HUnit text-based test controller.
33
44To add a new module to the test suite, do the following:
55
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+
726 '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.
928
1029 * Add an entry to 'tests' in Main.hs (along with the corresponding
1130 module import) so the test driver will know about the new module.