forked from facebookincubator/retrie
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathIgnore.hs
67 lines (58 loc) · 2.13 KB
/
Ignore.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
-- Copyright (c) Facebook, Inc. and its affiliates.
--
-- This source code is licensed under the MIT license found in the
-- LICENSE file in the root directory of this source tree.
--
module Ignore (ignoreTest) where
import Retrie.Util
import System.FilePath
import Test.HUnit
import Util
allFiles :: [FilePath]
allFiles = [ c:".hs" | c <- ['A'..'F'] ] ++
[ "ignored-folder/A.thrift"
, "ignored-folder/subfolder/Ctest.hs"
, "ignored-folder/subfolder/subfolder2/Btest.hs"
]
ignoredFiles :: [FilePath]
ignoredFiles = ["B.hs", "C.hs", "ignored-folder/"]
ignoreTest :: Test
ignoreTest = TestLabel "ignore" $ TestList
[ hgTest
, gitTest
, unifiedTest1
, unifiedTest2
]
assertStuff :: FilePath -> Maybe (FilePath -> Bool) -> IO ()
assertStuff _ Nothing = assertFailure "pred was Nothing"
assertStuff repo (Just p) = do
assertBool "B.hs ignored" $ p $ repo </> "B.hs"
assertBool "C.hs ignored" $ p $ repo </> "C.hs"
assertBool "A.hs not ignored" $ not $ p $ repo </> "A.hs"
assertBool "Foo.hs not ignored" $ not $ p $ repo </> "Foo.hs"
assertBool "subfolder ignored" $
p $ repo </> "ignored-folder/subfolder/Ctest.hs"
assertBool "deep subfolder ignored" $
p $ repo </> "ignored-folder/subfolder/subfolder2/Btest.hs"
hgTest :: Test
hgTest = TestLabel "hg ignore" $ TestCase $
withFakeHgRepo ignoredFiles allFiles $ \repo -> do
maybePredicate <- hgIgnorePred Loud repo
assertStuff repo maybePredicate
case maybePredicate of
Just p ->
assertBool "subfolder non-hs file not ignored" $
not $ p $ repo </> "ignored-folder/A.thrift"
Nothing -> assertFailure "pred was Nothing"
gitTest :: Test
gitTest = TestLabel "git ignore" $ TestCase $
withFakeGitRepo ignoredFiles allFiles $ \repo ->
gitIgnorePred Loud repo >>= assertStuff repo
unifiedTest1 :: Test
unifiedTest1 = TestLabel "vcs ignore on git repo" $ TestCase $
withFakeGitRepo ignoredFiles allFiles $ \repo ->
vcsIgnorePred Loud repo >>= assertStuff repo
unifiedTest2 :: Test
unifiedTest2 = TestLabel "vcs ignore on hg repo" $ TestCase $
withFakeHgRepo ignoredFiles allFiles $ \repo ->
vcsIgnorePred Loud repo >>= assertStuff repo