Commit fd3dd32d authored by Duncan Coutts's avatar Duncan Coutts
Browse files

Fix tar tests

No need to test functions that come from the tar lib now.

Also, correct the expected output for sandbox remove source. Previously
the results were expected to come out in reverse order, because the old
filterEntriesM performed the monad actions in reverse order. The new
code doesn't have that bug so the results come out in the correct order.
parent 0db3b216
......@@ -232,6 +232,7 @@ Test-Suite unit-tests
directory,
filepath,
stm,
tar,
time,
HTTP,
zlib,
......
Success deleting sources: "q" "p"
Success deleting sources: "p" "q"
Note: 'sandbox delete-source' only unregisters the source dependency, but does
not remove the package from the sandbox package DB.
......
......@@ -2,14 +2,15 @@ module UnitTests.Distribution.Client.Tar (
tests
) where
import Distribution.Client.Tar (foldrEntries
, filterEntries
, foldrEntriesM
import Distribution.Client.Tar ( filterEntries
, filterEntriesM
, EntryContent(..)
)
import Codec.Archive.Tar ( Entries(..)
, foldEntries
)
import Codec.Archive.Tar.Entry ( EntryContent(..)
, simpleEntry
, Entry(..)
, Entries(..)
, toTarPath
)
......@@ -21,28 +22,10 @@ import qualified Data.ByteString.Lazy.Char8 as BS.Char8
import Control.Monad.Writer.Lazy (runWriterT, tell)
tests :: [TestTree]
tests = [ testCase "foldrEntries" foldrTest
, testCase "filterEntries" filterTest
, testCase "foldrEntriesM" foldrMTest
tests = [ testCase "filterEntries" filterTest
, testCase "filterEntriesM" filterMTest
]
foldrTest :: Assertion
foldrTest = do
assertEqual "Unexpected result for Done" "x" $
foldrEntries undefined "x" undefined Done
assertEqual "Unexpected result for Fail" "x" $
foldrEntries undefined undefined id $ Fail "x"
let e1 = getFileEntry "path1" "x"
e2 = getFileEntry "path2" "y"
next = (\e acc -> let (NormalFile dta _) = entryContent e
str = BS.Char8.unpack dta
in str ++ acc)
assertEqual "Unexpected result for Next" "xyz" $
foldrEntries next "z" undefined $ Next e1 $ Next e2 Done
assertEqual "Unexpected result for Fail" "xyf" $
foldrEntries next "z" id $ Next e1 $ Next e2 $ Fail "f"
filterTest :: Assertion
filterTest = do
let e1 = getFileEntry "file1" "x"
......@@ -57,35 +40,6 @@ filterTest = do
assertEqual "Unexpected result for filter" "xf" $
entriesToString $ filterEntries p $ Next e1 $ Next e2 $ Fail "f"
foldrMTest :: Assertion
foldrMTest = do
(r, w) <- runWriterT $ foldrEntriesM undefined
(tell [1::Int] >> tell [2::Int] >> return "x") undefined Done
assertEqual "Unexpected result for Done" "x" r
assertEqual "Unexpected result for Done w" [1,2] w
(r1, w1) <- runWriterT $ foldrEntriesM undefined undefined
(return . id) $ Fail "x"
assertEqual "Unexpected result for Fail" "x" r1
assertEqual "Unexpected result for Fail w" "" w1
let e1 = getFileEntry "path1" "x"
e2 = getFileEntry "path2" "y"
next = (\e acc -> let (NormalFile dta _) = entryContent e
str = BS.Char8.unpack dta
in tell "a" >> return (str ++ acc))
done = tell "b" >> return "z"
(r2, w2) <- runWriterT $ foldrEntriesM next done undefined $
Next e1 $ Next e2 Done
assertEqual "Unexpected result for Next" "xyz" r2
assertEqual "Unexpected result for Next w" "baa" w2
let fail' = (\f -> tell "c" >> return f) . id
(r3, w3) <- runWriterT $ foldrEntriesM next done fail' $
Next e1 $ Next e2 $ Fail "f"
assertEqual "Unexpected result for Next" "xyf" r3
assertEqual "Unexpected result for Next w" "caa" w3
filterMTest :: Assertion
filterMTest = do
let e1 = getFileEntry "file1" "x"
......@@ -114,8 +68,8 @@ getFileEntry pth dta =
Left e -> error e
dta' = BS.Char8.pack dta
entriesToString :: Entries -> String
entriesToString :: Entries String -> String
entriesToString =
foldrEntries (\e acc -> let (NormalFile dta _) = entryContent e
str = BS.Char8.unpack dta
foldEntries (\e acc -> let (NormalFile dta _) = entryContent e
str = BS.Char8.unpack dta
in str ++ acc) "z" id
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment