@@ -1,45 +1,56 @@
1+{-# LANGUAGE DerivingStrategies #-}
2+{-# LANGUAGE DerivingVia #-}
3+{-# LANGUAGE DeriveAnyClass #-}
4+{-# OPTIONS_GHC -fconstraint-solver-iterations=5 #-} -- GHC-9.2.4
5+
16-- | Testing that our Arbitrary instances do not get stuck and respect the
27-- `size` parameter while generating.
38
49module RecursiveTest where
510
6−import Control.DeepSeq
11+import Control.DeepSeq (NFData)
712import GHC.Generics (Generic)
813import Test.QuickCheck
914import Test.QuickCheck.Arbitrary.Generic
1015
1116data Unit = Unit
1217 deriving (Eq, Show, Generic)
13−
14−instance NFData Unit
15−
18+ deriving anyclass NFData
19+#if MIN_VERSION_QuickCheck(2, 14, 0)
20+ deriving Arbitrary via (GenericArbitrary Unit)
21+#else
1622instance Arbitrary Unit where
1723 arbitrary = genericArbitrary
1824 shrink = genericShrink
25+#endif
1926
2027prop_unitTotal :: Unit -> Property
2128prop_unitTotal = total
2229
2330data Single = Single Int
2431 deriving (Eq, Show, Generic)
25−
26−instance NFData Single
27−
32+ deriving anyclass NFData
33+#if MIN_VERSION_QuickCheck(2, 14, 0)
34+ deriving Arbitrary via (GenericArbitrary Single)
35+#else
2836instance Arbitrary Single where
2937 arbitrary = genericArbitrary
3038 shrink = genericShrink
39+#endif
3140
3241prop_singleTotal :: Single -> Property
3342prop_singleTotal = total
3443
3544data Multiple = M1 | M2 | M3 Int
3645 deriving (Eq, Show, Generic)
37−
38−instance NFData Multiple
39−
46+ deriving anyclass NFData
47+#if MIN_VERSION_QuickCheck(2, 14, 0)
48+ deriving Arbitrary via (GenericArbitrary Multiple)
49+#else
4050instance Arbitrary Multiple where
4151 arbitrary = genericArbitrary
4252 shrink = genericShrink
53+#endif
4354
4455prop_multipleTotal :: Multiple -> Property
4556prop_multipleTotal = total
@@ -49,12 +60,14 @@ data Rec = Rec
4960 , single :: Single
5061 , multiple :: Multiple
5162 } deriving (Eq, Show, Generic)
52−
53−instance NFData Rec
54−
63+ deriving anyclass NFData
64+#if MIN_VERSION_QuickCheck(2, 14, 0)
65+ deriving Arbitrary via (GenericArbitrary Rec)
66+#else
5567instance Arbitrary Rec where
5668 arbitrary = genericArbitrary
5769 shrink = genericShrink
70+#endif
5871
5972prop_recTotal :: Rec -> Property
6073prop_recTotal = total
@@ -64,13 +77,14 @@ data Expr
6477 | Add Expr Expr
6578 | Mul Expr Expr
6679 deriving (Eq, Show, Generic)
67−
68−-- | Instance with may fall into infinite loop
80+ deriving anyclass NFData
81+#if MIN_VERSION_QuickCheck(2, 14, 0)
82+ deriving Arbitrary via (GenericArbitrary Expr)
83+#else
6984instance Arbitrary Expr where
7085 arbitrary = genericArbitrary
7186 shrink = genericShrink
72−
73−instance NFData Expr
87+#endif
7488
7589prop_exprTotal :: Expr -> Property
7690prop_exprTotal = total
@@ -83,12 +97,14 @@ data Recursive
8397 | R4 Recursive
8498 | R5 Recursive String
8599 deriving (Eq, Show, Generic)
86−
87−instance NFData Recursive
88−
100+ deriving anyclass NFData
101+#if MIN_VERSION_QuickCheck(2, 14, 0)
102+ deriving Arbitrary via (GenericArbitrary Recursive)
103+#else
89104instance Arbitrary Recursive where
90105 arbitrary = genericArbitrary
91106 shrink = genericShrink
107+#endif
92108
93109prop_recursiveTotal :: Recursive -> Property
94110prop_recursiveTotal = total
@@ -97,21 +113,23 @@ data DeepRecursive
97113 = Deep DeepRecursive DeepRecursive DeepRecursive DeepRecursive DeepRecursive
98114 | Short
99115 deriving (Eq, Show, Generic)
100−
101−instance NFData DeepRecursive
102−
116+ deriving anyclass NFData
117+#if MIN_VERSION_QuickCheck(2, 14, 0)
118+ deriving Arbitrary via (GenericArbitrary DeepRecursive)
119+#else
103120instance Arbitrary DeepRecursive where
104121 arbitrary = genericArbitrary
105122 shrink = genericShrink
123+#endif
106124
107125prop_deepRecursiveTotal :: DeepRecursive -> Property
108126prop_deepRecursiveTotal = total
109127
110128data P p = NoP | P p
111129 deriving (Eq, Show, Generic)
130+ deriving anyclass NFData
112131
113−instance (NFData p) => NFData (P p)
114−
132+-- Note that deriving via doesn't work for case with arguments
115133instance (Arg (P p) p, Arbitrary p) => Arbitrary (P p) where
116134 arbitrary = genericArbitrary
117135 shrink = genericShrink