2 {-# OPTIONS_GHC -fno-warn-orphans #-}
4 module UnitTests
.Distribution
.Client
.Glob
(tests
) where
6 import Distribution
.Client
.Compat
.Prelude
hiding (last)
9 import Distribution
.Client
.Glob
10 import Distribution
.Utils
.Structured
(structureHash
)
11 import UnitTests
.Distribution
.Client
.ArbitraryInstances
()
13 import GHC
.Fingerprint
(Fingerprint
(..))
15 import Test
.Tasty
.HUnit
16 import Test
.Tasty
.QuickCheck
20 [ testProperty
"print/parse roundtrip" prop_roundtrip_printparse
21 , testCase
"parse examples" testParseCases
24 [ testCase
"GlobPiece" $ structureHash
(Proxy
:: Proxy GlobPiece
) @?
= Fingerprint
0xd5e5361866a30ea2 0x31fbfe7b58864782
25 , testCase
"FilePathGlobRel" $ structureHash
(Proxy
:: Proxy FilePathGlobRel
) @?
= Fingerprint
0x76fa5bcb865a8501 0xb152f68915316f98
26 , testCase
"FilePathRoot" $ structureHash
(Proxy
:: Proxy FilePathRoot
) @?
= Fingerprint
0x713373d51426ec64 0xda7376a38ecee5a5
27 , testCase
"FilePathGlob" $ structureHash
(Proxy
:: Proxy FilePathGlob
) @?
= Fingerprint
0x3c11c41f3f03a1f0 0x96e69d85c37d0024
31 -- TODO: [nice to have] tests for trivial globs, tests for matching,
32 -- tests for windows style file paths
34 prop_roundtrip_printparse
:: FilePathGlob
-> Property
35 prop_roundtrip_printparse pathglob
=
36 counterexample
(prettyShow pathglob
) $
37 eitherParsec
(prettyShow pathglob
) === Right pathglob
39 -- first run, where we don't even call updateMonitor
40 testParseCases
:: Assertion
42 FilePathGlob
(FilePathRoot
"/") GlobDirTrailing
<- testparse
"/"
43 FilePathGlob FilePathHomeDir GlobDirTrailing
<- testparse
"~/"
45 FilePathGlob
(FilePathRoot
"A:\\") GlobDirTrailing
<- testparse
"A:/"
46 FilePathGlob
(FilePathRoot
"Z:\\") GlobDirTrailing
<- testparse
"z:/"
47 FilePathGlob
(FilePathRoot
"C:\\") GlobDirTrailing
<- testparse
"C:\\"
48 FilePathGlob FilePathRelative
(GlobFile
[Literal
"_:"]) <- testparse
"_:"
52 (GlobFile
[Literal
"."]) <-
57 (GlobFile
[Literal
"~"]) <-
62 (GlobDir
[Literal
"."] GlobDirTrailing
) <-
67 (GlobFile
[Literal
"foo"]) <-
74 (GlobFile
[Literal
"bar"])
82 (GlobDir
[Literal
"bar"] GlobDirTrailing
)
90 (GlobDir
[Literal
"bar"] GlobDirTrailing
)
98 (GlobDir
[Literal
"bar"] GlobDirTrailing
)
100 testparse
"C:\\foo\\bar\\"
104 (GlobFile
[WildCard
]) <-
109 (GlobFile
[WildCard
, WildCard
]) <-
110 testparse
"**" -- not helpful but valid
113 (GlobFile
[WildCard
, Literal
"foo", WildCard
]) <-
118 (GlobFile
[Literal
"foo", WildCard
, Literal
"bar"]) <-
123 (GlobFile
[Union
[[WildCard
], [Literal
"foo"]]]) <-
138 testparse
:: String -> IO FilePathGlob
140 case eitherParsec s
of
142 Left err
-> throwIO
$ HUnitFailure Nothing
("expected parse of: " ++ s
++ " -- " ++ err
)
144 parseFail
:: String -> Assertion
146 case eitherParsec s
:: Either String FilePathGlob
of
147 Right p
-> throwIO
$ HUnitFailure Nothing
("expected no parse of: " ++ s
++ " -- " ++ show p
)