Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use tasty in test-suite #57

Merged
merged 1 commit into from
Apr 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions postgresql-libpq.cabal
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -115,6 +114,8 @@ test-suite smoke
, base
, bytestring
, postgresql-libpq
, tasty ^>=1.5
, tasty-hunit ^>=0.10.1

source-repository head
type: git
Expand Down
30 changes: 18 additions & 12 deletions test/Smoke.hs
Original file line number Diff line number Diff line change
@@ -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)
Expand All @@ -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
Expand All @@ -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
Loading