@@ -40,10 +40,10 @@ main = do
4040 withSystemTempDirectory "blank-project" $ \blankProject ->
4141 hspec $ do
4242 let shelly_ = void . shelly . silently
43− describe "ob init" $ do
44− let inTmp :: (Shelly.FilePath -> Sh a) -> IO ()
45− inTmp f = shelly_ . withSystemTempDirectory "ob-init" $ (chdir <*> f) . fromString
43+ inTmp :: (Shelly.FilePath -> Sh a) -> IO ()
44+ inTmp f = shelly_ . withSystemTempDirectory "ob-init" $ (chdir <*> f) . fromString
4645
46+ describe "ob init" $ do
4747 it "works with default impl" $ inTmp $ \_ -> run "ob" ["init"]
4848 it "works with master branch impl" $ inTmp $ \_ -> run "ob" ["init", "--branch", "master"]
4949 it "works with symlink" $ inTmp $ \_ -> run "ob" ["init", "--symlink", obeliskImpl]
@@ -52,6 +52,14 @@ main = do
5252 errExit False $ run "ob" ["init", "--symlink", "/dev/null"]
5353 ls tmp >>= liftIO . assertEqual "" []
5454
55+ describe "ob run" $ do
56+ it "works in root directory" $ inTmp $ \_ -> do
57+ run "ob" ["init"]
58+ testObRunInDir Nothing httpManager
59+ it "works in sub directory" $ inTmp $ \_ -> do
60+ run "ob" ["init"]
61+ testObRunInDir (Just "frontend") httpManager
62+
5563 describe "obelisk project" $ parallel $ do
5664 it "can build obelisk command" $ shelly_ $ run "nix-build" ["-A", "command" , obeliskImpl]
5765 it "can build obelisk skeleton" $ shelly_ $ run "nix-build" ["-A", "skeleton", obeliskImpl]
@@ -138,21 +146,18 @@ main = do
138146 unpack
139147 testThunkPack (blankProject </> thunk)
140148
141− describe "ob run" $ do
142− it "works in root directory" $ inProj $ testObRun httpManager
143− it "works in sub directory" $ inProj $ chdir "frontend" $ testObRun httpManager
144−
145−testObRun :: HTTP.Manager -> Sh ()
146−testObRun httpManager = handle_sh (\case ExitSuccess -> pure (); e -> throw e) $ do
149+-- | Run `ob run` in the given directory (maximum of one level deep)
150+testObRunInDir :: Maybe Shelly.FilePath -> HTTP.Manager -> Sh ()
151+testObRunInDir mdir httpManager = handle_sh (\case ExitSuccess -> pure (); e -> throw e) $ do
147152 let uri p = "http://localhost:" <> T.pack (show p) <> "/" -- trailing slash required for comparison
148153 writefile "config/common/route" . uri =<< liftIO getFreePort -- Use a free port initially
149− runHandle "ob" ["run"] $ \stdout -> do
154+ maybe id chdir mdir $ runHandle "ob" ["run"] $ \stdout -> do
150155 freePort <- liftIO getFreePort
151156 (_, firstUri) <- handleObRunStdout httpManager stdout
152157 let newUri = uri freePort
153158 when (firstUri == newUri) $ errorExit $
154159 "Startup URI (" <> firstUri <> ") is the same as test URI (" <> newUri <> ")"
155− alterRouteTo newUri stdout
160+ maybe id (\_ -> chdir "..") mdir $ alterRouteTo newUri stdout
156161 (_, runningUri) <- handleObRunStdout httpManager stdout
157162 if runningUri /= newUri
158163 then errorExit $ "Reloading failed: expected " <> newUri <> " but got " <> runningUri