Skip to content

Commit 42f56f5

Browse files
committed
hnix-store-tests: init
Split from `-core` so it doesn't depend on quickcheck, generic-arbitrary and quickcheck-instances that could propagate downstrem. Also allows users to defined their own. With all roundtrip property tests. Later this should also absorb test nix-store/daemon harness from `-remote` so it can be reused by others.
1 parent 6a6bbaa commit 42f56f5

35 files changed

+613
-204
lines changed

cabal.project

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ packages:
22
./hnix-store-core/hnix-store-core.cabal
33
./hnix-store-db/hnix-store-db.cabal
44
./hnix-store-remote/hnix-store-remote.cabal
5+
./hnix-store-tests/hnix-store-tests.cabal
56

67
-- till https://github.com/obsidiansystems/dependent-sum/pull/80
78
allow-newer:

cabal.project.local.ci

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,6 @@ package hnix-store-db
88

99
package hnix-store-remote
1010
ghc-options: -Wunused-packages -Wall -Werror
11+
12+
package hnix-store-tests
13+
ghc-options: -Wunused-packages -Wall -Werror

default.nix

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ in {
2222
inherit (haskellPackages)
2323
hnix-store-core
2424
hnix-store-db
25-
hnix-store-remote;
25+
hnix-store-remote
26+
hnix-store-tests;
2627
haskellPackages = lib.dontRecurseIntoAttrs haskellPackages;
2728
pkgs = lib.dontRecurseIntoAttrs pkgs;
2829
}

hnix-store-core/hnix-store-core.cabal

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,6 @@ library
8989
, data-default-class
9090
, dependent-sum > 0.7
9191
, dependent-sum-template > 0.1.1 && < 0.3
92-
, generic-arbitrary < 1.1
9392
-- Required for cryptonite low-level type convertion
9493
, memory
9594
, cryptonite
@@ -100,8 +99,6 @@ library
10099
, monad-control
101100
, mtl
102101
, nix-derivation >= 1.1.1 && <2
103-
, QuickCheck
104-
, quickcheck-instances
105102
, saltine >= 0.2 && < 0.3
106103
, some > 1.0.5 && < 2
107104
, time
@@ -124,11 +121,8 @@ test-suite format-tests
124121
main-is: Driver.hs
125122
other-modules:
126123
Derivation
127-
DerivedPath
128-
ContentAddress
129124
NarFormat
130125
Hash
131-
StorePath
132126
hs-source-dirs:
133127
tests
134128
build-tool-depends:
@@ -147,7 +141,6 @@ test-suite format-tests
147141
, directory
148142
, filepath
149143
, process
150-
, nix-derivation >= 1.1.1 && <2
151144
, tasty
152145
, tasty-golden
153146
, hspec

