@@ -3,6 +3,7 @@
33{-# LANGUAGE OverloadedStrings #-}
44{-# LANGUAGE PatternGuards #-}
55{-# LANGUAGE ScopedTypeVariables #-}
6+{-# LANGUAGE ViewPatterns #-}
67module Obelisk.SelfTest where
78
89import Control.Exception (bracket, throw)
@@ -75,14 +76,28 @@ main = do
7576 putStrLn "Tests may take longer to run if there are unbuilt derivations: use -v for verbose output"
7677 let verbosity = bool silently verbosely isVerbose
7778 nixBuild args = run "nix-build" ("--no-out-link" : args)
78− obeliskImpl <- fromString <$> getEnv "OBELISK_IMPL"
79+ obeliskImplRaw <- fromString <$> getEnv "OBELISK_IMPL"
80+ let
81+ withObeliskImpl f =
82+ withSystemTempDirectory "obelisk-impl-copy" $ \(fromString -> obeliskImpl) -> do
83+ void . shellyOb verbosity $ chdir obeliskImpl $ do
84+ user <- T.strip <$> run "whoami" []
85+ run_ "cp" ["-rT", toTextIgnore obeliskImplRaw, toTextIgnore obeliskImpl]
86+ run_ "chown" ["-R", user, toTextIgnore obeliskImpl]
87+ run_ "chmod" ["-R", "g-rw,o-rw", toTextIgnore obeliskImpl]
88+
89+ withSystemTempDirectory "init Cache λ" $ \initCache -> do
90+ -- Setup the ob init cache
91+ void . shellyOb verbosity $ chdir (fromString initCache) $ do
92+ run_ "ob" ["init", "--symlink", toTextIgnore obeliskImpl]
93+ run_ "git" ["init"]
94+
95+ f obeliskImpl initCache
96+
7997 httpManager <- HTTP.newManager HTTP.defaultManagerSettings
8098 [p0, p1, p2, p3] <- liftIO $ getFreePorts 4
81− withSystemTempDirectory "init Cache λ" $ \initCache -> do
82− -- Setup the ob init cache
83− void . shellyOb verbosity $ chdir (fromString initCache) $ do
84− run_ "ob" ["init"]
85− run_ "git" ["init"]
99+
100+ withObeliskImpl $ \obeliskImpl initCache ->
86101 hspec $ parallel $ do
87102 let shelly_ = void . shellyOb verbosity
88103
@@ -92,7 +107,7 @@ main = do
92107 withTmp f = shelly_ . withSystemTempDirectory "test λ" $ f . fromString
93108
94109 inTmpObInit f = inTmp $ \dir -> do
95− run_ "cp" ["-a", fromString $ initCache <> "/.", toTextIgnore dir]
110+ run_ "cp" ["-rT", fromString initCache, toTextIgnore dir]
96111 f dir
97112
98113 assertRevEQ a b = liftIO . assertEqual "" "" =<< diff a b
@@ -115,7 +130,7 @@ main = do
115130 describe "ob init" $ parallel $ do
116131 it "works with default impl" $ inTmp $ \_ -> run "ob" ["init"]
117132 it "works with master branch impl" $ inTmp $ \_ -> run "ob" ["init", "--branch", "master"]
118− it "works with symlink" $ inTmp $ \_ -> run "ob" ["init", "--symlink", obeliskImpl]
133+ it "works with symlink" $ inTmp $ \_ -> run "ob" ["init", "--symlink", toTextIgnore obeliskImpl]
119134 it "doesn't silently overwrite existing files" $ withSystemTempDirectory "ob-init λ" $ \dir -> do
120135 let p force = (proc "ob" $ "--no-handoff" : "init" : ["--force"|force]) { cwd = Just dir }
121136 (ExitSuccess, _, _) <- readCreateProcessWithExitCode (p False) ""
@@ -139,10 +154,10 @@ main = do
139154 it "works in sub directory" $ inTmpObInit $ \_ -> testObRunInDir p2 p3 (Just "frontend") httpManager
140155
141156 describe "obelisk project" $ parallel $ do
142− it "can build obelisk command" $ inTmpObInit $ \_ -> nixBuild ["-A", "command" , obeliskImpl]
143− it "can build obelisk skeleton" $ inTmpObInit $ \_ -> nixBuild ["-A", "skeleton", obeliskImpl]
144− it "can build obelisk shell" $ inTmpObInit $ \_ -> nixBuild ["-A", "shell", obeliskImpl]
145− it "can build everything" $ inTmpObInit $ \_ -> nixBuild [obeliskImpl]
157+ it "can build obelisk command" $ inTmpObInit $ \_ -> nixBuild ["-A", "command" , toTextIgnore obeliskImpl]
158+ it "can build obelisk skeleton" $ inTmpObInit $ \_ -> nixBuild ["-A", "skeleton", toTextIgnore obeliskImpl]
159+ it "can build obelisk shell" $ inTmpObInit $ \_ -> nixBuild ["-A", "shell", toTextIgnore obeliskImpl]
160+ it "can build everything" $ inTmpObInit $ \_ -> nixBuild [toTextIgnore obeliskImpl]
146161
147162 describe "blank initialized project" $ parallel $ do
148163