on master help sign in
Merge pull request #43 from alexfmpe/cleanup-selftest

Cleanup selftest

commit65e0464a8a52d0409f1a39782f076feb750a5d6d authorLuigy Leon <luichi.19@gmail.com> dateWed 30 May 2018, 17:54 (8 years ago) parent288680fa9e2ac7
1 file changed+56−52
lib/selftest/src/Obelisk/SelfTest.hs+56−52
lib/selftest/src/Obelisk/SelfTest.hs+56−52
@@ -40,9 +40,32 @@ main = do
4040 withSystemTempDirectory "blank-project" $ \blankProject ->
4141 hspec $ do
4242 let shelly_ = void . shelly . silently
43+
44+ inProj :: Sh a -> IO ()
45+ inProj = shelly_ . chdir (fromString blankProject)
46+
4347 inTmp :: (Shelly.FilePath -> Sh a) -> IO ()
4448 inTmp f = shelly_ . withSystemTempDirectory "ob-init" $ (chdir <*> f) . fromString
4549
50+ assertRevEQ a b = liftIO . assertEqual "" "" =<< diff a b
51+ assertRevNE a b = liftIO . assertBool "" . (/= "") =<< diff a b
52+
53+ doubleQuotes s = "\"" <> s <> "\""
54+
55+ revParseHead = T.strip <$> run "git" ["rev-parse", "HEAD"]
56+
57+ commitAll = do
58+ run "git" ["add", "."]
59+ run "git" ["commit", "--allow-empty", "-m", doubleQuotes "checkpoint"]
60+ revParseHead
61+
62+ thunk = ".obelisk/impl"
63+ update = run "ob" ["thunk", "update", thunk] >> commitAll
64+ pack = run "ob" ["thunk", "pack", thunk] >> commitAll
65+ unpack = run "ob" ["thunk", "unpack", thunk] >> commitAll
66+
67+ diff a b = run "git" ["diff", a, b]
68+
4669 describe "ob init" $ do
4770 it "works with default impl" $ inTmp $ \_ -> run "ob" ["init"]
4871 it "works with master branch impl" $ inTmp $ \_ -> run "ob" ["init", "--branch", "master"]
@@ -67,21 +90,6 @@ main = do
6790 it "can build everything" $ shelly_ $ run "nix-build" [obeliskImpl]
6891
6992 describe "blank initialized project" $ do
70− let inProj :: Sh a -> IO ()
71− inProj = shelly_ . chdir (fromString blankProject)
72− thunk = ".obelisk/impl"
73−
74− doubleQuotes s = "\"" <> s <> "\""
75− revParseHead = T.strip <$> run "git" ["rev-parse", "HEAD"]
76− commitAll = do
77− run "git" ["add", "."]
78− run "git" ["commit", "--allow-empty", "-m", doubleQuotes "checkpoint"]
79− revParseHead
80−
81− diff a b = run "git" ["diff", a, b]
82− assertRevEQ a b = liftIO . assertEqual "" "" =<< diff a b
83− assertRevNE a b = liftIO . assertBool "" . (/= "") =<< diff a b
84−
8593 it "can be created" $ inProj $ do
8694 run "ob" ["init"]
8795 run "git" ["init"]
@@ -107,47 +115,43 @@ main = do
107115 run "nix-build" []
108116
109117 it "has idempotent thunk update" $ inProj $ do
110− let update = run "ob" ["thunk", "update", thunk] >> commitAll
111118 u <- update
112119 uu <- update
113120 assertRevEQ u uu
114121
115− describe "ob thunk pack/unpack" $ do
116− let pack = run "ob" ["thunk", "pack", thunk] >> commitAll
117− unpack = run "ob" ["thunk", "unpack", thunk] >> commitAll
118−
119− it "has thunk pack and unpack inverses" $ inProj $ do
120− e <- commitAll
121− eu <- unpack
122− eup <- pack
123− eupu <- unpack
124− _ <- pack
125−
126− assertRevEQ e eup
127− assertRevEQ eu eupu
128− assertRevNE e eu
129−
130− it "can pack and unpack plain git repos" $ do
131− withSystemTempDirectory "git-repo" $ \dir -> shelly @IO $ silently $ do
132− let repo = toTextIgnore $ dir </> ("repo" :: String)
133− run_ "git" ["clone", "https://git.haskell.org/packages/primitive.git", repo]
134− origHash <- chdir (fromText repo) revParseHead
135−
136− run_ "ob" ["thunk", "pack", repo]
137− packedFiles <- Set.fromList <$> ls (fromText repo)
138− liftIO $ assertEqual "" packedFiles $
139− Set.fromList $ (repo </>) <$> ["default.nix", "git.json", ".attr-cache" :: String]
140−
141− run_ "ob" ["thunk", "unpack", repo]
142− chdir (fromText repo) $ do
143− unpackHash <- revParseHead
144− assertRevEQ origHash unpackHash
145−
146− testThunkPack $ fromText repo
147−
148− it "aborts thunk pack when there are uncommitted files" $ inProj $ do
149− unpack
150− testThunkPack (blankProject </> thunk)
122+ describe "ob thunk pack/unpack" $ do
123+ it "has thunk pack and unpack inverses" $ inProj $ do
124+ e <- commitAll
125+ eu <- unpack
126+ eup <- pack
127+ eupu <- unpack
128+ _ <- pack
129+
130+ assertRevEQ e eup
131+ assertRevEQ eu eupu
132+ assertRevNE e eu
133+
134+ it "can pack and unpack plain git repos" $ do
135+ withSystemTempDirectory "git-repo" $ \dir -> shelly @IO $ silently $ do
136+ let repo = toTextIgnore $ dir </> ("repo" :: String)
137+ run_ "git" ["clone", "https://git.haskell.org/packages/primitive.git", repo]
138+ origHash <- chdir (fromText repo) revParseHead
139+
140+ run_ "ob" ["thunk", "pack", repo]
141+ packedFiles <- Set.fromList <$> ls (fromText repo)
142+ liftIO $ assertEqual "" packedFiles $
143+ Set.fromList $ (repo </>) <$> ["default.nix", "git.json", ".attr-cache" :: String]
144+
145+ run_ "ob" ["thunk", "unpack", repo]
146+ chdir (fromText repo) $ do
147+ unpackHash <- revParseHead
148+ assertRevEQ origHash unpackHash
149+
150+ testThunkPack $ fromText repo
151+
152+ it "aborts thunk pack when there are uncommitted files" $ inProj $ do
153+ unpack
154+ testThunkPack (blankProject </> thunk)
151155
152156-- | Run `ob run` in the given directory (maximum of one level deep)
153157testObRunInDir :: Maybe Shelly.FilePath -> HTTP.Manager -> Sh ()