on master help sign in
Merge pull request #260 from obsidiansystems/ts-tests

Test updates

commita0fc29ce9f7715bfe69497b07f87aa280580ab8f authorLuigy Leon <luichi.19@gmail.com> dateMon 22 Oct 2018, 14:35 (8 years ago) parentc7a224dcea88b7
1 file changed+34−32
lib/selftest/src/Obelisk/SelfTest.hs+34−32
lib/selftest/src/Obelisk/SelfTest.hs+34−32
@@ -90,15 +90,20 @@ main = do
9090 let verbosity = bool silently verbosely isVerbose
9191 obeliskImpl <- fromString <$> getEnv "OBELISK_IMPL"
9292 httpManager <- HTTP.newManager HTTP.defaultManagerSettings
93− withSystemTempDirectory "blank-project" $ \blankProject ->
93+ withSystemTempDirectory "initCache" $ \initCache -> do
94+ -- Setup the ob init cache
95+ void . shellyOb verbosity $ chdir (fromString initCache) $ do
96+ run_ "ob" ["init"]
97+ run_ "git" ["init"]
9498 hspec $ do
9599 let shelly_ = void . shellyOb verbosity
96100
97− inProj :: Sh a -> IO ()
98− inProj = shelly_ . chdir (fromString blankProject)
99−
100101 inTmp :: (Shelly.FilePath -> Sh a) -> IO ()
101− inTmp f = shelly_ . withSystemTempDirectory "ob-init" $ (chdir <*> f) . fromString
102+ inTmp f = shelly_ . withSystemTempDirectory "test" $ (chdir <*> f) . fromString
103+
104+ inTmpObInit f = inTmp $ \dir -> do
105+ run_ "cp" ["-a", fromString $ initCache <> "/.", toTextIgnore dir]
106+ f dir
102107
103108 assertRevEQ a b = liftIO . assertEqual "" "" =<< diff a b
104109 assertRevNE a b = liftIO . assertBool "" . (/= "") =<< diff a b
@@ -132,19 +137,18 @@ main = do
132137 void $ errExit False $ run "ob" ["init", "--symlink", "/dev/null"]
133138 ls tmp >>= liftIO . assertEqual "" []
134139
135− it "produces a valid route config" $ inTmp $ \tmp -> do
136− run_ "ob" ["init"]
140+ it "produces a valid route config" $ inTmpObInit $ \tmp -> do
137141 liftIO $ withCurrentDirectory (T.unpack $ toTextIgnore tmp) $ getConfigRoute `shouldNotReturn` Nothing
138142
143+ -- These tests fail with "Could not find module 'Obelisk.Generated.Static'"
144+ -- when not run by 'nix-build --attr selftest'
139145 describe "ob run" $ do
140− it "works in root directory" $ inTmp $ \_ -> do
141− run_ "ob" ["init"]
146+ it "works in root directory" $ inTmpObInit $ \_ -> do
142147 testObRunInDir Nothing httpManager
143− it "works in sub directory" $ inTmp $ \_ -> do
144− run_ "ob" ["init"]
148+ it "works in sub directory" $ inTmpObInit $ \_ -> do
145149 testObRunInDir (Just "frontend") httpManager
146150
147− describe "obelisk project" $ parallel $ do
151+ describe "obelisk project" $ do
148152 it "can build obelisk command" $ shelly_ $ run "nix-build" ["-A", "command" , obeliskImpl]
149153 it "can build obelisk skeleton" $ shelly_ $ run "nix-build" ["-A", "skeleton", obeliskImpl]
150154 it "can build obelisk shell" $ shelly_ $ run "nix-build" ["-A", "shell", obeliskImpl]
@@ -152,37 +156,34 @@ main = do
152156 -- it "can build everything" $ shelly_ $ run "nix-build" [obeliskImpl]
153157
154158 describe "blank initialized project" $ do
155− it "can be created" $ inProj $ do
156− run_ "ob" ["init"]
157− run_ "git" ["init"]
158− commitAll
159159
160− it "can build ghc.backend" $ inProj $ do
160+ it "can build ghc.backend" $ inTmpObInit $ \_ -> do
161161 run "nix-build" ["--no-out-link", "-A", "ghc.backend"]
162− it "can build ghcjs.frontend" $ inProj $ do
162+ it "can build ghcjs.frontend" $ inTmpObInit $ \_ -> do
163163 run "nix-build" ["--no-out-link", "-A", "ghcjs.frontend"]
164164
165165 if os == "darwin"
166− then it "can build ios" $ inProj $ run "nix-build" ["--no-out-link", "-A", "ios.frontend" ]
167− else it "can build android" $ inProj $ run "nix-build" ["--no-out-link", "-A", "android.frontend"]
166+ then it "can build ios" $ inTmpObInit $ \_ -> run "nix-build" ["--no-out-link", "-A", "ios.frontend" ]
167+ else it "can build android" $ inTmpObInit $ \_ -> run "nix-build" ["--no-out-link", "-A", "android.frontend"]
168168
169169 forM_ ["ghc", "ghcjs"] $ \compiler -> do
170170 let
171171 shell = "shells." <> compiler
172172 inShell cmd' = run "nix-shell" ["-A", fromString shell, "--run", cmd']
173− it ("can enter " <> shell) $ inProj $ inShell "exit"
174− it ("can build in " <> shell) $ inProj $ inShell $ "cabal new-build --" <> fromString compiler <> " all"
173+ it ("can enter " <> shell) $ inTmpObInit $ \_ -> inShell "exit"
174+ it ("can build in " <> shell) $ inTmpObInit $ \_ -> inShell $ "cabal new-build --" <> fromString compiler <> " all"
175175
176− it "can build reflex project" $ inProj $ do
176+ it "can build reflex project" $ inTmpObInit $ \_ -> do
177177 run "nix-build" []
178178
179− it "has idempotent thunk update" $ inProj $ do
179+ it "has idempotent thunk update" $ inTmpObInit $ \_ -> do
180180 u <- update
181181 uu <- update
182182 assertRevEQ u uu
183183
184184 describe "ob thunk pack/unpack" $ do
185− it "has thunk pack and unpack inverses" $ inProj $ do
185+ it "has thunk pack and unpack inverses" $ inTmpObInit $ \_ -> do
186+
186187 e <- commitAll
187188 eu <- unpack
188189 eup <- pack
@@ -211,9 +212,9 @@ main = do
211212
212213 testThunkPack $ fromText repo
213214
214− it "aborts thunk pack when there are uncommitted files" $ inProj $ do
215+ it "aborts thunk pack when there are uncommitted files" $ inTmpObInit $ \dir -> do
215216 void $ unpack
216− testThunkPack (blankProject </> thunk)
217+ testThunkPack (dir </> thunk)
217218
218219-- | Run `ob run` in the given directory (maximum of one level deep)
219220testObRunInDir :: Maybe Shelly.FilePath -> HTTP.Manager -> Sh ()
@@ -248,7 +249,7 @@ testThunkPack path' = withTempFile (T.unpack $ toTextIgnore path') "test-file" $
248249 ensureThunkPackFails "unsaved"
249250 chdir path' $ commit "test commit"
250251 -- Non-pushed commits in any branch
251− ensureThunkPackFails "not been pushed"
252+ ensureThunkPackFails "not yet pushed"
252253 -- Uncommitted files (unstaged)
253254 liftIO $ T.hPutStrLn handle "test file" >> hClose handle
254255 ensureThunkPackFails "modified"
@@ -275,12 +276,12 @@ alterRouteTo uri stdout = do
275276
276277-- | Handle stdout of `ob run`: check that the frontend and backend servers are started correctly
277278handleObRunStdout :: HTTP.Manager -> Handle -> Sh Text
278−handleObRunStdout httpManager stdout = flip fix ObRunState_Init $ \loop state -> do
279+handleObRunStdout httpManager stdout = flip fix (ObRunState_Init, []) $ \loop (state, msgs) -> do
279280 liftIO (T.hGetLine stdout) >>= \t -> case state of
280281 ObRunState_Init
281− | "Running test..." `T.isPrefixOf` t -> loop ObRunState_BackendStarted
282+ | "Running test..." `T.isPrefixOf` t -> loop (ObRunState_BackendStarted, msgs)
282283 ObRunState_Startup
283− | t == "backend stopped; make a change to your code to reload" -> loop ObRunState_Startup
284+ | t == "backend stopped; make a change to your code to reload" -> loop (ObRunState_Startup, msgs)
284285 -- | Just port <- "Backend running on port " `T.stripPrefix` t -> loop $ ObRunState_BackendStarted port
285286 | not (T.null t) -> errorExit $ "Startup: " <> t -- If theres any other output here, startup failed
286287 ObRunState_BackendStarted
@@ -288,7 +289,8 @@ handleObRunStdout httpManager stdout = flip fix ObRunState_Init $ \loop state ->
288289 obRunCheck httpManager stdout uri
289290 pure uri
290291 | not (T.null t) -> errorExit $ "Started: " <> t -- If theres any other output here, startup failed
291− _ -> loop state
292+ _ | "Failed" `T.isPrefixOf` t -> errorExit $ "ob run failed: " <> T.unlines (reverse $ t : msgs)
293+ | otherwise -> loop (state, t : msgs)
292294
293295-- | Make requests to frontend/backend servers to check they are working properly
294296obRunCheck :: HTTP.Manager -> Handle -> Text -> Sh ()