on master help sign in
Merge pull request #581 from obsidiansystems/eac@fix-selftest-android

Fix selftest for android builds

commitba0e28fcf28daf77424b26dba4565c5c07ae8daa authorElliot Cameron <3noch@users.noreply.github.com> dateWed 18 Dec 2019, 14:14 (7 years ago) parentc7f02b3137f2a2
1 file changed+19−17
lib/selftest/src/Obelisk/SelfTest.hs+19−17
lib/selftest/src/Obelisk/SelfTest.hs+19−17
@@ -3,7 +3,6 @@
33{-# LANGUAGE OverloadedStrings #-}
44{-# LANGUAGE PatternGuards #-}
55{-# LANGUAGE ScopedTypeVariables #-}
6−{-# LANGUAGE TypeApplications #-}
76module Obelisk.SelfTest where
87
98import Control.Exception (bracket, throw)
@@ -71,7 +70,7 @@ shellyOb f obTest = shelly $ f obTest
7170main :: IO ()
7271main = do
7372 -- Note: you can pass hspec arguments as well, eg: `-m <pattern>`
74− isVerbose <- (elem "-v") <$> getArgs
73+ isVerbose <- elem "-v" <$> getArgs
7574 unless isVerbose $
7675 putStrLn "Tests may take longer to run if there are unbuilt derivations: use -v for verbose output"
7776 let verbosity = bool silently verbosely isVerbose
@@ -118,7 +117,7 @@ main = do
118117 it "works with master branch impl" $ inTmp $ \_ -> run "ob" ["init", "--branch", "master"]
119118 it "works with symlink" $ inTmp $ \_ -> run "ob" ["init", "--symlink", obeliskImpl]
120119 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 }
122121 (ExitSuccess, _, _) <- readCreateProcessWithExitCode (p False) ""
123122 (ExitFailure _, _, _) <- readCreateProcessWithExitCode (p False) ""
124123 (ExitSuccess, _, _) <- readCreateProcessWithExitCode (p True) ""
@@ -128,7 +127,7 @@ main = do
128127 void $ errExit False $ run "ob" ["init", "--symlink", "/dev/null"]
129128 ls tmp >>= liftIO . assertEqual "" []
130129
131− it "produces a valid route config" $ inTmpObInit $ \tmp -> liftIO $ do
130+ it "produces a valid route config" $ inTmpObInit $ \tmp -> liftIO $
132131 withCurrentDirectory (T.unpack $ toTextIgnore tmp) $ do
133132 configs <- getConfigs
134133 return (either (const Nothing) Just $ getConfigRoute configs) `shouldNotReturn` Nothing
@@ -136,10 +135,8 @@ main = do
136135 -- These tests fail with "Could not find module 'Obelisk.Generated.Static'"
137136 -- when not run by 'nix-build --attr selftest'
138137 describe "ob run" $ parallel $ do
139− it "works in root directory" $ inTmpObInit $ \_ -> do
140− testObRunInDir p0 p1 Nothing httpManager
141− it "works in sub directory" $ inTmpObInit $ \_ -> do
142− testObRunInDir p2 p3 (Just "frontend") httpManager
138+ it "works in root directory" $ inTmpObInit $ \_ -> testObRunInDir p0 p1 Nothing httpManager
139+ it "works in sub directory" $ inTmpObInit $ \_ -> testObRunInDir p2 p3 (Just "frontend") httpManager
143140
144141 describe "obelisk project" $ parallel $ do
145142 it "can build obelisk command" $ inTmpObInit $ \_ -> nixBuild ["-A", "command" , obeliskImpl]
@@ -149,14 +146,19 @@ main = do
149146
150147 describe "blank initialized project" $ parallel $ do
151148
152− it "can build ghc.backend" $ inTmpObInit $ \_ -> do
153− nixBuild ["-A", "ghc.backend"]
154− it "can build ghcjs.frontend" $ inTmpObInit $ \_ -> do
155− nixBuild ["-A", "ghcjs.frontend"]
149+ it "can build ghc.backend" $ inTmpObInit $ \_ -> nixBuild ["-A", "ghc.backend"]
150+ it "can build ghcjs.frontend" $ inTmpObInit $ \_ -> nixBuild ["-A", "ghcjs.frontend"]
156151
157152 if os == "darwin"
158− then it "can build ios" $ inTmpObInit $ \_ -> nixBuild ["-A", "ios.frontend"]
159− else it "can build android" $ inTmpObInit $ \_ -> nixBuild ["-A", "android.frontend"]
153+ then it "can build ios" $ inTmpObInit $ \_ -> nixBuild ["-A", "ios.frontend"]
154+ else it "can build android after accepting license" $ inTmpObInit $ \dir -> do
155+ let defaultNixPath = dir </> ("default.nix" :: Shelly.FilePath)
156+ writefile defaultNixPath
157+ =<< T.replace
158+ "# config.android_sdk.accept_license = false;"
159+ "config.android_sdk.accept_license = true;"
160+ <$> readfile defaultNixPath
161+ nixBuild ["-A", "android.frontend"]
160162
161163 forM_ ["ghc", "ghcjs"] $ \compiler -> do
162164 let
@@ -191,7 +193,7 @@ main = do
191193 branch' <- chdir dir $ run "git" ["rev-parse", "--abbrev-ref", "HEAD"]
192194 liftIO $ assertEqual "" branch (T.strip branch')
193195
194− it "can pack and unpack plain git repos" $ do
196+ it "can pack and unpack plain git repos" $
195197 shelly_ $ withSystemTempDirectory "git-repo" $ \dir -> do
196198 let repo = toTextIgnore $ dir </> ("repo" :: String)
197199 run_ "git" ["clone", "https://github.com/haskell/process.git", repo]
@@ -210,7 +212,7 @@ main = do
210212 testThunkPack $ fromText repo
211213
212214 it "aborts thunk pack when there are uncommitted files" $ inTmpObInit $ \dir -> do
213− void $ unpack
215+ void unpack
214216 testThunkPack (dir </> thunk)
215217
216218 describe "ob thunk update --branch" $ parallel $ do
@@ -289,7 +291,7 @@ alterRouteTo uri stdout = do
289291
290292-- | Handle stdout of `ob run`: check that the frontend and backend servers are started correctly
291293handleObRunStdout :: HTTP.Manager -> Handle -> Sh Text
292−handleObRunStdout httpManager stdout = flip fix (ObRunState_Init, []) $ \loop (state, msgs) -> do
294+handleObRunStdout httpManager stdout = flip fix (ObRunState_Init, []) $ \loop (state, msgs) ->
293295 liftIO (T.hGetLine stdout) >>= \t -> case state of
294296 ObRunState_Init
295297 | "Running test..." `T.isPrefixOf` t -> loop (ObRunState_BackendStarted, msgs)