2016-07-26 01:37:06 +02:00
|
|
|
{-# LANGUAGE OverloadedStrings #-}
|
|
|
|
|
|
|
|
module GeneratedTests where
|
|
|
|
|
|
|
|
import Test.Tasty
|
|
|
|
import Test.Tasty.HUnit (testCase, (@?=))
|
|
|
|
|
|
|
|
import Data.String
|
|
|
|
import Data.Protobuf.Wire.DotProto.Generate
|
|
|
|
import qualified Data.Text as T
|
|
|
|
|
|
|
|
import Turtle
|
|
|
|
|
|
|
|
generatedTests :: TestTree
|
|
|
|
generatedTests = testGroup "Code generator tests"
|
2016-08-13 00:48:28 +02:00
|
|
|
[ testServerGeneration
|
|
|
|
, testClientGeneration ]
|
2016-07-26 01:37:06 +02:00
|
|
|
|
|
|
|
testServerGeneration :: TestTree
|
|
|
|
testServerGeneration = testCase "server generation" $ do
|
|
|
|
mktree hsTmpDir
|
|
|
|
mktree pyTmpDir
|
|
|
|
|
|
|
|
compileSimpleDotProto
|
|
|
|
|
2016-08-05 18:29:20 +02:00
|
|
|
exitCode <- proc "tests/simple-server.sh" [hsTmpDir] empty
|
2016-07-26 01:37:06 +02:00
|
|
|
exitCode @?= ExitSuccess
|
|
|
|
|
2016-08-05 18:29:20 +02:00
|
|
|
exitCode <- proc "tests/protoc.sh" [pyTmpDir] empty
|
2016-07-26 01:37:06 +02:00
|
|
|
exitCode @?= ExitSuccess
|
|
|
|
|
|
|
|
runManaged $ do
|
|
|
|
serverExitCodeA <- fork (shell (hsTmpDir <> "/simple-server") empty)
|
|
|
|
clientExitCodeA <- fork
|
|
|
|
(export "PYTHONPATH" pyTmpDir >> shell "python tests/test-client.py" empty)
|
|
|
|
|
|
|
|
liftIO $ do
|
|
|
|
serverExitCode <- liftIO (wait serverExitCodeA)
|
|
|
|
clientExitCode <- liftIO (wait clientExitCodeA)
|
|
|
|
|
|
|
|
serverExitCode @?= ExitSuccess
|
|
|
|
clientExitCode @?= ExitSuccess
|
|
|
|
|
|
|
|
rmtree hsTmpDir
|
|
|
|
rmtree pyTmpDir
|
|
|
|
|
2016-08-13 00:48:28 +02:00
|
|
|
testClientGeneration :: TestTree
|
|
|
|
testClientGeneration = testCase "client generation" $ do
|
|
|
|
mktree hsTmpDir
|
|
|
|
mktree pyTmpDir
|
|
|
|
|
|
|
|
compileSimpleDotProto
|
|
|
|
|
|
|
|
exitCode <- proc "tests/simple-client.sh" [hsTmpDir] empty
|
|
|
|
exitCode @?= ExitSuccess
|
|
|
|
|
|
|
|
exitCode <- proc "tests/protoc.sh" [pyTmpDir] empty
|
|
|
|
exitCode @?= ExitSuccess
|
|
|
|
|
|
|
|
runManaged $ do
|
|
|
|
serverExitCodeA <- fork
|
|
|
|
(export "PYTHONPATH" pyTmpDir >> shell "python tests/test-server.py" empty)
|
|
|
|
clientExitCodeA <- fork (shell (hsTmpDir <> "/simple-client") empty)
|
|
|
|
|
|
|
|
liftIO $ do
|
|
|
|
serverExitCode <- liftIO (wait serverExitCodeA)
|
|
|
|
clientExitCode <- liftIO (wait clientExitCodeA)
|
|
|
|
|
|
|
|
serverExitCode @?= ExitSuccess
|
|
|
|
clientExitCode @?= ExitSuccess
|
|
|
|
|
|
|
|
rmtree hsTmpDir
|
|
|
|
rmtree pyTmpDir
|
|
|
|
|
2016-07-26 01:37:06 +02:00
|
|
|
hsTmpDir, pyTmpDir :: IsString a => a
|
|
|
|
hsTmpDir = "tests/tmp"
|
|
|
|
pyTmpDir = "tests/py-tmp"
|
|
|
|
|
|
|
|
compileSimpleDotProto :: IO ()
|
|
|
|
compileSimpleDotProto =
|
|
|
|
do dpRes <- readDotProtoWithContext "tests/simple.proto"
|
|
|
|
case dpRes of
|
|
|
|
Left err -> fail (show err)
|
|
|
|
Right (dp, ctxt) ->
|
|
|
|
case renderHsModuleForDotProto dp ctxt of
|
|
|
|
Left err -> fail ("compileSimpleDotProto: Error compiling test.proto: " <> show err)
|
|
|
|
Right hsSrc -> writeFile (hsTmpDir ++ "/Simple.hs") hsSrc
|