Skip to content

Commit e8341ef

Browse files
committed
Require a psql test arg to run tests
Without this the stackage and nix tests will fail as they will not have a test psql instance for these tests.
1 parent 7db356a commit e8341ef

File tree

5 files changed

+40
-12
lines changed

5 files changed

+40
-12
lines changed

.github/workflows/haskell-ci.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ jobs:
204204
205205
- name: tests
206206
run: |
207-
PGPASSWORD=test PGDATABASE=test PGUSER=test $CABAL v2-test $ARG_COMPILER $ARG_TESTS $ARG_BENCH all --test-show-details=direct
207+
PGPASSWORD=test PGDATABASE=test PGUSER=test $CABAL run $ARG_COMPILER $ARG_TESTS $ARG_BENCH --test-show-details=direct test:tests psql
208208
209209
- name: cabal check
210210
run: |

Makefile

+7
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ stack-ghcid:
3131
stack-ghcid-quiet:
3232
$(stack) exec -- ghcid -c "stack ghci $(package):lib --ghci-options='-ignore-dot-ghci -fobject-code -fno-warn-unused-do-bind -fno-warn-unused-matches -fno-warn-unused-local-binds -fno-warn-unused-imports -j6 +RTS -A128m -n2m -qg' --main-is $(package):exe:$(exe)"
3333

34+
stack-test:
35+
$(stack) test --ta "psql"
36+
37+
3438

3539
cabal-run:
3640
cabal run $(exe)
@@ -44,5 +48,8 @@ cabal-build-fast:
4448
cabal-ghcid:
4549
ghcid --lint -c "cabal repl --repl-options='-ignore-dot-ghci' --repl-options='-fobject-code' --repl-options='-fno-warn-unused-do-bind' --repl-options='-j6' "
4650

51+
cabal-test:
52+
cabal run --test-show-details=direct test:tests psql
53+
4754

4855
.PHONY : stack-build stack-build-dirty stack-run stack-ghci stack-ghcid stack-check-nightly cabal-ghcid cabal-build cabal-run cabal-build-fast

Readme.markdown

+10-4
Original file line numberDiff line numberDiff line change
@@ -158,11 +158,14 @@ The following command builds the library, the standalone binary and the test pac
158158
cabal configure --enable-tests && cabal build -j
159159
```
160160

161-
To execute the tests, you need a running PostgreSQL server with an empty
162-
database called _test_. Tests are executed through cabal as follows:
161+
To execute the tests, you need a running PostgreSQL server. You need to set the correct
162+
environment varaiables for the psql connection.
163+
164+
Tests are executed through cabal as follows:
163165

164166
```bash
165-
cabal configure --enable-tests && cabal test
167+
cabal configure --enable-tests
168+
PGHOST=localhost PGDATABASE=test make-cabal test
166169
```
167170

168171
To build with stack use the following command
@@ -174,9 +177,12 @@ stack build
174177
To run the tests with stack use the following command
175178

176179
```bash
177-
stack test
180+
PGHOST=localhost PGDATABASE=test make stack-test
178181
```
179182

183+
NB note that the **psql** test argument must be set for the test suite to run. This is so that other CI environments like
184+
stackage or nix that wont have a running test psql instance will not fail on these tests
185+
180186

181187
# Changes from the original postgresql-simple-migration (version 0.1)
182188

postgresql-migration.cabal

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
cabal-version: 3.0
22
name: postgresql-migration
3-
version: 0.2.1.2
3+
version: 0.2.1.3
44
synopsis: PostgreSQL Schema Migrations
55
homepage: https://github.com/andrevdm/postgresql-migration
66
Bug-reports: https://github.com/andrevdm/postgresql-migration/issues

test/Main.hs

+21-6
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
-- The test entry-point for postgresql-migration.
1111

1212
{-# LANGUAGE OverloadedStrings #-}
13+
{-# LANGUAGE LambdaCase #-}
1314

1415
module Main
1516
( main
@@ -21,14 +22,28 @@ import qualified Database.PostgreSQL.Simple.MigrationTest as V2
2122
import qualified Database.PostgreSQL.Simple.TransactionPerRunTest as V2TrnRun
2223
import qualified Database.PostgreSQL.Simple.TransactionPerStepTest as V2TrnStep
2324
import Database.PostgreSQL.Simple.Util (withTransactionRolledBack)
25+
import qualified System.Environment as Env
26+
2427
import Test.Hspec (hspec)
2528

2629
main :: IO ()
2730
main = do
28-
conRollback <- connectPostgreSQL ""
29-
withTransactionRolledBack conRollback (hspec (V2.migrationSpec conRollback))
30-
withTransactionRolledBack conRollback (hspec (V1.migrationSpec conRollback))
31-
withTransactionRolledBack conRollback (hspec (V2TrnRun.migrationSpec conRollback))
31+
Env.getArgs >>= \case
32+
("psql":as) -> Env.withArgs as $ do
33+
conRollback <- connectPostgreSQL ""
34+
withTransactionRolledBack conRollback (hspec (V2.migrationSpec conRollback))
35+
withTransactionRolledBack conRollback (hspec (V1.migrationSpec conRollback))
36+
withTransactionRolledBack conRollback (hspec (V2TrnRun.migrationSpec conRollback))
37+
38+
conPerStep <- connectPostgreSQL ""
39+
hspec (V2TrnStep.migrationSpec conPerStep)
40+
41+
_ -> do
42+
putStrLn "Skipping tests, no 'psql' argument provided"
43+
putStrLn " To run the tests please use one of the following make commands"
44+
putStrLn " make cabal-test"
45+
putStrLn " make stack-test"
46+
putStrLn " or directly"
47+
putStrLn " stack test --ta psql"
48+
putStrLn " cabal run --test-show-details=direct test:tests psql"
3249

33-
conPerStep <- connectPostgreSQL ""
34-
hspec (V2TrnStep.migrationSpec conPerStep)

0 commit comments

Comments
 (0)