From 5ff30e7c5c7f89c31a657a4f3d9f9542745c069f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Crist=C3=B3v=C3=A3o?= Date: Sun, 15 Sep 2013 15:58:13 +0100 Subject: [PATCH] Minor changes --- test/Test.hs | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/test/Test.hs b/test/Test.hs index 1ee3ee2..7aa7fd6 100644 --- a/test/Test.hs +++ b/test/Test.hs @@ -27,7 +27,9 @@ import Database.Persist.Postgresql (withPostgresqlConn) import Database.Persist.MySQL ( withMySQLConn , connectHost , connectDatabase - ,connectUser,connectPassword,defaultConnectInfo) + , connectUser + , connectPassword + , defaultConnectInfo) #endif import Database.Persist.TH import Test.Hspec @@ -55,8 +57,8 @@ share [mkPersist sqlSettings, mkMigrate "migrateAll"] [persistUpperCase| -- | this could be achieved with S.fromList, but not all lists -- have Ord instances -sameElements :: Eq a => [a] -> [a] -> Bool -sameElements l1 l2 = null (l1 L.\\ l2) +sameElementsAs :: Eq a => [a] -> [a] -> Bool +sameElementsAs l1 l2 = null (l1 L.\\ l2) main :: IO () main = do @@ -110,10 +112,10 @@ main = do ret <- select $ from $ \(person1, person2) -> return (person1, person2) - liftIO $ ret `shouldSatisfy` sameElements [ (p1e, p1e) - , (p1e, p2e) - , (p2e, p1e) - , (p2e, p2e) ] + liftIO $ ret `shouldSatisfy` sameElementsAs [ (p1e, p1e) + , (p1e, p2e) + , (p2e, p1e) + , (p2e, p2e) ] it "works for a simple projection" $ run $ do @@ -132,7 +134,7 @@ main = do ret <- select $ from $ \(pa, pb) -> return (pa ^. PersonName, pb ^. PersonName) - liftIO $ ret `shouldSatisfy` sameElements + liftIO $ ret `shouldSatisfy` sameElementsAs [ (Value (personName p1), Value (personName p1)) , (Value (personName p1), Value (personName p2)) , (Value (personName p2), Value (personName p1)) @@ -771,6 +773,10 @@ type RunDbMonad m = ( MonadBaseControl IO m, MonadIO m, MonadLogger m , C.MonadUnsafeIO m, C.MonadThrow m ) #if defined (WITH_POSTGRESQL) || defined (WITH_MYSQL) +-- With SQLite and in-memory databases, a separate connection implies a +-- separate database. With 'actual databases', the data is persistent and +-- thus must be cleaned after each test. +-- TODO: there is certainly a better way... cleanDB :: (forall m. RunDbMonad m => SqlPersistT (C.ResourceT m) ()) @@ -798,7 +804,7 @@ run_worker :: RunDbMonad m => SqlPersistT (C.ResourceT m) a -> m a run_worker act = C.runResourceT . #if defined(WITH_POSTGRESQL) - withPostgresqlConn "host=localhost port=5432 user=test dbname=test" . + withPostgresqlConn "host=localhost port=5432 user=joao dbname=esqueleto" . #elif defined (WITH_MYSQL) withMySQLConn defaultConnectInfo { connectHost = "localhost"