on master help sign in
Merge pull request #92 from obsidiansystems/alexfmpe-test-ob-thunk

Test ob thunk

commit36e49a2c8ef72c59ec6713bb3d83d9682a4f11e5 authorLuigy Leon <luichi.19@gmail.com> dateFri 18 May 2018, 15:36 (8 years ago) parent06f35815aac627
2 files changed+30−1
lib/selftest/obelisk-selftest.cabal+1 lib/selftest/src/Obelisk/SelfTest.hs+29−1
lib/selftest/obelisk-selftest.cabal+1
@@ -13,6 +13,7 @@ library
1313 , hspec
1414 , http-client
1515 , http-types
16+ , HUnit
1617 , shelly
1718 , temporary
1819 , text
lib/selftest/src/Obelisk/SelfTest.hs+29−1
@@ -21,6 +21,7 @@ import System.IO (Handle)
2121import System.IO.Temp
2222import System.Timeout
2323import Test.Hspec
24+import Test.HUnit.Base
2425
2526data ObRunState
2627 = ObRunState_Init
@@ -37,8 +38,14 @@ main = do
3738 describe "blank initialized project" $ do
3839 let inProj :: Sh a -> IO ()
3940 inProj = void . shelly . silently . chdir (fromString blankProject)
41+ thunk = ".obelisk/impl"
42+
43+ -- 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 %` %'"]
45+
4046 it "can be created" $ inProj $ do
41− run "ob" ["init", "--symlink", T.pack obeliskImpl]
47+ run "ob" ["init"]
48+
4249 it "can build ghc.backend" $ inProj $ do
4350 run "nix-build" ["--no-out-link", "-A", "ghc.backend"]
4451 it "can build ghcjs.frontend" $ inProj $ do
@@ -55,6 +62,27 @@ main = do
5562 it ("can enter " <> shell) $ inProj $ inShell "exit"
5663 it ("can build in " <> shell) $ inProj $ inShell $ "cabal new-build --" <> fromString compiler <> " all"
5764
65+ it "has idempotent thunk update" $ inProj $ do
66+ let update = run "ob" ["thunk", "update", thunk] *> hash
67+ u <- update
68+ uu <- update
69+ liftIO $ assertEqual "" u uu
70+
71+ 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
74+
75+ e <- hash
76+ eu <- unpack
77+ eup <- pack
78+ eupu <- unpack
79+ _ <- pack
80+
81+ liftIO $ do
82+ assertEqual "" e eup
83+ assertEqual "" eu eupu
84+ assertBool "" (e /= eu)
85+
5886 it "can use ob run" $ inProj $ handle_sh (\case ExitSuccess -> pure (); e -> throw e) $ do
5987 runHandle "ob" ["run"] $ \stdout -> do
6088 (_, firstUri) <- obRun httpManager stdout