git.iko.soy/typeable/postgresql-simple
on master help sign in
Move testsuite to tasty
ce97656Ben Gamari
postgresql-simple.cabal+2
@@ -115,6 +115,8 @@ test-suite test
115 , bytestring
115 , bytestring
116 , containers
116 , containers
117 , cryptohash
117 , cryptohash
118+ , tasty
119+ , tasty-hunit
118 , HUnit
120 , HUnit
119 , postgresql-simple
121 , postgresql-simple
120 , text
122 , text
test/Common.hs+2−2
@@ -1,6 +1,6 @@
1module Common (
1module Common (
2 module Database.PostgreSQL.Simple,
2 module Database.PostgreSQL.Simple,
3− module Test.HUnit,
3+ module Test.Tasty.HUnit,
4 TestEnv(..),
4 TestEnv(..),
5 md5,
5 md5,
6) where
6) where
@@ -8,7 +8,7 @@ module Common (
8import Data.ByteString (ByteString)
8import Data.ByteString (ByteString)
9import Data.Text (Text)
9import Data.Text (Text)
10import Database.PostgreSQL.Simple
10import Database.PostgreSQL.Simple
11−import Test.HUnit
11+import Test.Tasty.HUnit
12
12
13import qualified Crypto.Hash.MD5 as MD5
13import qualified Crypto.Hash.MD5 as MD5
14import qualified Data.ByteString.Base16 as Base16
14import qualified Data.ByteString.Base16 as Base16
test/Main.hs+51−55
@@ -20,39 +20,39 @@ import Data.List (sort)
20import qualified Data.Map as Map
20import qualified Data.Map as Map
21import Data.Text(Text)
21import Data.Text(Text)
22import qualified Data.Text.Encoding as T
22import qualified Data.Text.Encoding as T
23−import System.Exit (exitFailure)
24−import System.IO
25import qualified Data.Vector as V
23import qualified Data.Vector as V
26import Data.Aeson
24import Data.Aeson
27import GHC.Generics (Generic)
25import GHC.Generics (Generic)
28
26
27+import Test.Tasty
29import Notify
28import Notify
30import Serializable
29import Serializable
31import Time
30import Time
32
31
33−tests :: [TestEnv -> Test]
32+tests :: TestEnv -> TestTree
34−tests =
33+tests env = testGroup "tests"
34+ $ map ($ env)
35− [ TestLabel "Bytea" . testBytea
35+ [ testBytea
36− , TestLabel "ExecuteMany" . testExecuteMany
36+ , testCase "ExecuteMany" . testExecuteMany
37− , TestLabel "Fold" . testFold
37+ , testCase "Fold" . testFold
38− , TestLabel "Notify" . testNotify
38+ , testCase "Notify" . testNotify
39− , TestLabel "Serializable" . testSerializable
39+ , testCase "Serializable" . testSerializable
40− , TestLabel "Time" . testTime
40+ , testCase "Time" . testTime
41− , TestLabel "Array" . testArray
41+ , testCase "Array" . testArray
42− , TestLabel "HStore" . testHStore
42+ , testCase "HStore" . testHStore
43− , TestLabel "JSON" . testJSON
43+ , testCase "JSON" . testJSON
44− , TestLabel "Savepoint" . testSavepoint
44+ , testCase "Savepoint" . testSavepoint
45− , TestLabel "Unicode" . testUnicode
45+ , testCase "Unicode" . testUnicode
46− , TestLabel "Values" . testValues
46+ , testCase "Values" . testValues
47− , TestLabel "Copy" . testCopy
47+ , testCase "Copy" . testCopy
48− , TestLabel "Double" . testDouble
48+ , testCase "Double" . testDouble
49− , TestLabel "1-ary generic" . testGeneric1
49+ , testCase "1-ary generic" . testGeneric1
50− , TestLabel "2-ary generic" . testGeneric2
50+ , testCase "2-ary generic" . testGeneric2
51− , TestLabel "3-ary generic" . testGeneric3
51+ , testCase "3-ary generic" . testGeneric3
52 ]
52 ]
53
53
54−testBytea :: TestEnv -> Test
54+testBytea :: TestEnv -> TestTree
55−testBytea TestEnv{..} = TestList
55+testBytea TestEnv{..} = testGroup "Bytea"
56 [ testStr "empty" []
56 [ testStr "empty" []
57 , testStr "\"hello\"" $ map (fromIntegral . fromEnum) ("hello" :: String)
57 , testStr "\"hello\"" $ map (fromIntegral . fromEnum) ("hello" :: String)
58 , testStr "ascending" [0..255]
58 , testStr "ascending" [0..255]
@@ -61,7 +61,7 @@ testBytea TestEnv{..} = TestList
61 , testStr "descending, doubled up" $ doubleUp [255,254..0]
61 , testStr "descending, doubled up" $ doubleUp [255,254..0]
62 ]
62 ]
63 where
63 where
64− testStr label bytes = TestLabel label $ TestCase $ do
64+ testStr label bytes = testCase label $ do
65 let bs = B.pack bytes
65 let bs = B.pack bytes
66
66
67 [Only h] <- query conn "SELECT md5(?::bytea)" [Binary bs]
67 [Only h] <- query conn "SELECT md5(?::bytea)" [Binary bs]
@@ -72,8 +72,8 @@ testBytea TestEnv{..} = TestList
72
72
73 doubleUp = concatMap (\x -> [x, x])
73 doubleUp = concatMap (\x -> [x, x])
74
74
75−testExecuteMany :: TestEnv -> Test
75+testExecuteMany :: TestEnv -> Assertion
76−testExecuteMany TestEnv{..} = TestCase $ do
76+testExecuteMany TestEnv{..} = do
77 execute_ conn "CREATE TEMPORARY TABLE tmp_executeMany (i INT, t TEXT, b BYTEA)"
77 execute_ conn "CREATE TEMPORARY TABLE tmp_executeMany (i INT, t TEXT, b BYTEA)"
78
78
79 let rows :: [(Int, String, Binary ByteString)]
79 let rows :: [(Int, String, Binary ByteString)]
@@ -90,8 +90,8 @@ testExecuteMany TestEnv{..} = TestCase $ do
90
90
91 return ()
91 return ()
92
92
93−testFold :: TestEnv -> Test
93+testFold :: TestEnv -> Assertion
94−testFold TestEnv{..} = TestCase $ do
94+testFold TestEnv{..} = do
95 xs <- fold_ conn "SELECT generate_series(1,10000)"
95 xs <- fold_ conn "SELECT generate_series(1,10000)"
96 [] $ \xs (Only x) -> return (x:xs)
96 [] $ \xs (Only x) -> return (x:xs)
97 reverse xs @?= ([1..10000] :: [Int])
97 reverse xs @?= ([1..10000] :: [Int])
@@ -160,8 +160,8 @@ queryFailure conn q resultType = do
160 ++ show (typeOf resultType)
160 ++ show (typeOf resultType)
161 ++ " -> " ++ show val)
161 ++ " -> " ++ show val)
162
162
163−testArray :: TestEnv -> Test
163+testArray :: TestEnv -> Assertion
164−testArray TestEnv{..} = TestCase $ do
164+testArray TestEnv{..} = do
165 xs <- query_ conn "SELECT '{1,2,3,4}'::_int4"
165 xs <- query_ conn "SELECT '{1,2,3,4}'::_int4"
166 xs @?= [Only (V.fromList [1,2,3,4 :: Int])]
166 xs @?= [Only (V.fromList [1,2,3,4 :: Int])]
167 xs <- query_ conn "SELECT '{{1,2},{3,4}}'::_int4"
167 xs <- query_ conn "SELECT '{{1,2},{3,4}}'::_int4"
@@ -170,8 +170,8 @@ testArray TestEnv{..} = TestCase $ do
170 queryFailure conn "SELECT '{1,2,3,4}'::_int4" (undefined :: V.Vector Bool)
170 queryFailure conn "SELECT '{1,2,3,4}'::_int4" (undefined :: V.Vector Bool)
171 queryFailure conn "SELECT '{{1,2},{3,4}}'::_int4" (undefined :: V.Vector Int)
171 queryFailure conn "SELECT '{{1,2},{3,4}}'::_int4" (undefined :: V.Vector Int)
172
172
173−testHStore :: TestEnv -> Test
173+testHStore :: TestEnv -> Assertion
174−testHStore TestEnv{..} = TestCase $ do
174+testHStore TestEnv{..} = do
175 execute_ conn "CREATE EXTENSION IF NOT EXISTS hstore"
175 execute_ conn "CREATE EXTENSION IF NOT EXISTS hstore"
176 roundTrip []
176 roundTrip []
177 roundTrip [("foo","bar"),("bar","baz"),("baz","hello")]
177 roundTrip [("foo","bar"),("bar","baz"),("baz","hello")]
@@ -183,8 +183,8 @@ testHStore TestEnv{..} = TestCase $ do
183 m' <- query conn "SELECT ?::hstore" m
183 m' <- query conn "SELECT ?::hstore" m
184 [m] @?= m'
184 [m] @?= m'
185
185
186−testJSON :: TestEnv -> Test
186+testJSON :: TestEnv -> Assertion
187−testJSON TestEnv{..} = TestCase $ do
187+testJSON TestEnv{..} = do
188 roundTrip (Map.fromList [] :: Map Text Text)
188 roundTrip (Map.fromList [] :: Map Text Text)
189 roundTrip (Map.fromList [("foo","bar"),("bar","baz"),("baz","hello")] :: Map Text Text)
189 roundTrip (Map.fromList [("foo","bar"),("bar","baz"),("baz","hello")] :: Map Text Text)
190 roundTrip (Map.fromList [("fo\"o","bar"),("b\\ar","baz"),("baz","\"value\\with\"escapes")] :: Map Text Text)
190 roundTrip (Map.fromList [("fo\"o","bar"),("b\\ar","baz"),("baz","\"value\\with\"escapes")] :: Map Text Text)
@@ -198,8 +198,8 @@ testJSON TestEnv{..} = TestCase $ do
198 js' <- query conn "SELECT ?::json" js
198 js' <- query conn "SELECT ?::json" js
199 [js] @?= js'
199 [js] @?= js'
200
200
201−testSavepoint :: TestEnv -> Test
201+testSavepoint :: TestEnv -> Assertion
202−testSavepoint TestEnv{..} = TestCase $ do
202+testSavepoint TestEnv{..} = do
203 True <- expectError ST.isNoActiveTransactionError $
203 True <- expectError ST.isNoActiveTransactionError $
204 withSavepoint conn $ return ()
204 withSavepoint conn $ return ()
205
205
@@ -259,8 +259,8 @@ testSavepoint TestEnv{..} = TestCase $ do
259
259
260 return ()
260 return ()
261
261
262−testUnicode :: TestEnv -> Test
262+testUnicode :: TestEnv -> Assertion
263−testUnicode TestEnv{..} = TestCase $ do
263+testUnicode TestEnv{..} = do
264 let q = Query . T.encodeUtf8 -- Handle encoding ourselves to ensure
264 let q = Query . T.encodeUtf8 -- Handle encoding ourselves to ensure
265 -- the table gets created correctly.
265 -- the table gets created correctly.
266 let messages = map Only ["привет","мир"] :: [Only Text]
266 let messages = map Only ["привет","мир"] :: [Only Text]
@@ -269,8 +269,8 @@ testUnicode TestEnv{..} = TestCase $ do
269 messages' <- query_ conn "SELECT сообщение FROM ру́сский"
269 messages' <- query_ conn "SELECT сообщение FROM ру́сский"
270 sort messages @?= sort messages'
270 sort messages @?= sort messages'
271
271
272−testValues :: TestEnv -> Test
272+testValues :: TestEnv -> Assertion
273−testValues TestEnv{..} = TestCase $ do
273+testValues TestEnv{..} = do
274 execute_ conn "CREATE TEMPORARY TABLE values_test (x int, y text)"
274 execute_ conn "CREATE TEMPORARY TABLE values_test (x int, y text)"
275 test (Values ["int4","text"] [])
275 test (Values ["int4","text"] [])
276 test (Values ["int4","text"] [(1,"hello")])
276 test (Values ["int4","text"] [(1,"hello")])
@@ -287,8 +287,8 @@ testValues TestEnv{..} = TestCase $ do
287 sort vals @?= sort vals'
287 sort vals @?= sort vals'
288
288
289
289
290−testCopy :: TestEnv -> Test
290+testCopy :: TestEnv -> Assertion
291−testCopy TestEnv{..} = TestCase $ do
291+testCopy TestEnv{..} = do
292 execute_ conn "CREATE TEMPORARY TABLE copy_test (x int, y text)"
292 execute_ conn "CREATE TEMPORARY TABLE copy_test (x int, y text)"
293 copy_ conn "COPY copy_test FROM STDIN (FORMAT CSV)"
293 copy_ conn "COPY copy_test FROM STDIN (FORMAT CSV)"
294 mapM_ (putCopyData conn) copyRows
294 mapM_ (putCopyData conn) copyRows
@@ -315,8 +315,8 @@ testCopy TestEnv{..} = TestCase $ do
315 CopyOutDone _ -> return rows
315 CopyOutDone _ -> return rows
316 CopyOutRow row -> loop (row:rows)
316 CopyOutRow row -> loop (row:rows)
317
317
318−testDouble :: TestEnv -> Test
318+testDouble :: TestEnv -> Assertion
319−testDouble TestEnv{..} = TestCase $ do
319+testDouble TestEnv{..} = do
320 [Only (x :: Double)] <- query_ conn "SELECT 'NaN'::float8"
320 [Only (x :: Double)] <- query_ conn "SELECT 'NaN'::float8"
321 assertBool "expected NaN" (isNaN x)
321 assertBool "expected NaN" (isNaN x)
322 [Only (x :: Double)] <- query_ conn "SELECT 'Infinity'::float8"
322 [Only (x :: Double)] <- query_ conn "SELECT 'Infinity'::float8"
@@ -325,24 +325,24 @@ testDouble TestEnv{..} = TestCase $ do
325 x @?= (-1 / 0)
325 x @?= (-1 / 0)
326
326
327
327
328−testGeneric1 :: TestEnv -> Test
328+testGeneric1 :: TestEnv -> Assertion
329−testGeneric1 TestEnv{..} = TestCase $ do
329+testGeneric1 TestEnv{..} = do
330 roundTrip conn (Gen1 123)
330 roundTrip conn (Gen1 123)
331 where
331 where
332 roundTrip conn x0 = do
332 roundTrip conn x0 = do
333 r <- query conn "SELECT ?::int" (x0 :: Gen1)
333 r <- query conn "SELECT ?::int" (x0 :: Gen1)
334 r @?= [x0]
334 r @?= [x0]
335
335
336−testGeneric2 :: TestEnv -> Test
336+testGeneric2 :: TestEnv -> Assertion
337−testGeneric2 TestEnv{..} = TestCase $ do
337+testGeneric2 TestEnv{..} = do
338 roundTrip conn (Gen2 123 "asdf")
338 roundTrip conn (Gen2 123 "asdf")
339 where
339 where
340 roundTrip conn x0 = do
340 roundTrip conn x0 = do
341 r <- query conn "SELECT ?::int, ?::text" x0
341 r <- query conn "SELECT ?::int, ?::text" x0
342 r @?= [x0]
342 r @?= [x0]
343
343
344−testGeneric3 :: TestEnv -> Test
344+testGeneric3 :: TestEnv -> Assertion
345−testGeneric3 TestEnv{..} = TestCase $ do
345+testGeneric3 TestEnv{..} = do
346 roundTrip conn (Gen3 123 "asdf" True)
346 roundTrip conn (Gen3 123 "asdf" True)
347 where
347 where
348 roundTrip conn x0 = do
348 roundTrip conn x0 = do
@@ -401,8 +401,4 @@ withTestEnv cb =
401 withConn = bracket testConnect close
401 withConn = bracket testConnect close
402
402
403main :: IO ()
403main :: IO ()
404−main = do
405− mapM_ (`hSetBuffering` LineBuffering) [stdout, stderr]
406− Counts{cases, tried, errors, failures} <-
407− withTestEnv $ \env -> runTestTT $ TestList $ map ($ env) tests
404+main = withTestEnv $ defaultMain . tests
408− when (cases /= tried || errors /= 0 || failures /= 0) $ exitFailure
test/Notify.hs+1−2
@@ -14,9 +14,8 @@ import qualified Data.ByteString as B
14-- TODO: Test with payload, but only for PostgreSQL >= 9.0
14-- TODO: Test with payload, but only for PostgreSQL >= 9.0
15-- (when that feature was introduced).
15-- (when that feature was introduced).
16
16
17−testNotify :: TestEnv -> Test
17+testNotify :: TestEnv -> Assertion
18testNotify TestEnv{..} =
18testNotify TestEnv{..} =
19− TestCase $
20 withConn $ \conn2 -> do
19 withConn $ \conn2 -> do
21 execute_ conn "LISTEN foo"
20 execute_ conn "LISTEN foo"
22 execute_ conn "LISTEN bar"
21 execute_ conn "LISTEN bar"
test/Serializable.hs+1−2
@@ -23,9 +23,8 @@ putCounter conn n = do
23 1 <- execute conn "UPDATE testSerializableCounter SET n=?" (Only n)
23 1 <- execute conn "UPDATE testSerializableCounter SET n=?" (Only n)
24 return ()
24 return ()
25
25
26−testSerializable :: TestEnv -> Test
26+testSerializable :: TestEnv -> Assertion
27testSerializable TestEnv{..} =
27testSerializable TestEnv{..} =
28− TestCase $
29 withConn $ \conn2 -> do
28 withConn $ \conn2 -> do
30 initCounter conn
29 initCounter conn
31
30
test/Time.hs+2−2
@@ -43,8 +43,8 @@ import Database.PostgreSQL.Simple.SqlQQ
43numTests :: Int
43numTests :: Int
44numTests = 200
44numTests = 200
45
45
46−testTime :: TestEnv -> Test
46+testTime :: TestEnv -> Assertion
47−testTime env@TestEnv{..} = TestCase $ do
47+testTime env@TestEnv{..} = do
48 initializeTable env
48 initializeTable env
49 execute_ conn "SET timezone TO 'UTC'"
49 execute_ conn "SET timezone TO 'UTC'"
50 checkRoundTrips env "1860-01-01 00:00:00+00"
50 checkRoundTrips env "1860-01-01 00:00:00+00"