on master help sign in
selftest: Lint and style changes
8f961deElliot Cameron
lib/selftest/src/Obelisk/SelfTest.hs+11−16
@@ -3,7 +3,6 @@
3{-# LANGUAGE OverloadedStrings #-}
3{-# LANGUAGE OverloadedStrings #-}
4{-# LANGUAGE PatternGuards #-}
4{-# LANGUAGE PatternGuards #-}
5{-# LANGUAGE ScopedTypeVariables #-}
5{-# LANGUAGE ScopedTypeVariables #-}
6−{-# LANGUAGE TypeApplications #-}
7module Obelisk.SelfTest where
6module Obelisk.SelfTest where
8
7
9import Control.Exception (bracket, throw)
8import Control.Exception (bracket, throw)
@@ -71,7 +70,7 @@ shellyOb f obTest = shelly $ f obTest
71main :: IO ()
70main :: IO ()
72main = do
71main = do
73 -- Note: you can pass hspec arguments as well, eg: `-m <pattern>`
72 -- Note: you can pass hspec arguments as well, eg: `-m <pattern>`
74− isVerbose <- (elem "-v") <$> getArgs
73+ isVerbose <- elem "-v" <$> getArgs
75 unless isVerbose $
74 unless isVerbose $
76 putStrLn "Tests may take longer to run if there are unbuilt derivations: use -v for verbose output"
75 putStrLn "Tests may take longer to run if there are unbuilt derivations: use -v for verbose output"
77 let verbosity = bool silently verbosely isVerbose
76 let verbosity = bool silently verbosely isVerbose
@@ -118,7 +117,7 @@ main = do
118 it "works with master branch impl" $ inTmp $ \_ -> run "ob" ["init", "--branch", "master"]
117 it "works with master branch impl" $ inTmp $ \_ -> run "ob" ["init", "--branch", "master"]
119 it "works with symlink" $ inTmp $ \_ -> run "ob" ["init", "--symlink", obeliskImpl]
118 it "works with symlink" $ inTmp $ \_ -> run "ob" ["init", "--symlink", obeliskImpl]
120 it "doesn't silently overwrite existing files" $ withSystemTempDirectory "ob-init" $ \dir -> do
119 it "doesn't silently overwrite existing files" $ withSystemTempDirectory "ob-init" $ \dir -> do
121− let p force = (proc "ob" $ "--no-handoff" : "init" : if force then ["--force"] else []) { cwd = Just dir }
120+ let p force = (proc "ob" $ "--no-handoff" : "init" : ["--force"|force]) { cwd = Just dir }
122 (ExitSuccess, _, _) <- readCreateProcessWithExitCode (p False) ""
121 (ExitSuccess, _, _) <- readCreateProcessWithExitCode (p False) ""
123 (ExitFailure _, _, _) <- readCreateProcessWithExitCode (p False) ""
122 (ExitFailure _, _, _) <- readCreateProcessWithExitCode (p False) ""
124 (ExitSuccess, _, _) <- readCreateProcessWithExitCode (p True) ""
123 (ExitSuccess, _, _) <- readCreateProcessWithExitCode (p True) ""
@@ -128,7 +127,7 @@ main = do
128 void $ errExit False $ run "ob" ["init", "--symlink", "/dev/null"]
127 void $ errExit False $ run "ob" ["init", "--symlink", "/dev/null"]
129 ls tmp >>= liftIO . assertEqual "" []
128 ls tmp >>= liftIO . assertEqual "" []
130
129
131− it "produces a valid route config" $ inTmpObInit $ \tmp -> liftIO $ do
130+ it "produces a valid route config" $ inTmpObInit $ \tmp -> liftIO $
132 withCurrentDirectory (T.unpack $ toTextIgnore tmp) $ do
131 withCurrentDirectory (T.unpack $ toTextIgnore tmp) $ do
133 configs <- getConfigs
132 configs <- getConfigs
134 return (either (const Nothing) Just $ getConfigRoute configs) `shouldNotReturn` Nothing
133 return (either (const Nothing) Just $ getConfigRoute configs) `shouldNotReturn` Nothing
@@ -136,10 +135,8 @@ main = do
136 -- These tests fail with "Could not find module 'Obelisk.Generated.Static'"
135 -- These tests fail with "Could not find module 'Obelisk.Generated.Static'"
137 -- when not run by 'nix-build --attr selftest'
136 -- when not run by 'nix-build --attr selftest'
138 describe "ob run" $ parallel $ do
137 describe "ob run" $ parallel $ do
139− it "works in root directory" $ inTmpObInit $ \_ -> do
140− testObRunInDir p0 p1 Nothing httpManager
138+ it "works in root directory" $ inTmpObInit $ \_ -> testObRunInDir p0 p1 Nothing httpManager
141− it "works in sub directory" $ inTmpObInit $ \_ -> do
142− testObRunInDir p2 p3 (Just "frontend") httpManager
139+ it "works in sub directory" $ inTmpObInit $ \_ -> testObRunInDir p2 p3 (Just "frontend") httpManager
143
140
144 describe "obelisk project" $ parallel $ do
141 describe "obelisk project" $ parallel $ do
145 it "can build obelisk command" $ inTmpObInit $ \_ -> nixBuild ["-A", "command" , obeliskImpl]
142 it "can build obelisk command" $ inTmpObInit $ \_ -> nixBuild ["-A", "command" , obeliskImpl]
@@ -149,13 +146,11 @@ main = do
149
146
150 describe "blank initialized project" $ parallel $ do
147 describe "blank initialized project" $ parallel $ do
151
148
152− it "can build ghc.backend" $ inTmpObInit $ \_ -> do
149+ it "can build ghc.backend" $ inTmpObInit $ \_ -> nixBuild ["-A", "ghc.backend"]
153− nixBuild ["-A", "ghc.backend"]
154− it "can build ghcjs.frontend" $ inTmpObInit $ \_ -> do
150+ it "can build ghcjs.frontend" $ inTmpObInit $ \_ -> nixBuild ["-A", "ghcjs.frontend"]
155− nixBuild ["-A", "ghcjs.frontend"]
156
151
157 if os == "darwin"
152 if os == "darwin"
158− then it "can build ios" $ inTmpObInit $ \_ -> nixBuild ["-A", "ios.frontend"]
153+ then it "can build ios" $ inTmpObInit $ \_ -> nixBuild ["-A", "ios.frontend"]
159 else it "can build android" $ inTmpObInit $ \_ -> nixBuild ["-A", "android.frontend"]
154 else it "can build android" $ inTmpObInit $ \_ -> nixBuild ["-A", "android.frontend"]
160
155
161 forM_ ["ghc", "ghcjs"] $ \compiler -> do
156 forM_ ["ghc", "ghcjs"] $ \compiler -> do
@@ -191,7 +186,7 @@ main = do
191 branch' <- chdir dir $ run "git" ["rev-parse", "--abbrev-ref", "HEAD"]
186 branch' <- chdir dir $ run "git" ["rev-parse", "--abbrev-ref", "HEAD"]
192 liftIO $ assertEqual "" branch (T.strip branch')
187 liftIO $ assertEqual "" branch (T.strip branch')
193
188
194− it "can pack and unpack plain git repos" $ do
189+ it "can pack and unpack plain git repos" $
195 shelly_ $ withSystemTempDirectory "git-repo" $ \dir -> do
190 shelly_ $ withSystemTempDirectory "git-repo" $ \dir -> do
196 let repo = toTextIgnore $ dir </> ("repo" :: String)
191 let repo = toTextIgnore $ dir </> ("repo" :: String)
197 run_ "git" ["clone", "https://github.com/haskell/process.git", repo]
192 run_ "git" ["clone", "https://github.com/haskell/process.git", repo]
@@ -210,7 +205,7 @@ main = do
210 testThunkPack $ fromText repo
205 testThunkPack $ fromText repo
211
206
212 it "aborts thunk pack when there are uncommitted files" $ inTmpObInit $ \dir -> do
207 it "aborts thunk pack when there are uncommitted files" $ inTmpObInit $ \dir -> do
213− void $ unpack
208+ void unpack
214 testThunkPack (dir </> thunk)
209 testThunkPack (dir </> thunk)
215
210
216 describe "ob thunk update --branch" $ parallel $ do
211 describe "ob thunk update --branch" $ parallel $ do
@@ -289,7 +284,7 @@ alterRouteTo uri stdout = do
289
284
290-- | Handle stdout of `ob run`: check that the frontend and backend servers are started correctly
285-- | Handle stdout of `ob run`: check that the frontend and backend servers are started correctly
291handleObRunStdout :: HTTP.Manager -> Handle -> Sh Text
286handleObRunStdout :: HTTP.Manager -> Handle -> Sh Text
292−handleObRunStdout httpManager stdout = flip fix (ObRunState_Init, []) $ \loop (state, msgs) -> do
287+handleObRunStdout httpManager stdout = flip fix (ObRunState_Init, []) $ \loop (state, msgs) ->
293 liftIO (T.hGetLine stdout) >>= \t -> case state of
288 liftIO (T.hGetLine stdout) >>= \t -> case state of
294 ObRunState_Init
289 ObRunState_Init
295 | "Running test..." `T.isPrefixOf` t -> loop (ObRunState_BackendStarted, msgs)
290 | "Running test..." `T.isPrefixOf` t -> loop (ObRunState_BackendStarted, msgs)