Skip to content

Commit 20057c6

Browse files
committed
Add instance Arbitrary PkgBuildReports_v4
1 parent 772bb1f commit 20057c6

File tree

4 files changed

+29
-6
lines changed

4 files changed

+29
-6
lines changed

src/Distribution/Server/Features/BuildReports/BuildReport.hs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,16 @@ data BuildCovg = BuildCovg {
276276
topLevel :: (Int,Int)
277277
} deriving (Eq, Typeable, Show)
278278

279+
instance Arbitrary BuildCovg where
280+
arbitrary =
281+
BuildCovg
282+
<$> intPair
283+
<*> liftA3 BooleanCovg intPair intPair intPair
284+
<*> intPair
285+
<*> intPair
286+
<*> intPair
287+
where intPair = liftA2 (,) arbitrary arbitrary
288+
279289
instance MemSize BuildCovg where
280290
memSize (BuildCovg a (BooleanCovg b c d) e f g) = memSize7 a b c d e f g
281291

@@ -500,6 +510,10 @@ instance Arbitrary Outcome where
500510

501511
data BuildStatus = BuildOK | BuildFailCnt Int
502512
deriving (Eq, Ord, Typeable, Show)
513+
514+
instance Arbitrary BuildStatus where
515+
arbitrary = oneof [ pure BuildOK, BuildFailCnt <$> arbitrary ]
516+
503517
instance ToJSON BuildStatus where
504518
toJSON (BuildFailCnt a) = toJSON a
505519
toJSON BuildOK = toJSON ((-1)::Int)

src/Distribution/Server/Features/BuildReports/BuildReports.hs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
{-# LANGUAGE DeriveDataTypeable, GeneralizedNewtypeDeriving, TemplateHaskell,
22
TypeFamilies #-}
3-
{-# OPTIONS_GHC -fno-warn-orphans #-}
43
module Distribution.Server.Features.BuildReports.BuildReports (
54
BuildReport(..),
65
BuildReports(..),
7-
BuildReports_v3,
86
BuildReportId(..),
7+
PkgBuildReports_v4(..),
98
PkgBuildReports(..),
109
BuildLog(..),
1110
TestLog(..),
@@ -55,12 +54,13 @@ import Data.Typeable (Typeable)
5554
import qualified Data.List as L
5655
import qualified Data.Char as Char
5756
import Data.Maybe (fromMaybe)
57+
import Test.QuickCheck (Arbitrary(..))
5858

5959
import Text.StringTemplate (ToSElem(..))
6060

6161

6262
newtype BuildReportId = BuildReportId Int
63-
deriving (Eq, Ord, Typeable, Show, MemSize, Pretty)
63+
deriving (Eq, Ord, Typeable, Show, MemSize, Pretty, Arbitrary)
6464

6565
incrementReportId :: BuildReportId -> BuildReportId
6666
incrementReportId (BuildReportId n) = BuildReportId (n+1)
@@ -82,10 +82,10 @@ instance Parsec BuildReportId where
8282
f c = Char.ord c - Char.ord '0'
8383

8484
newtype BuildLog = BuildLog BlobStorage.BlobId
85-
deriving (Eq, Typeable, Show, MemSize)
85+
deriving (Eq, Typeable, Show, MemSize, Arbitrary)
8686

8787
newtype TestLog = TestLog BlobStorage.BlobId
88-
deriving (Eq, Typeable, Show, MemSize)
88+
deriving (Eq, Typeable, Show, MemSize, Arbitrary)
8989

9090
newtype TestReportLog = TestReportLog BlobStorage.BlobId
9191
deriving (Eq, Typeable, Show, MemSize)
@@ -307,6 +307,10 @@ data PkgBuildReports_v4 = PkgBuildReports_v4 {
307307
runTests_v4 :: !Bool
308308
} deriving (Eq, Typeable, Show)
309309

310+
instance Arbitrary PkgBuildReports_v4 where
311+
arbitrary = PkgBuildReports_v4 <$> arbitrary <*> arbitrary
312+
<*> arbitrary <*> arbitrary
313+
310314
instance SafeCopy PkgBuildReports_v4 where
311315
version = 4
312316
kind = extension

src/Distribution/Server/Features/Security/MD5.hs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import qualified Data.ByteString.Char8 as BS.Char8
2727
import qualified Data.ByteString.Lazy as BS.Lazy
2828
import Data.SafeCopy
2929
import qualified Data.Serialize as Ser
30+
import Test.QuickCheck (Arbitrary(..))
3031

3132
-- cryptohash
3233
import qualified Crypto.Hash.MD5 as MD5
@@ -39,6 +40,9 @@ import Distribution.Server.Util.ReadDigest
3940
data MD5Digest = MD5Digest {-# UNPACK #-} !Word64 {-# UNPACK #-} !Word64
4041
deriving (Eq,Ord)
4142

43+
instance Arbitrary MD5Digest where
44+
arbitrary = MD5Digest <$> arbitrary <*> arbitrary
45+
4246
instance NFData MD5Digest where
4347
rnf !_ = () -- 'MD5Digest' has only strict primitive fields, hence WHNF==NF
4448

src/Distribution/Server/Framework/BlobStorage.hs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ import System.Directory
5353
import System.IO
5454
import Data.Aeson
5555
import System.Posix.Files as Posix (createLink)
56+
import Test.QuickCheck (Arbitrary)
5657

5758
-- For fsync
5859
import System.Posix.Types (Fd(..))
@@ -71,7 +72,7 @@ import System.Posix.IO (
7172
-- | An id for a blob. The content of the blob is stable.
7273
--
7374
newtype BlobId = BlobId MD5Digest
74-
deriving (Eq, Ord, Show, Typeable, MemSize)
75+
deriving (Eq, Ord, Show, Typeable, MemSize, Arbitrary)
7576

7677
instance ToJSON BlobId where
7778
toJSON = toJSON . blobMd5

0 commit comments

Comments
 (0)