@@ -76,6 +76,14 @@ tshow = T.pack . show
7676shellyOb :: MonadIO m => (Sh a -> Sh a) -> Sh a -> m a
7777shellyOb f obTest = shelly $ f obTest
7878
79+-- Set "ob" in a single place so it can be replaced with a
80+-- link to obelisk in the nix store in the future,
81+-- and avoid PATH hacking before calling this script.
82+ob :: FilePath
83+ob = "ob"
84+
85+augmentWithVerbosity :: (String -> [Text] -> a) -> String -> Bool -> [Text] -> a
86+augmentWithVerbosity runner executable isVerbose args = runner executable $ (if isVerbose then ("-v" :) else id) args
7987
8088main :: IO ()
8189main = do
@@ -86,6 +94,10 @@ main = do
8694 let verbosity = bool silently verbosely isVerbose
8795 nixBuild args = run "nix-build" ("--no-out-link" : args)
8896 obeliskImplRaw <- fromString <$> getEnv "OBELISK_IMPL"
97+ let runOb_ = augmentWithVerbosity run_ ob isVerbose
98+ let runOb = augmentWithVerbosity run ob isVerbose
99+ let testObRunInDir' = augmentWithVerbosity testObRunInDir ob isVerbose ["run"]
100+ let testThunkPack' = augmentWithVerbosity testThunkPack ob isVerbose []
89101 let
90102 withObeliskImpl f =
91103 withSystemTempDirectory "obelisk-impl-copy" $ \(fromString -> obeliskImpl) -> do
@@ -100,7 +112,7 @@ main = do
100112 withSystemTempDirectory "init Cache λ" $ \initCache -> do
101113 -- Setup the ob init cache
102114 void . shellyOb verbosity $ chdir initCache $ do
103− run_ "ob" ["init", "--symlink", toTextIgnore obeliskImpl]
115+ runOb_ ["init", "--symlink", toTextIgnore obeliskImpl]
104116 run_ "git" ["init"]
105117
106118 f initCache
@@ -146,25 +158,25 @@ main = do
146158 revParseHead
147159
148160 thunk = ".obelisk/impl"
149− update = run "ob" ["thunk", "update", thunk] >> commitAll
150− pack = run "ob" ["thunk", "pack", thunk] >> commitAll
151− unpack = run "ob" ["thunk", "unpack", thunk] >> commitAll
161+ update = runOb ["thunk", "update", thunk] >> commitAll
162+ pack = runOb ["thunk", "pack", thunk] >> commitAll
163+ unpack = runOb ["thunk", "unpack", thunk] >> commitAll
152164
153165 diff a b = run "git" ["diff", a, b]
154166
155167 describe "ob init" $ parallel $ do
156− it "works with default impl" $ inTmp $ \_ -> run "ob" ["init"]
157− it "works with master branch impl" $ inTmp $ \_ -> run "ob" ["init", "--branch", "master"]
158− it "works with symlink" $ inTmp $ \_ -> run "ob" ["init", "--symlink", toTextIgnore obeliskImpl]
168+ it "works with default impl" $ inTmp $ \_ -> runOb ["init"]
169+ it "works with master branch impl" $ inTmp $ \_ -> runOb ["init", "--branch", "master"]
170+ it "works with symlink" $ inTmp $ \_ -> runOb ["init", "--symlink", toTextIgnore obeliskImpl]
159171 it "doesn't silently overwrite existing files" $ withSystemTempDirectory "ob-init λ" $ \dir -> do
160− let p force = (System.Process.proc "ob" $ "--no-handoff" : "init" : ["--force"|force]) { cwd = Just dir }
172+ let p force = (System.Process.proc ob $ "--no-handoff" : "-v" : "init" : ["--force"|force]) { cwd = Just dir }
161173 (ExitSuccess, _, _) <- readCreateProcessWithExitCode (p False) ""
162174 (ExitFailure _, _, _) <- readCreateProcessWithExitCode (p False) ""
163175 (ExitSuccess, _, _) <- readCreateProcessWithExitCode (p True) ""
164176 pure ()
165177
166178 it "doesn't create anything when given an invalid impl" $ inTmp $ \tmp -> do
167− void $ errExit False $ run "ob" ["init", "--symlink", "/dev/null"]
179+ void $ errExit False $ runOb ["init", "--symlink", "/dev/null"]
168180 ls tmp >>= liftIO . assertEqual "" []
169181
170182 it "produces a valid route config" $ inTmpObInit $ \tmp -> liftIO $
@@ -175,11 +187,11 @@ main = do
175187 -- These tests fail with "Could not find module 'Obelisk.Generated.Static'"
176188 -- when not run by 'nix-build --attr selftest'
177189 describe "ob run" $ {- NOT parallel $ -} do
178− it "works in root directory" $ inTmpObInit $ \_ -> testObRunInDir Nothing httpManager
179− it "works in sub directory" $ inTmpObInit $ \_ -> testObRunInDir (Just "frontend") httpManager
190+ it "works in root directory" $ inTmpObInit $ \_ -> testObRunInDir' Nothing httpManager
191+ it "works in sub directory" $ inTmpObInit $ \_ -> testObRunInDir' (Just "frontend") httpManager
180192 it "works with differently named cabal files" $ inTmpObInit $ \_ -> do
181193 changeCabalPackageName "backend/backend.cabal" "new-backend"
182− testObRunInDir Nothing httpManager
194+ testObRunInDir' Nothing httpManager
183195
184196 describe "obelisk project" $ parallel $ do
185197 it "can build obelisk command" $ inTmpObInit $ \_ -> nixBuild ["-A", "command" , toTextIgnore obeliskImpl]
@@ -236,8 +248,8 @@ main = do
236248 it "unpacks the correct branch" $ withTmp $ \dir -> do
237249 let branch = "master"
238250 run_ "git" ["clone", "https://github.com/reflex-frp/reflex.git", toTextIgnore dir, "--branch", branch]
239− run_ "ob" ["thunk", "pack", toTextIgnore dir]
240− run_ "ob" ["thunk", "unpack", toTextIgnore dir]
251+ runOb_ ["thunk", "pack", toTextIgnore dir]
252+ runOb_ ["thunk", "unpack", toTextIgnore dir]
241253 branch' <- chdir dir $ run "git" ["rev-parse", "--abbrev-ref", "HEAD"]
242254 liftIO $ assertEqual "" branch (T.strip branch')
243255
@@ -247,45 +259,45 @@ main = do
247259 run_ "git" ["clone", "https://github.com/haskell/process.git", repo]
248260 origHash <- chdir (fromText repo) revParseHead
249261
250− run_ "ob" ["thunk", "pack", repo]
262+ runOb_ ["thunk", "pack", repo]
251263 packedFiles <- Set.fromList <$> ls (fromText repo)
252264 liftIO $ assertEqual "" packedFiles $ Set.fromList $ (repo </>) <$>
253265 ["default.nix", "github.json", ".attr-cache" :: String]
254266
255− run_ "ob" ["thunk", "unpack", repo]
267+ runOb_ ["thunk", "unpack", repo]
256268 chdir (fromText repo) $ do
257269 unpackHash <- revParseHead
258270 assertRevEQ origHash unpackHash
259271
260− testThunkPack $ fromText repo
272+ testThunkPack' $ fromText repo
261273
262274 it "aborts thunk pack when there are uncommitted files" $ inTmpObInit $ \dir -> do
263− testThunkPack (dir </> thunk)
275+ testThunkPack' (dir </> thunk)
264276
265277 describe "ob thunk update --branch" $ parallel $ do
266278 it "can change a thunk to the latest version of a desired branch" $ withTmp $ \dir -> do
267279 let branch1 = "master"
268280 branch2 = "develop"
269281 run_ "git" ["clone", "https://github.com/reflex-frp/reflex.git", toTextIgnore dir, "--branch", branch1]
270− run_ "ob" ["thunk" , "pack", toTextIgnore dir]
271− run_ "ob" ["thunk", "update", toTextIgnore dir, "--branch", branch2]
282+ runOb_ ["thunk" , "pack", toTextIgnore dir]
283+ runOb_ ["thunk", "update", toTextIgnore dir, "--branch", branch2]
272284
273285 it "doesn't create anything when given an invalid branch" $ withTmp $ \dir -> do
274286 let checkDir dir' = liftIO $ getDirectoryContents $ T.unpack $ toTextIgnore dir'
275287 run_ "git" ["clone", "https://github.com/reflex-frp/reflex.git", toTextIgnore dir, "--branch", "master"]
276− run_ "ob" ["thunk" , "pack", toTextIgnore dir]
288+ runOb_ ["thunk" , "pack", toTextIgnore dir]
277289 startingContents <- checkDir dir
278− void $ errExit False $ run "ob" ["thunk", "update", toTextIgnore dir, "--branch", "dumble-palooza"]
290+ void $ errExit False $ runOb ["thunk", "update", toTextIgnore dir, "--branch", "dumble-palooza"]
279291 checkDir dir >>= liftIO . assertEqual "" startingContents
280292
281293
282294-- | Run `ob run` in the given directory (maximum of one level deep)
283−testObRunInDir :: Maybe FilePath -> HTTP.Manager -> Sh ()
284−testObRunInDir mdir httpManager = handle_sh (\case ExitSuccess -> pure (); e -> throw e) $ do
295+testObRunInDir :: String -> [Text] -> Maybe FilePath -> HTTP.Manager -> Sh ()
296+testObRunInDir executable extraArgs mdir httpManager = handle_sh (\case ExitSuccess -> pure (); e -> throw e) $ do
285297 [p0, p1] <- liftIO $ getFreePorts 2
286298 let uri p = "http://localhost:" <> T.pack (show p) <> "/" -- trailing slash required for comparison
287299 writefile "config/common/route" $ uri p0
288− maybe id chdir mdir $ runHandle "ob" ["run", "-v"] $ \stdout -> do
300+ maybe id chdir mdir $ runHandle executable extraArgs $ \stdout -> do
289301 firstUri <- handleObRunStdout httpManager stdout
290302 let newUri = uri p1
291303 when (firstUri == newUri) $ errorExit $
@@ -296,9 +308,9 @@ testObRunInDir mdir httpManager = handle_sh (\case ExitSuccess -> pure (); e ->
296308 then errorExit $ "Reloading failed: expected " <> newUri <> " but got " <> runningUri
297309 else exit 0
298310
299−testThunkPack :: FilePath -> Sh ()
300−testThunkPack path' = withTempFile (T.unpack $ toTextIgnore path') "test-file" $ \file handle -> do
301− let pack' = readProcessWithExitCode "ob" ["thunk", "pack", T.unpack $ toTextIgnore path'] ""
311+testThunkPack :: String -> [Text] -> FilePath -> Sh ()
312+testThunkPack executable args path' = withTempFile (T.unpack $ toTextIgnore path') "test-file" $ \file handle -> do
313+ let pack' = readProcessWithExitCode executable (T.unpack <$> ["thunk", "pack", toTextIgnore path'] ++ args) ""
302314 ensureThunkPackFails q = liftIO $ pack' >>= \case
303315 (code, out, err)
304316 | code == ExitSuccess -> fail "ob thunk pack succeeded when it should have failed"