on master help sign in
Get the test suite working with GHC 7.0 again
commitf2589c3dc87e864d375ca9b3136dad1705301282 authorBryan O'Sullivan <bos@serpentine.com> dateWed 4 Sep 2013, 11:22 (13 years ago) parent7ab286f
5 files changed+50−18
aeson.cabal+2 tests/Encoders.hs+5−1 tests/Instances.hs+4−1 tests/Properties.hs+12−5 tests/Types.hs+27−11
aeson.cabal+2
@@ -150,6 +150,8 @@ test-suite tests
150150 -Wall -threaded -rtsopts
151151 if impl(ghc < 7.4)
152152 ghc-options: -fcontext-stack=40
153+ if impl(ghc >= 7.2)
154+ ghc-options: -DGHC_GENERICS
153155
154156 build-depends:
155157 QuickCheck,
tests/Encoders.hs+5−1
@@ -1,4 +1,4 @@
1−{-# Language TemplateHaskell #-}
1+{-# Language CPP, TemplateHaskell #-}
22
33module Encoders where
44
@@ -38,6 +38,7 @@ thNullaryToJSONObjectWithSingleField = $(mkToJSON optsObjectWithSingleField ''Nu
3838thNullaryParseJSONObjectWithSingleField :: Value -> Parser Nullary
3939thNullaryParseJSONObjectWithSingleField = $(mkParseJSON optsObjectWithSingleField ''Nullary)
4040
41+#ifdef GHC_GENERICS
4142gNullaryToJSONString :: Nullary -> Value
4243gNullaryToJSONString = genericToJSON defaultOptions
4344
@@ -64,6 +65,7 @@ gNullaryToJSONObjectWithSingleField = genericToJSON optsObjectWithSingleField
6465
6566gNullaryParseJSONObjectWithSingleField :: Value -> Parser Nullary
6667gNullaryParseJSONObjectWithSingleField = genericParseJSON optsObjectWithSingleField
68+#endif
6769
6870
6971--------------------------------------------------------------------------------
@@ -93,6 +95,7 @@ thSomeTypeParseJSONObjectWithSingleField :: FromJSON a => Value -> Parser (SomeT
9395thSomeTypeParseJSONObjectWithSingleField = $(mkParseJSON optsObjectWithSingleField ''SomeType)
9496
9597
98+#ifdef GHC_GENERICS
9699gSomeTypeToJSON2ElemArray :: ToJSON a => SomeType a -> Value
97100gSomeTypeToJSON2ElemArray = genericToJSON opts2ElemArray
98101
@@ -112,3 +115,4 @@ gSomeTypeToJSONObjectWithSingleField = genericToJSON optsObjectWithSingleField
112115
113116gSomeTypeParseJSONObjectWithSingleField :: FromJSON a => Value -> Parser (SomeType a)
114117gSomeTypeParseJSONObjectWithSingleField = genericParseJSON optsObjectWithSingleField
118+#endif
tests/Instances.hs+4−1
@@ -1,5 +1,8 @@
1−{-# Language OverloadedStrings, RecordWildCards, StandaloneDeriving #-}
1+{-# Language CPP, OverloadedStrings, RecordWildCards, StandaloneDeriving #-}
22{-# OPTIONS_GHC -fno-warn-orphans #-}
3+#if __GLASGOW_HASKELL__ < 702
4+{-# OPTIONS_GHC -fno-warn-missing-methods #-}
5+#endif
36
47module Instances where
58
tests/Properties.hs+12−5
@@ -1,10 +1,9 @@
1−{-# LANGUAGE OverloadedStrings, RecordWildCards, ScopedTypeVariables #-}
1+{-# LANGUAGE CPP, OverloadedStrings, RecordWildCards, ScopedTypeVariables #-}
22
33import Data.Aeson.Encode
44import Data.Aeson.Parser (value)
55import Data.Aeson.Types
66import Data.Attoparsec.Number
7−import Data.Int
87import Test.Framework (Test, defaultMain, testGroup)
98import Test.Framework.Providers.QuickCheck2 (testProperty)
109import Test.QuickCheck (Arbitrary(..))
@@ -12,15 +11,17 @@ import qualified Data.Vector as V
1211import qualified Data.Attoparsec.Lazy as L
1312import qualified Data.ByteString.Lazy.Char8 as L
1413import qualified Data.Text as T
15−import qualified Data.Map as Map
1614import qualified Data.HashMap.Strict as H
1715import Data.Time.Clock (UTCTime(..))
1816import Data.Time (ZonedTime(..))
19−import Types (Foo(..))
2017import Instances ()
21−import Types (Approx(..), OneConstructor(..), Product2, Product6, Sum4)
18+import Types
2219import Encoders
2320import Properties.Deprecated (deprecatedTests)
21+#ifdef GHC_GENERICS
22+import Data.Int
23+import qualified Data.Map as Map
24+#endif
2425
2526
2627encodeDouble :: Double -> Double -> Bool
@@ -63,8 +64,10 @@ modifyFailureProp orig added =
6364main :: IO ()
6465main = defaultMain tests
6566
67+#ifdef GHC_GENERICS
6668type P6 = Product6 Int Bool String (Approx Double) (Int, Approx Double) ()
6769type S4 = Sum4 Int8 ZonedTime T.Text (Map.Map String Int)
70+#endif
6871
6972--------------------------------------------------------------------------------
7073-- Value properties
@@ -110,12 +113,14 @@ tests = [
110113 , testProperty "DotNetTime" $ roundTripEq (undefined :: Approx DotNetTime)
111114 , testProperty "UTCTime" $ roundTripEq (undefined :: Approx UTCTime)
112115 , testProperty "ZonedTime" $ roundTripEq (undefined::ZonedTime)
116+#ifdef GHC_GENERICS
113117 , testGroup "ghcGenerics" [
114118 testProperty "OneConstructor" $ roundTripEq OneConstructor
115119 , testProperty "Product2" $ roundTripEq (undefined :: Product2 Int Bool)
116120 , testProperty "Product6" $ roundTripEq (undefined :: P6)
117121 , testProperty "Sum4" $ roundTripEq (undefined :: S4)
118122 ]
123+#endif
119124 ],
120125 testGroup "toFromJSON" [
121126 testProperty "Integer" (toFromJSON :: Integer -> Bool)
@@ -154,6 +159,7 @@ tests = [
154159 ]
155160 ]
156161 ]
162+#ifdef GHC_GENERICS
157163 , testGroup "GHC-generics" [
158164 testGroup "Nullary" [
159165 testProperty "string" (isString . gNullaryToJSONString)
@@ -190,4 +196,5 @@ tests = [
190196 ]
191197 ]
192198 ]
199+#endif
193200 ]
tests/Types.hs+27−11
@@ -1,12 +1,16 @@
1−{-# LANGUAGE DeriveDataTypeable, DeriveGeneric,
2− GeneralizedNewtypeDeriving #-}
1+{-# LANGUAGE CPP, DeriveDataTypeable, GeneralizedNewtypeDeriving #-}
2+#ifdef GHC_GENERICS
3+{-# LANGUAGE DeriveGeneric, StandaloneDeriving #-}
4+#endif
35
46module Types where
57
68import qualified Data.Map as Map
79import Data.Data
810import Data.Text
11+#ifdef GHC_GENERICS
912import GHC.Generics
13+#endif
1014
1115data Foo = Foo {
1216 fooInt :: Int
@@ -15,35 +19,35 @@ data Foo = Foo {
1519 -- This definition causes an infinite loop in genericTo and genericFrom!
1620 -- , fooMap :: Map.Map String Foo
1721 , fooMap :: Map.Map String (Text,Int)
18− } deriving (Show, Typeable, Data, Generic)
22+ } deriving (Show, Typeable, Data)
1923
2024data UFoo = UFoo {
2125 _UFooInt :: Int
2226 , uFooInt :: Int
23− } deriving (Show, Eq, Data, Typeable, Generic)
27+ } deriving (Show, Eq, Data, Typeable)
2428
2529data OneConstructor = OneConstructor
26− deriving (Show, Eq, Typeable, Data, Generic)
30+ deriving (Show, Eq, Typeable, Data)
2731
2832data Product2 a b = Product2 a b
29− deriving (Show, Eq, Typeable, Data, Generic)
33+ deriving (Show, Eq, Typeable, Data)
3034
3135data Product6 a b c d e f = Product6 a b c d e f
32− deriving (Show, Eq, Typeable, Data, Generic)
36+ deriving (Show, Eq, Typeable, Data)
3337
3438data Sum4 a b c d = Alt1 a | Alt2 b | Alt3 c | Alt4 d
35− deriving (Show, Eq, Typeable, Data, Generic)
39+ deriving (Show, Eq, Typeable, Data)
3640
3741class ApproxEq a where
3842 (=~) :: a -> a -> Bool
3943
4044newtype Approx a = Approx { fromApprox :: a }
41− deriving (Show, Data, Typeable, Generic, ApproxEq, Num)
45+ deriving (Show, Data, Typeable, ApproxEq, Num)
4246
4347instance (ApproxEq a) => Eq (Approx a) where
4448 Approx a == Approx b = a =~ b
4549
46−data Nullary = C1 | C2 | C3 deriving (Eq, Show, Generic)
50+data Nullary = C1 | C2 | C3 deriving (Eq, Show)
4751
4852data SomeType a = Nullary
4953 | Unary Int
@@ -51,4 +55,16 @@ data SomeType a = Nullary
5155 | Record { testOne :: Double
5256 , testTwo :: Maybe Bool
5357 , testThree :: Maybe a
54− } deriving (Eq, Show, Generic)
58+ } deriving (Eq, Show)
59+
60+#ifdef GHC_GENERICS
61+deriving instance Generic Foo
62+deriving instance Generic UFoo
63+deriving instance Generic OneConstructor
64+deriving instance Generic (Product2 a b)
65+deriving instance Generic (Product6 a b c d e f)
66+deriving instance Generic (Sum4 a b c d)
67+deriving instance Generic (Approx a)
68+deriving instance Generic Nullary
69+deriving instance Generic (SomeType a)
70+#endif