Skip to content

Commit e6d60ed

Browse files
committed
migration (wip)
1 parent 1b54abc commit e6d60ed

4 files changed

Lines changed: 28 additions & 35 deletions

File tree

default.nix

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{ mkDerivation, attoparsec, base, bytestring, case-conversion
2-
, heredoc, HUnit, postgresql-simple, stdenv, template-haskell, text
3-
, time
2+
, heredoc, hspec2, HUnit, postgresql-simple, stdenv
3+
, template-haskell, text, time
44
}:
55
mkDerivation {
66
pname = "postgresql-simple-bind";
@@ -11,8 +11,8 @@ mkDerivation {
1111
template-haskell text time
1212
];
1313
testHaskellDepends = [
14-
attoparsec base bytestring case-conversion HUnit postgresql-simple
15-
text
14+
attoparsec base bytestring case-conversion hspec2 HUnit
15+
postgresql-simple text
1616
];
1717
description = "A FFI-like bindings for PostgreSQL stored functions";
1818
license = stdenv.lib.licenses.gpl3;

postgresql-simple-bind.cabal

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ test-suite tests
6060
build-depends: base >= 4.8 && < 5.0
6161
, bytestring >= 0.10.8 && < 0.11
6262
, HUnit
63+
, hspec2
64+
, hspec-expectations
6365
, postgresql-simple >= 0.5.2 && < 0.6
6466
, postgresql-simple-bind
6567
, text >= 1.2.2 && < 1.3

tests/Main.hs

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,31 @@
11
{-# LANGUAGE OverloadedStrings #-}
22
{-# LANGUAGE NamedFieldPuns #-}
33

4-
import Test.HUnit
5-
import Control.Monad
6-
import System.IO
7-
import System.Exit
4+
import Control.Monad (unless)
5+
-- import Data.WithLocation (WithLocation)
6+
import Test.Hspec
7+
import Test.Hspec.Expectations (expectationFailure)
8+
-- import Test.Hspec.Wai (with)
9+
import Database.PostgreSQL.Simple.Bind.Representation
10+
import Data.Text ()
811

9-
import TestRepresentation
12+
main :: IO ()
13+
main = hspec spec
1014

15+
spec :: Spec
16+
spec = do
17+
describe "simple signatures" $ do
18+
it "works with simple signatures" $ do
19+
(parsePGFunction "function f(x bigint) returns bigint") `shouldBe`
20+
(PGFunction "" "f" [PGArgument "x" "bigint" False] (PGSingle "bigint"))
1121

12-
tests :: [Test]
13-
tests = [
14-
TestLabel "Representation" testRepresentation
15-
]
22+
(parsePGFunction "function g(x bigint, y varchar) returns void") `shouldBe`
23+
(PGFunction "" "g" [PGArgument "x" "bigint" False, PGArgument "y" "varchar" False]
24+
(PGSingle "void"))
1625

17-
main :: IO ()
18-
main = do
19-
mapM_ (`hSetBuffering` LineBuffering) [stdout, stderr]
26+
(parsePGFunction "function h() returns varchar") `shouldBe`
27+
(PGFunction "" "h" [] (PGSingle "varchar"))
2028

21-
Counts {cases, tried, errors, failures} <- runTestTT $ TestList tests
22-
when (cases /= tried || errors /= 0 || failures /= 0) $ exitFailure
29+
(parsePGFunction "FUNCTION H(Z VARCHAR) RETURNS BIGINT") `shouldBe`
30+
(PGFunction "" "h" [PGArgument "z" "varchar" False] (PGSingle "bigint"))
2331

tests/TestRepresentation.hs

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -11,23 +11,6 @@ import Data.Text ()
1111
import TestTypes
1212

1313

14-
simpleTests :: Test
15-
simpleTests = "simple" ~: [
16-
(parsePGFunction "function f(x bigint) returns bigint")
17-
~?= (PGFunction "" "f" [PGArgument "x" "bigint" False] (PGSingle "bigint"))
18-
19-
, (parsePGFunction "function g(x bigint, y varchar) returns void")
20-
~?= (PGFunction "" "g"
21-
[PGArgument "x" "bigint" False, PGArgument "y" "varchar" False ] (PGSingle "void"))
22-
23-
, (parsePGFunction "function h() returns varchar")
24-
~?= (PGFunction "" "h" [] (PGSingle "varchar"))
25-
26-
, (parsePGFunction "FUNCTION H(Z VARCHAR) RETURNS BIGINT")
27-
~?= (PGFunction "" "h" [PGArgument "z" "varchar" False] (PGSingle "bigint"))
28-
]
29-
30-
3114
defaultValuesTests :: Test
3215
defaultValuesTests = "default values" ~: [
3316
(parsePGFunction "function f(x bigint default 0::bigint) returns void")

0 commit comments

Comments
 (0)