hnix-store-core/src/System/Nix/Build.hs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
-- due to recent generic-arbitrary
2-
{-# OPTIONS_GHC -fconstraint-solver-iterations=0 #-}
31
{-|
42
Description : Build related types
53
Maintainer : srk <[email protected]>
@@ -14,15 +12,11 @@ module System.Nix.Build
1412
import Data.Time (UTCTime)
1513
import Data.Text (Text)
1614
import GHC.Generics (Generic)
17-
import Test.QuickCheck (Arbitrary(..))
18-
import Test.QuickCheck.Arbitrary.Generic (GenericArbitrary(..))
19-
import Test.QuickCheck.Instances ()
2015

2116
-- keep the order of these Enums to match enums from reference implementations
2217
-- src/libstore/store-api.hh
2318
data BuildMode = Normal | Repair | Check
2419
deriving (Eq, Generic, Ord, Enum, Show)
25-
deriving Arbitrary via GenericArbitrary BuildMode
2620

2721
data BuildStatus =
2822
Built
@@ -41,7 +35,6 @@ data BuildStatus =
4135
| ResolvesToAlreadyValid
4236
| NoSubstituters
4337
deriving (Eq, Generic, Ord, Enum, Show)
44-
deriving Arbitrary via GenericArbitrary BuildStatus
4538

4639
-- | Result of the build
4740
data BuildResult = BuildResult
@@ -59,7 +52,6 @@ data BuildResult = BuildResult
5952
stopTime :: !UTCTime
6053
}
6154
deriving (Eq, Generic, Ord, Show)
62-
deriving Arbitrary via GenericArbitrary BuildResult
6355

6456
buildSuccess :: BuildResult -> Bool
6557
buildSuccess BuildResult {..} =

hnix-store-core/src/System/Nix/ContentAddress.hs

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
module System.Nix.ContentAddress (
44
ContentAddress
5+
, ContentAddressMethod
6+
, FileIngestionMethod
57
, contentAddressBuilder
68
, contentAddressParser
79
, buildContentAddress
@@ -16,9 +18,6 @@ import Data.Text (Text)
1618
import Data.Text.Lazy.Builder (Builder)
1719
import GHC.Generics (Generic)
1820
import System.Nix.Hash (HashAlgo)
19-
import Test.QuickCheck (Arbitrary)
20-
import Test.QuickCheck.Arbitrary.Generic (GenericArbitrary(..))
21-
import Test.QuickCheck.Instances ()
2221

2322
import qualified Data.Attoparsec.Text
2423
import qualified Data.Text.Lazy
@@ -30,9 +29,6 @@ data FileIngestionMethod
3029
| FileRecursive
3130
deriving (Eq, Bounded, Generic, Enum, Ord, Show)
3231

33-
deriving via GenericArbitrary FileIngestionMethod
34-
instance Arbitrary FileIngestionMethod
35-
3632
data ContentAddressMethod
3733
= FileIngestionMethod !FileIngestionMethod
3834
-- ^ The path was added to the store via makeFixedOutputPath or
@@ -44,9 +40,6 @@ data ContentAddressMethod
4440
-- file contents.
4541
deriving (Eq, Generic, Ord, Show)
4642

47-
deriving via GenericArbitrary ContentAddressMethod
48-
instance Arbitrary ContentAddressMethod
49-
5043
-- | An address for a content-addressable store path, i.e. one whose
5144
-- store path hash is purely a function of its contents (as opposed to
5245
-- paths that are derivation outputs, whose hashes are a function of
@@ -61,9 +54,6 @@ data ContentAddress = ContentAddress
6154
(DSum HashAlgo Digest)
6255
deriving (Eq, Generic, Ord, Show)
6356

64-
deriving via GenericArbitrary ContentAddress
65-
instance Arbitrary ContentAddress
66-
6757
-- | Marshall `ContentAddressableAddress` to `Text`
6858
-- in form suitable for remote protocol usage.
6959
buildContentAddress :: ContentAddress -> Text

hnix-store-core/src/System/Nix/Derivation.hs

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
-- due to recent generic-arbitrary
2-
{-# OPTIONS_GHC -Wno-orphans -fconstraint-solver-iterations=0 #-}
3-
41
module System.Nix.Derivation
52
( parseDerivation
63
, buildDerivation
@@ -12,9 +9,6 @@ module System.Nix.Derivation
129
import Data.Attoparsec.Text.Lazy (Parser)
1310
import Data.Text (Text)
1411
import Data.Text.Lazy.Builder (Builder)
15-
import Test.QuickCheck (Arbitrary(..))
16-
import Test.QuickCheck.Arbitrary.Generic (GenericArbitrary(..))
17-
import Test.QuickCheck.Instances ()
1812

1913
import Nix.Derivation (Derivation(..), DerivationOutput(..))
2014
import System.Nix.StorePath (StoreDir, StorePath)
@@ -27,11 +21,6 @@ import qualified Data.Text.Lazy.Builder
2721
import qualified Nix.Derivation
2822
import qualified System.Nix.StorePath
2923

30-
deriving via GenericArbitrary (Derivation StorePath Text)
31-
instance Arbitrary (Derivation StorePath Text)
32-
deriving via GenericArbitrary (DerivationOutput StorePath Text)
33-
instance Arbitrary (DerivationOutput StorePath Text)
34-
3524
parseDerivation :: StoreDir -> Parser (Derivation StorePath Text)
3625
parseDerivation expectedRoot =
3726
Nix.Derivation.parseDerivationWith

hnix-store-core/src/System/Nix/DerivedPath.hs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@ import GHC.Generics (Generic)
1414
import Data.Set (Set)
1515
import Data.Text (Text)
1616
import System.Nix.StorePath (StoreDir, StorePath, StorePathName, InvalidPathError)
17-
import Test.QuickCheck (Arbitrary)
18-
import Test.QuickCheck.Arbitrary.Generic (GenericArbitrary(..))
1917

2018
import qualified Data.Set
2119
import qualified Data.Text
@@ -26,17 +24,11 @@ data OutputsSpec =
2624
| OutputsSpec_Names (Set StorePathName)
2725
deriving (Eq, Generic, Ord, Show)
2826

29-
deriving via GenericArbitrary OutputsSpec
30-
instance Arbitrary OutputsSpec
31-
3227
data DerivedPath =
3328
DerivedPath_Opaque StorePath
3429
| DerivedPath_Built StorePath OutputsSpec
3530
deriving (Eq, Generic, Ord, Show)
3631

37-
deriving via GenericArbitrary DerivedPath
38-
instance Arbitrary DerivedPath
39-
4032
data ParseOutputsError =
4133
ParseOutputsError_InvalidPath InvalidPathError
4234
| ParseOutputsError_NoNames

hnix-store-core/src/System/Nix/Hash.hs

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,6 @@ import Data.Some (Some(Some))
3737
import Data.Text (Text)
3838
import Data.Text.Lazy.Builder (Builder)
3939
import System.Nix.Base (BaseEncoding(..))
40-
import Test.QuickCheck (Arbitrary(arbitrary), oneof)
41-
import Test.QuickCheck.Instances ()
4240

4341
import qualified Crypto.Hash
4442
import qualified Data.ByteArray
@@ -64,20 +62,6 @@ instance NamedAlgo SHA256 where
6462
instance NamedAlgo SHA512 where
6563
algoName = "sha512"
6664

67-
-- * Arbitrary @Digest@s
68-
69-
instance Arbitrary (Digest MD5) where
70-
arbitrary = Crypto.Hash.hash @ByteString <$> arbitrary
71-
72-
instance Arbitrary (Digest SHA1) where
73-
arbitrary = Crypto.Hash.hash @ByteString <$> arbitrary
74-
75-
instance Arbitrary (Digest SHA256) where
76-
arbitrary = Crypto.Hash.hash @ByteString <$> arbitrary
77-
78-
instance Arbitrary (Digest SHA512) where
79-
arbitrary = Crypto.Hash.hash @ByteString <$> arbitrary
80-
8165
data HashAlgo :: Type -> Type where
8266
HashAlgo_MD5 :: HashAlgo MD5
8367
HashAlgo_SHA1 :: HashAlgo SHA1
@@ -107,14 +91,6 @@ textToAlgo = \case
10791
"sha512" -> Right $ Some HashAlgo_SHA512
10892
name -> Left $ "Unknown hash name: " <> Data.Text.unpack name
10993

110-
instance Arbitrary (DSum HashAlgo Digest) where
111-
arbitrary = oneof
112-
[ (HashAlgo_MD5 :=>) <$> arbitrary
113-
, (HashAlgo_SHA1 :=>) <$> arbitrary
114-
, (HashAlgo_SHA256 :=>) <$> arbitrary
115-
, (HashAlgo_SHA512 :=>) <$> arbitrary
116-
]
117-
11894
-- | Make @DSum HashAlgo Digest@ based on provided SRI hash name
11995
-- and its encoded form
12096
mkNamedDigest

hnix-store-core/src/System/Nix/StorePath.hs

Lines changed: 1 addition & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
{-# LANGUAGE AllowAmbiguousTypes #-}
2-
{-# LANGUAGE CPP #-}
32
{-# LANGUAGE DeriveAnyClass #-}
43
{-# LANGUAGE OverloadedStrings #-}
54
{-|
@@ -32,19 +31,15 @@ module System.Nix.StorePath
3231
, pathParser
3332
) where
3433

35-
#if !MIN_VERSION_base(4,18,0)
36-
import Control.Applicative (liftA2)
37-
#endif
3834
import Control.Monad.Reader.Class (MonadReader, asks)
39-
import Crypto.Hash (HashAlgorithm, SHA256)
35+
import Crypto.Hash (HashAlgorithm)
4036
import Data.Attoparsec.Text.Lazy (Parser, (<?>))
4137
import Data.ByteString (ByteString)
4238
import Data.Default.Class (Default(def))
4339
import Data.Hashable (Hashable(hashWithSalt))
4440
import Data.Text (Text)
4541
import GHC.Generics (Generic)
4642
import System.Nix.Base (BaseEncoding(NixBase32))
47-
import Test.QuickCheck (Arbitrary(arbitrary), listOf, elements)
4843

4944
import qualified Data.Bifunctor
5045
import qualified Data.ByteString.Char8
@@ -81,12 +76,6 @@ instance Hashable StorePath where
8176
hashWithSalt s StorePath{..} =
8277
s `hashWithSalt` storePathHash `hashWithSalt` storePathName
8378

84-
instance Arbitrary StorePath where
85-
arbitrary =
86-
liftA2 StorePath
87-
arbitrary
88-
arbitrary
89-
9079
-- | The name portion of a Nix path.
9180
--
9281
-- 'unStorePathName' must only contain a-zA-Z0-9+._?=-, can't start
@@ -97,25 +86,13 @@ newtype StorePathName = StorePathName
9786
unStorePathName :: Text
9887
} deriving (Eq, Generic, Hashable, Ord, Show)
9988

100-
instance Arbitrary StorePathName where
101-
arbitrary = StorePathName . Data.Text.pack <$> ((:) <$> s1 <*> listOf sn)
102-
where
103-
alphanum = ['a' .. 'z'] <> ['A' .. 'Z'] <> ['0' .. '9']
104-
s1 = elements $ alphanum <> "+-_?="
105-
sn = elements $ alphanum <> "+-._?="
106-
10789
-- | The hash algorithm used for store path hashes.
10890
newtype StorePathHashPart = StorePathHashPart
10991
{ -- | Extract the contents of the hash.
11092
unStorePathHashPart :: ByteString
11193
}
11294
deriving (Eq, Generic, Hashable, Ord, Show)
11395

114-
instance Arbitrary StorePathHashPart where
115-
arbitrary =
116-
mkStorePathHashPart @SHA256
117-
. Data.ByteString.Char8.pack <$> arbitrary
118-
11996
-- | Make @StorePathHashPart@ from @ByteString@ (hash part of the @StorePath@)
12097
-- using specific @HashAlgorithm@
12198
mkStorePathHashPart
@@ -183,12 +160,6 @@ newtype StoreDir = StoreDir {
183160
unStoreDir :: RawFilePath
184161
} deriving (Eq, Generic, Hashable, Ord, Show)
185162

186-
instance Arbitrary StoreDir where
187-
arbitrary =
188-
StoreDir
189-
. ("/" <>) -- TODO(srk): nasty, see #237
190-
. Data.ByteString.Char8.pack <$> arbitrary
191-
192163
instance Default StoreDir where
193164
def = StoreDir "/nix/store"
194165

0 commit comments

Comments
 (0)