1 module UnitTests
.Distribution
.Client
.Tar
5 import Codec
.Archive
.Tar
8 import Codec
.Archive
.Tar
.Entry
12 import Distribution
.Client
.Tar
18 import Test
.Tasty
.HUnit
20 import Control
.Monad
.Writer
.Lazy
(runWriterT
, tell
)
21 import qualified Data
.ByteString
.Lazy
as BS
22 import qualified Data
.ByteString
.Lazy
.Char8
as BS
.Char8
24 import Distribution
.Client
.Compat
.Tar
28 [ testCase
"filterEntries" filterTest
29 , testCase
"filterEntriesM" filterMTest
32 filterTest
:: Assertion
34 let e1
= getFileEntry
"file1" "x"
35 e2
= getFileEntry
"file2" "y"
38 let str
= BS
.Char8
.unpack
$ case entryContent e
of
39 NormalFile dta _
-> dta
40 _
-> error "Invalid entryContent"
43 assertEqual
"Unexpected result for filter" "xz" $
48 assertEqual
"Unexpected result for filter" "z" $
52 assertEqual
"Unexpected result for filter" "xf" $
59 filterMTest
:: Assertion
61 let e1
= getFileEntry
"file1" "x"
62 e2
= getFileEntry
"file2" "y"
65 let str
= BS
.Char8
.unpack
$ case entryContent e
of
66 NormalFile dta _
-> dta
67 _
-> error "Invalid entryContent"
68 in tell
"t" >> return (str
/= "y")
71 (r
, w
) <- runWriterT
$ filterEntriesM p
$ Next e1
$ Next e2 Done
72 assertEqual
"Unexpected result for filterM" "xz" $ entriesToString r
73 assertEqual
"Unexpected result for filterM w" "tt" w
75 (r1
, w1
) <- runWriterT
$ filterEntriesM p
$ Done
76 assertEqual
"Unexpected result for filterM" "z" $ entriesToString r1
77 assertEqual
"Unexpected result for filterM w" "" w1
79 (r2
, w2
) <- runWriterT
$ filterEntriesM p
$ Next e1
$ Next e2
$ Fail
"f"
80 assertEqual
"Unexpected result for filterM" "xf" $ entriesToString r2
81 assertEqual
"Unexpected result for filterM w" "tt" w2
83 getFileEntry
:: FilePath -> [Char] -> Entry
84 getFileEntry pth dta
=
85 simpleEntry tp
$ NormalFile dta
' $ BS
.length dta
'
87 tp
= case toTarPath
False pth
of
90 dta
' = BS
.Char8
.pack dta
92 entriesToString
:: Entries
String -> String
96 let str
= BS
.Char8
.unpack
$ case entryContent e
of
97 NormalFile dta _
-> dta
98 _
-> error "Invalid entryContent"