servant/servant-client/test/Servant/Client/TestServer/GHCJS.hs

35 lines
1.1 KiB
Haskell
Raw Normal View History

2015-11-25 10:31:58 +01:00
module Servant.Client.TestServer.GHCJS where
import Control.Exception
import Safe
import System.Exit
import System.IO
import System.Process
2016-01-04 17:59:28 +01:00
import Servant.Client.TestServer.Types
2015-11-25 10:31:58 +01:00
import Servant.Common.BaseUrl
buildTestServer :: IO ()
buildTestServer = do
process <- spawnProcess "./test/ghcjs/build-test-server.sh" []
ExitSuccess <- waitForProcess process
return ()
2016-01-04 19:04:10 +01:00
withServer :: TestServer -> (BaseUrl -> IO a) -> IO a
withServer (TestServer testServerName _) action = do
2015-11-25 10:31:58 +01:00
bracket start stop $ \ (port, _) -> action (BaseUrl Http "localhost" port ("/" ++ testServerName))
where
start :: IO (Int, ProcessHandle)
start = do
(Nothing, Just stdout, Nothing, process) <- createProcess $ (proc "./test/ghcjs/testServer" []) {
std_out = CreatePipe
}
line <- hGetLine stdout
case readMay line :: Maybe Int of
2016-04-06 10:58:44 +02:00
Nothing -> die ("unparseable port: " ++ show line)
2015-11-25 10:31:58 +01:00
Just port -> return (port, process)
stop (_, process) = do
terminateProcess process
waitForProcess process