on master help sign in
Fix route config for files ending in newline
commitee1c092f4fceca5d250ef8eaf704b748a85e61ed authorTom Smalley <tfsmalley@gmail.com> dateTue 29 May 2018, 16:20 (8 years ago) parent70ac8ef
3 files changed+17−3
lib/run/src/Obelisk/Run.hs+7−3 lib/selftest/obelisk-selftest.cabal+2 lib/selftest/src/Obelisk/SelfTest.hs+8
lib/run/src/Obelisk/Run.hs+7−3
@@ -48,9 +48,13 @@ run port backend frontend = do
4848 runWidget conf frontend `finally` killThread backendTid
4949
5050getConfigRoute :: IO (Maybe URI)
51−getConfigRoute = do
52− mroute <- get "common/route"
53− return $ URI.mkURI =<< mroute
51+getConfigRoute = get "common/route" >>= \case
52+ Just r -> case URI.mkURI $ fromMaybe r $ T.stripSuffix "\n" r of
53+ Just route -> pure $ Just route
54+ Nothing -> do
55+ putStrLn $ "Route is invalid: " <> show r
56+ pure Nothing
57+ Nothing -> pure Nothing
5458
5559defAppUri :: URI
5660defAppUri = fromMaybe (error "defAppUri") $ URI.mkURI "http://127.0.0.1:8000"
lib/selftest/obelisk-selftest.cabal+2
@@ -11,10 +11,12 @@ library
1111 build-depends:
1212 base
1313 , containers
14+ , directory
1415 , hspec
1516 , http-client
1617 , http-types
1718 , HUnit
19+ , obelisk-run
1820 , process
1921 , network
2022 , shelly
lib/selftest/src/Obelisk/SelfTest.hs+8
@@ -7,6 +7,7 @@ import Control.Exception (Exception, throw, bracket)
77import Control.Monad
88import Control.Monad.IO.Class
99import Data.Function (fix)
10+import Data.Maybe (isJust)
1011import Data.Semigroup ((<>))
1112import qualified Data.Set as Set
1213import Data.String
@@ -17,6 +18,7 @@ import qualified Network.HTTP.Client as HTTP
1718import qualified Network.HTTP.Types as HTTP
1819import qualified Network.Socket as Socket
1920import Shelly
21+import System.Directory (withCurrentDirectory)
2022import System.Environment
2123import System.Exit (ExitCode (..))
2224import System.Info
@@ -27,6 +29,8 @@ import Test.Hspec
2729import Test.HUnit.Base
2830import System.Process (readProcessWithExitCode)
2931
32+import Obelisk.Run (getConfigRoute)
33+
3034data ObRunState
3135 = ObRunState_Init
3236 | ObRunState_Startup
@@ -52,6 +56,10 @@ main = do
5256 errExit False $ run "ob" ["init", "--symlink", "/dev/null"]
5357 ls tmp >>= liftIO . assertEqual "" []
5458
59+ it "produces a valid route config" $ inTmp $ \tmp -> do
60+ run "ob" ["init"]
61+ liftIO $ withCurrentDirectory (T.unpack $ toTextIgnore tmp) $ getConfigRoute `shouldNotReturn` Nothing
62+
5563 describe "ob run" $ do
5664 it "works in root directory" $ inTmp $ \_ -> do
5765 run "ob" ["init"]