@@ -3,11 +3,14 @@ import Test.HUnit
3import System.Exit
3import System.Exit
4import ProjectM36.Relation
4import ProjectM36.Relation
5import qualified ProjectM36.Client as C
5import qualified ProjectM36.Client as C
6+import ProjectM36.DateExamples
7+import ProjectM36.DatabaseContext
6import System.IO.Temp
8import System.IO.Temp
7import System.FilePath
9import System.FilePath
8import ProjectM36.TupleSet
10import ProjectM36.TupleSet
9import ProjectM36.Attribute
11import ProjectM36.Attribute
10import qualified Data.Vector as V
12import qualified Data.Vector as V
13+import qualified Data.Map as M
12main :: IO ()
15main :: IO ()
@@ -15,7 +18,7 @@ main = do
15 if errors tcounts + failures tcounts > 0 then exitFailure else exitSuccess
18 if errors tcounts + failures tcounts > 0 then exitFailure else exitSuccess
17testList :: Test
20testList :: Test
18−testList = TestList [testSimpleCommitSuccess, testSimpleCommitFailure]
21+testList = TestList [testSimpleCommitSuccess, testSimpleCommitFailure, testSimpleUpdate]
20assertEither :: (Show a) => IO (Either a b) -> IO b
23assertEither :: (Show a) => IO (Either a b) -> IO b
21assertEither x = do
24assertEither x = do
@@ -45,6 +48,7 @@ testSimpleCommitSuccess = TestCase $
45 eRes <- C.executeRelationalExpr sess conn relExpr
48 eRes <- C.executeRelationalExpr sess conn relExpr
46 assertEqual "x and y" (Right relationTrue) eRes
49 assertEqual "x and y" (Right relationTrue) eRes
48testSimpleCommitFailure :: Test
52testSimpleCommitFailure :: Test
49testSimpleCommitFailure = TestCase $ do
53testSimpleCommitFailure = TestCase $ do
50 let failAttrs = attributesFromList [Attribute "fail" IntAtomType]
54 let failAttrs = attributesFromList [Attribute "fail" IntAtomType]
@@ -57,11 +61,13 @@ testSimpleCommitFailure = TestCase $ do
57 execute $ Assign "x" (MakeStaticRelation failAttrs emptyTupleSet)
61 execute $ Assign "x" (MakeStaticRelation failAttrs emptyTupleSet)
58 let expectedErr = Left (RelError (RelationTypeMismatchError V.empty failAttrs))
62 let expectedErr = Left (RelError (RelationTypeMismatchError V.empty failAttrs))
59 assertEqual "dbc error" expectedErr err
63 assertEqual "dbc error" expectedErr err
64−
65+-- #176 default merge couldn't handle Update
65−
66+testSimpleUpdate :: Test
66−
67+testSimpleUpdate = TestCase $ do
67−
68+ let connInfo = InProcessConnectionInfo NoPersistence emptyNotificationCallback []
69+ dbconn <- assertEither (simpleConnectProjectM36 connInfo)
70+ assertEither $ withTransaction dbconn $
71+ execute $ databaseContextAsDatabaseContextExpr dateExamples
72+ assertEither $ withTransaction dbconn $
73+ execute $ Update "s" (M.singleton "sname" (C.NakedAtomExpr (C.TextAtom "Blakey"))) (C.AttributeEqualityPredicate "sname" (C.NakedAtomExpr (C.TextAtom "Blake")))