Skip to content

Commit 4e224c3

Browse files
committed
tests: custom Arbitrary OutputsSpec producing nonempty OutputsSpec_Names
1 parent 91befa2 commit 4e224c3

File tree

3 files changed

+16
-19
lines changed

3 files changed

+16
-19
lines changed

hnix-store-tests/hnix-store-tests.cabal

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ library
5151
base >=4.12 && <5
5252
, hnix-store-core >= 0.8
5353
, bytestring
54+
, containers
5455
, crypton
5556
, dependent-sum > 0.7
5657
, generic-arbitrary < 1.1
@@ -80,7 +81,5 @@ test-suite props
8081
, hnix-store-core
8182
, hnix-store-tests
8283
, attoparsec
83-
, containers
84-
, QuickCheck
8584
, text
8685
, hspec

hnix-store-tests/src/System/Nix/Arbitrary/DerivedPath.hs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,19 @@
33
{-# OPTIONS_GHC -Wno-orphans #-}
44
module System.Nix.Arbitrary.DerivedPath where
55

6-
import Test.QuickCheck (Arbitrary)
6+
import qualified Data.Set
7+
import Test.QuickCheck (Arbitrary(..), oneof)
78
import Test.QuickCheck.Arbitrary.Generic (GenericArbitrary(..))
89
import System.Nix.Arbitrary.StorePath ()
9-
import System.Nix.DerivedPath (DerivedPath, OutputsSpec)
10+
import System.Nix.DerivedPath (DerivedPath, OutputsSpec(..))
1011

11-
deriving via GenericArbitrary OutputsSpec
12-
instance Arbitrary OutputsSpec
12+
instance Arbitrary OutputsSpec where
13+
arbitrary = oneof
14+
[ pure OutputsSpec_All
15+
, OutputsSpec_Names
16+
. Data.Set.fromList
17+
<$> ((:) <$> arbitrary <*> arbitrary)
18+
]
1319

1420
deriving via GenericArbitrary DerivedPath
1521
instance Arbitrary DerivedPath
Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,17 @@
11
module DerivedPathSpec where
22

3-
import Test.Hspec (Spec, describe, shouldBe)
3+
import Test.Hspec (Spec, describe)
44
import Test.Hspec.QuickCheck (prop)
5-
import Test.QuickCheck (Arbitrary(arbitrary), forAll, suchThat)
5+
import Test.Hspec.Nix (roundtrips)
66

77
import System.Nix.Arbitrary ()
8-
import System.Nix.DerivedPath (DerivedPath(..), OutputsSpec(..))
98

10-
import qualified Data.Set
119
import qualified System.Nix.DerivedPath
1210

1311
spec :: Spec
1412
spec = do
1513
describe "DerivedPath" $ do
1614
prop "roundtrips" $ \sd ->
17-
forAll (arbitrary `suchThat` nonEmptyOutputsSpec_Names) $ \p ->
18-
System.Nix.DerivedPath.parseDerivedPath sd
19-
(System.Nix.DerivedPath.derivedPathToText sd p)
20-
`shouldBe` pure p
21-
where
22-
nonEmptyOutputsSpec_Names :: DerivedPath -> Bool
23-
nonEmptyOutputsSpec_Names (DerivedPath_Built _ (OutputsSpec_Names set)) =
24-
not $ Data.Set.null set
25-
nonEmptyOutputsSpec_Names _ = True
15+
roundtrips
16+
(System.Nix.DerivedPath.derivedPathToText sd)
17+
(System.Nix.DerivedPath.parseDerivedPath sd)

0 commit comments

Comments
 (0)