From 1d569ce54e8bbc073123b9642764cf65b05f8851 Mon Sep 17 00:00:00 2001 From: Oleg Grenrus Date: Thu, 18 Apr 2024 17:52:56 +0300 Subject: [PATCH] Use tasty in test-suite --- postgresql-libpq.cabal | 9 +++++---- test/Smoke.hs | 30 ++++++++++++++++++------------ 2 files changed, 23 insertions(+), 16 deletions(-) diff --git a/postgresql-libpq.cabal b/postgresql-libpq.cabal index 94ac78d..f3a13ce 100644 --- a/postgresql-libpq.cabal +++ b/postgresql-libpq.cabal @@ -1,7 +1,6 @@ cabal-version: 2.4 name: postgresql-libpq -version: 0.10.0.0 -x-revision: 1 +version: 0.10.1.0 synopsis: low-level binding to libpq description: This is a binding to libpq: the C application @@ -31,8 +30,8 @@ tested-with: || ==9.0.2 || ==9.2.8 || ==9.4.8 - || ==9.6.3 - || ==9.8.1 + || ==9.6.5 + || ==9.8.2 extra-source-files: CHANGELOG.md @@ -115,6 +114,8 @@ test-suite smoke , base , bytestring , postgresql-libpq + , tasty ^>=1.5 + , tasty-hunit ^>=0.10.1 source-repository head type: git diff --git a/test/Smoke.hs b/test/Smoke.hs index 1802d4c..29ed9c6 100644 --- a/test/Smoke.hs +++ b/test/Smoke.hs @@ -1,6 +1,8 @@ module Main (main) where import Control.Monad (unless) +import Test.Tasty (defaultMain, testGroup) +import Test.Tasty.HUnit (testCaseSteps, assertEqual) import Database.PostgreSQL.LibPQ import Data.Foldable (toList) import System.Environment (getEnvironment) @@ -11,7 +13,9 @@ import qualified Data.ByteString.Char8 as BS8 main :: IO () main = do libpqVersion >>= print - withConnstring smoke + withConnstring $ \connString -> defaultMain $ testGroup "postgresql-libpq" + [ testCaseSteps "smoke" $ \info -> smoke info connString + ] withConnstring :: (BS8.ByteString -> IO ()) -> IO () withConnstring kont = do @@ -35,21 +39,23 @@ withConnstring kont = do , "port=5432" ] -smoke :: BS8.ByteString -> IO () -smoke connstring = do +smoke :: (String -> IO ()) -> BS8.ByteString -> IO () +smoke info connstring = do + let infoShow x = info (show x) + conn <- connectdb connstring -- status functions - db conn >>= print - user conn >>= print - host conn >>= print - port conn >>= print - status conn >>= print - transactionStatus conn >>= print - protocolVersion conn >>= print - serverVersion conn >>= print + db conn >>= infoShow + user conn >>= infoShow + host conn >>= infoShow + port conn >>= infoShow + status conn >>= infoShow + transactionStatus conn >>= infoShow + protocolVersion conn >>= infoShow + serverVersion conn >>= infoShow s <- status conn - unless (s == ConnectionOk) exitFailure + assertEqual "connection not ok" s ConnectionOk finish conn