Skip to content

Commit 0926e16

Browse files
committed
Write a property test for large file sizes
1 parent 7adb980 commit 0926e16

File tree

3 files changed

+17
-3
lines changed

3 files changed

+17
-3
lines changed

test/Codec/Archive/Tar/Pack/Tests.hs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,9 @@ import qualified Data.ByteString.Lazy as BL
1616
import Data.FileEmbed
1717
import qualified Codec.Archive.Tar as Tar
1818
import qualified Codec.Archive.Tar.Pack as Pack
19-
import Codec.Archive.Tar.Types (GenEntries(..), Entries)
19+
import Codec.Archive.Tar.Types (GenEntries(..), Entries, simpleEntry, toTarPath)
2020
import qualified Codec.Archive.Tar.Unpack as Unpack
21+
import qualified Codec.Archive.Tar.Write as Write
2122
import Control.Exception
2223
import Data.List.NonEmpty (NonEmpty(..))
2324
import System.Directory

test/Codec/Archive/Tar/Tests.hs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,13 @@ module Codec.Archive.Tar.Tests (
1515
prop_write_read_ustar,
1616
prop_write_read_gnu,
1717
prop_write_read_v7,
18+
prop_large_filesize,
1819
) where
1920

2021
import Codec.Archive.Tar
2122
import Codec.Archive.Tar.Types
2223
import Codec.Archive.Tar.Types.Tests
24+
import qualified Data.ByteString.Lazy as BL
2325
import Prelude hiding (read)
2426
import Test.Tasty.QuickCheck
2527

@@ -40,3 +42,14 @@ prop_write_read_v7 entries =
4042
foldr Next Done entries' === read (write entries')
4143
where
4244
entries' = map limitToV7FormatCompat $ filter ((== V7Format) . entryFormat) entries
45+
46+
prop_large_filesize :: Word -> Property
47+
prop_large_filesize n = sz === sz'
48+
where
49+
sz = fromIntegral $ n * 1024 * 1024 * 128
50+
Right fn = toTarPath False "Large.file"
51+
entry = simpleEntry fn (NormalFile (BL.replicate sz 42) sz)
52+
-- Trim the tail so it does not blow up RAM
53+
tar = BL.take 2048 $ write [entry]
54+
Next entry' _ = read tar
55+
NormalFile _ sz' = entryContent entry'

test/Properties.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ main =
2727
, testGroup "write/read" [
2828
testProperty "ustar format" Tar.prop_write_read_ustar,
2929
testProperty "gnu format" Tar.prop_write_read_gnu,
30-
testProperty "v7 format" Tar.prop_write_read_v7
30+
testProperty "v7 format" Tar.prop_write_read_v7,
31+
testProperty "large filesize" Tar.prop_large_filesize
3132
]
3233

3334
, testGroup "string table" [
@@ -73,4 +74,3 @@ main =
7374
testProperty "modtime 1970-01-01" Unpack.case_modtime_1970
7475
]
7576
]
76-

0 commit comments

Comments
 (0)