on master help sign in
Merge pull request #10 from tomsmalley/tom-devel

Add devel to improve ob run error messages

commit68f0725a29eadb8583b1a7db05ce65835a172887 authorLuigy Leon <luichi.19@gmail.com> dateFri 25 May 2018, 13:50 (8 years ago) parentc14b3e388ba801
3 files changed+30−16
lib/command/src/Obelisk/Command/Run.hs+2−3 lib/selftest/src/Obelisk/SelfTest.hs+18−13 skeleton/devel/Devel.hs+10
lib/command/src/Obelisk/Command/Run.hs+2−3
@@ -35,7 +35,7 @@ run = do
3535 pkgs <- getLocalPkgs
3636 withGhciScript pkgs $ \dotGhciPath -> do
3737 freePort <- getFreePort
38− runGhcid dotGhciPath $ Just $ unwords ["Obelisk.Run.run", show freePort, "backend", "frontend"]
38+ runGhcid dotGhciPath $ Just $ unwords ["main", show freePort]
3939
4040runRepl :: MonadObelisk m => m ()
4141runRepl = do
@@ -89,8 +89,7 @@ withGhciScript pkgs f = do
8989
9090 let dotGhci = unlines
9191 [ ":set -i" <> intercalate ":" (mconcat hsSrcDirs)
92− , ":add Backend Frontend"
93− , ":module + Obelisk.Run Frontend Backend"
92+ , ":load ./devel/Devel.hs" -- TODO more robust filepath
9493 ]
9594 withSystemTempDirectory "ob-ghci" $ \fp -> do
9695 let dotGhciPath = fp </> ".ghci"
lib/selftest/src/Obelisk/SelfTest.hs+18−13
@@ -137,17 +137,22 @@ main = do
137137 unpack
138138 testThunkPack (blankProject </> thunk)
139139
140− it "can use ob run" $ inProj $ handle_sh (\case ExitSuccess -> pure (); e -> throw e) $ do
141− runHandle "ob" ["run"] $ \stdout -> do
142− (_, firstUri) <- obRun httpManager stdout
143− let newUri = "http://localhost:8080/" -- trailing slash required for comparison
144− when (firstUri == newUri) $ errorExit $
145− "Default URI (" <> firstUri <> ") is the same as test URI (" <> newUri <> ")"
146− alterRouteTo newUri stdout
147− (_, runningUri) <- obRun httpManager stdout
148− if runningUri /= newUri
149− then errorExit $ "Reloading failed: expected " <> newUri <> " but got " <> runningUri
150− else exit 0
140+ describe "ob run" $ do
141+ it "works in root directory" $ inProj $ testObRun httpManager
142+ it "works in sub directory" $ inProj $ chdir "frontend" $ testObRun httpManager
143+
144+testObRun :: HTTP.Manager -> Sh ()
145+testObRun httpManager = handle_sh (\case ExitSuccess -> pure (); e -> throw e) $ do
146+ runHandle "ob" ["run"] $ \stdout -> do
147+ (_, firstUri) <- handleObRunStdout httpManager stdout
148+ let newUri = "http://localhost:8080/" -- trailing slash required for comparison
149+ when (firstUri == newUri) $ errorExit $
150+ "Default URI (" <> firstUri <> ") is the same as test URI (" <> newUri <> ")"
151+ alterRouteTo newUri stdout
152+ (_, runningUri) <- handleObRunStdout httpManager stdout
153+ if runningUri /= newUri
154+ then errorExit $ "Reloading failed: expected " <> newUri <> " but got " <> runningUri
155+ else exit 0
151156
152157testThunkPack :: Shelly.FilePath -> Sh ()
153158testThunkPack path = withTempFile (T.unpack $ toTextIgnore path) "test-file" $ \file handle -> do
@@ -193,8 +198,8 @@ alterRouteTo uri stdout = do
193198 "Reloading failed: " <> T.pack (show t)
194199
195200-- | Handle stdout of `ob run`: check that the frontend and backend servers are started correctly
196−obRun :: HTTP.Manager -> Handle -> Sh (Text, Text)
197−obRun httpManager stdout = flip fix ObRunState_Init $ \loop state -> do
201+handleObRunStdout :: HTTP.Manager -> Handle -> Sh (Text, Text)
202+handleObRunStdout httpManager stdout = flip fix ObRunState_Init $ \loop state -> do
198203 liftIO (T.hGetLine stdout) >>= \t -> case state of
199204 ObRunState_Init
200205 | "Running test..." `T.isPrefixOf` t -> loop ObRunState_Startup
skeleton/devel/Devel.hsnew file+10
@@ -0,0 +1,10 @@
1+module Devel where
2+
3+import Obelisk.Run
4+
5+import Backend
6+import Frontend
7+
8+main :: Int -> IO ()
9+main port = run port backend frontend
10+