on master help sign in
Add tests for plain git thunks
commitda79300bc7a5ec350f1de1f55a93ffdf6f756a55 authorElliot Cameron <eacameron@gmail.com> dateFri 18 May 2018, 20:20 (8 years ago) parentb3b8de6
2 files changed+25−8
lib/selftest/obelisk-selftest.cabal+1 lib/selftest/src/Obelisk/SelfTest.hs+24−8
lib/selftest/obelisk-selftest.cabal+1
@@ -10,6 +10,7 @@ library
1010 hs-source-dirs: src
1111 build-depends:
1212 base
13+ , containers
1314 , hspec
1415 , http-client
1516 , http-types
lib/selftest/src/Obelisk/SelfTest.hs+24−8
@@ -1,5 +1,6 @@
11{-# LANGUAGE LambdaCase #-}
22{-# LANGUAGE OverloadedStrings #-}
3+{-# LANGUAGE TypeApplications #-}
34module Obelisk.SelfTest where
45
56import Control.Exception (throw)
@@ -7,6 +8,7 @@ import Control.Monad
78import Control.Monad.IO.Class
89import Data.Function (fix)
910import Data.Semigroup ((<>))
11+import qualified Data.Set as Set
1012import Data.String
1113import Data.Text (Text)
1214import qualified Data.Text as T
@@ -41,7 +43,8 @@ main = do
4143 thunk = ".obelisk/impl"
4244
4345 -- See https://github.com/obsidiansystems/obelisk/pull/92#issuecomment-390226735
44− hash = silently $ run "sh" ["-c", "cd " <> thunk <> " && find . | grep -v '^./.git' | grep -v '/.attr-cache' | grep -v '^.$' | xargs -n 1 -I % -- sh -c 'echo `nix-hash %` %'"]
46+ hashDir dir = silently $ run "sh" ["-c", "cd " <> dir <> " && find . | grep -v '^./.git' | grep -v '/.attr-cache' | grep -v '^.$' | xargs -n 1 -I % -- sh -c 'echo `nix-hash %` %'"]
47+ hash = hashDir thunk
4548
4649 it "can be created" $ inProj $ do
4750 run "ob" ["init"]
@@ -51,14 +54,14 @@ main = do
5154 it "can build ghcjs.frontend" $ inProj $ do
5255 run "nix-build" ["--no-out-link", "-A", "ghcjs.frontend"]
5356
54− if (os == "darwin")
55− then it "can build ios" $ inProj $ run "nix-build" $ ["--no-out-link", "-A", "ios.frontend" ]
56− else it "can build android" $ inProj $ run "nix-build" $ ["--no-out-link", "-A", "android.frontend"]
57+ if os == "darwin"
58+ then it "can build ios" $ inProj $ run "nix-build" ["--no-out-link", "-A", "ios.frontend" ]
59+ else it "can build android" $ inProj $ run "nix-build" ["--no-out-link", "-A", "android.frontend"]
5760
5861 forM_ ["ghc", "ghcjs"] $ \compiler -> do
5962 let
6063 shell = "shells." <> compiler
61− inShell cmd = run "nix-shell" $ ["-A", fromString shell, "--run", cmd]
64+ inShell cmd = run "nix-shell" ["-A", fromString shell, "--run", cmd]
6265 it ("can enter " <> shell) $ inProj $ inShell "exit"
6366 it ("can build in " <> shell) $ inProj $ inShell $ "cabal new-build --" <> fromString compiler <> " all"
6467
@@ -69,8 +72,8 @@ main = do
6972 liftIO $ assertEqual "" u uu
7073
7174 it "has thunk pack and unpack inverses" $ inProj $ do
72− let pack = run "ob" ["thunk", "pack", thunk] *> hash
73− unpack = run "ob" ["thunk", "unpack", thunk] *> hash
75+ let pack = run_ "ob" ["thunk", "pack", thunk] *> hash
76+ unpack = run_ "ob" ["thunk", "unpack", thunk] *> hash
7477
7578 e <- hash
7679 eu <- unpack
@@ -81,7 +84,20 @@ main = do
8184 liftIO $ do
8285 assertEqual "" e eup
8386 assertEqual "" eu eupu
84− assertBool "" (e /= eu)
87+ assertBool "" (e /= eu)
88+
89+ it "can pack and unpack plain git repos" $ do
90+ withSystemTempDirectory "git-repo" $ \dir -> shelly @IO $ silently $ do
91+ let repo = toTextIgnore $ dir </> ("repo" :: String)
92+ origHash <- run_ "git" ["clone", "https://git.haskell.org/packages/primitive.git", repo] *> hashDir repo
93+
94+ run_ "ob" ["thunk", "pack", repo]
95+ packedFiles <- Set.fromList <$> ls (repo </> ("" :: String))
96+ liftIO $ assertEqual "" packedFiles $
97+ Set.fromList $ (repo </>) <$> ["default.nix", "git.json", ".attr-cache" :: String]
98+
99+ unpackHash <- run_ "ob" ["thunk", "unpack", repo] *> hashDir repo
100+ liftIO $ assertEqual "" origHash unpackHash
85101
86102 it "can use ob run" $ inProj $ handle_sh (\case ExitSuccess -> pure (); e -> throw e) $ do
87103 runHandle "ob" ["run"] $ \stdout -> do