Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Reorder Arbitrary instance definitions
Citing the GHC 9.0.1 changelog[1]:

  Breaking change: Template Haskell splices now act as separation points
  between constraint solving passes. It is no longer possible to use an
  instance of a class before a splice and define that instance after a
  splice. For example, this code now reports a missing instance for C
  Bool:

    ```
    class C a where foo :: a
    bar :: Bool
    bar = foo
    $(return [])
    instance C Bool where foo = True
    ```

In other words, code order matters in Template Haskell files, which
breaks the Haskell test build with GHC >= 9.0.1. Fix this by reordering
various Arbitrary instances so that they are defined before being used.

Also the Arbitrary instance for IAllocatorParams was silently acting as
a generic instance for (Container JSValue), providing instances for
DiskParams, HypervisorState and DiskState as well. Change the Arbitrary
instance declaration to Arbitrary (Container JSValue) to better reflect
its generic purpose.

[1] https://downloads.haskell.org/ghc/9.0.1/docs/html/users_guide/9.0.1-notes.html#highlights

Signed-off-by: Apollon Oikonomopoulos <apoikos@dmesg.gr>
  • Loading branch information
apoikos committed Mar 7, 2023
1 parent 5e30bad commit feab8fa
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
20 changes: 10 additions & 10 deletions test/hs/Test/Ganeti/Objects.hs
Expand Up @@ -93,8 +93,14 @@ instance Arbitrary (Container DataCollectorConfig) where
instance Arbitrary BS.ByteString where
arbitrary = genPrintableByteString

instance Arbitrary a => Arbitrary (Private a) where
arbitrary = Private <$> arbitrary

$(genArbitrary ''PartialNDParams)

instance Arbitrary (Container J.JSValue) where
arbitrary = return $ GenericContainer Map.empty

instance Arbitrary Node where
arbitrary = Node <$> genFQDN <*> genFQDN <*> genFQDN
<*> arbitrary <*> arbitrary <*> arbitrary <*> genFQDN
Expand Down Expand Up @@ -297,10 +303,6 @@ genDisk = genDiskWithChildren 3
-- validation rules.
$(genArbitrary ''PartialISpecParams)

-- | FIXME: This generates completely random data, without normal
-- validation rules.
$(genArbitrary ''PartialIPolicy)

$(genArbitrary ''FilledISpecParams)
$(genArbitrary ''MinMaxISpecs)
$(genArbitrary ''FilledIPolicy)
Expand All @@ -309,6 +311,10 @@ $(genArbitrary ''FilledNDParams)
$(genArbitrary ''FilledNicParams)
$(genArbitrary ''FilledBeParams)

-- | FIXME: This generates completely random data, without normal
-- validation rules.
$(genArbitrary ''PartialIPolicy)

-- | No real arbitrary instance for 'ClusterHvParams' yet.
instance Arbitrary ClusterHvParams where
arbitrary = return $ GenericContainer Map.empty
Expand All @@ -331,18 +337,12 @@ instance Arbitrary OsParams where
instance Arbitrary Objects.ClusterOsParamsPrivate where
arbitrary = (GenericContainer . Map.fromList) <$> arbitrary

instance Arbitrary a => Arbitrary (Private a) where
arbitrary = Private <$> arbitrary

instance Arbitrary ClusterOsParams where
arbitrary = (GenericContainer . Map.fromList) <$> arbitrary

instance Arbitrary ClusterBeParams where
arbitrary = (GenericContainer . Map.fromList) <$> arbitrary

instance Arbitrary IAllocatorParams where
arbitrary = return $ GenericContainer Map.empty

$(genArbitrary ''Cluster)

instance Arbitrary ConfigData where
Expand Down
6 changes: 3 additions & 3 deletions test/hs/Test/Ganeti/Query/Language.hs
Expand Up @@ -59,6 +59,9 @@ import Ganeti.Query.Language
instance Arbitrary (Filter FilterField) where
arbitrary = genFilter

instance Arbitrary FilterRegex where
arbitrary = genName >>= mkRegex -- a name should be a good regex

-- | Custom 'Filter' generator (top-level), which enforces a
-- (sane) limit on the depth of the generated filters.
genFilter :: Gen (Filter FilterField)
Expand Down Expand Up @@ -97,9 +100,6 @@ $(genArbitrary ''QueryTypeLuxi)

$(genArbitrary ''ItemType)

instance Arbitrary FilterRegex where
arbitrary = genName >>= mkRegex -- a name should be a good regex

$(genArbitrary ''ResultStatus)

$(genArbitrary ''FieldType)
Expand Down

0 comments on commit feab8fa

Please sign in to comment.