Commits

Bryan O'Sullivan  committed c153037

Get the test suite working with GHC 7.0 again

  • Participants
  • Parent commits 86798c5

Comments (0)

Files changed (5)

     -Wall -threaded -rtsopts
   if impl(ghc < 7.4)
     ghc-options: -fcontext-stack=40
+  if impl(ghc >= 7.2)
+    ghc-options: -DGHC_GENERICS
 
   build-depends:
     QuickCheck,

File tests/Encoders.hs

-{-# Language TemplateHaskell #-}
+{-# Language CPP, TemplateHaskell #-}
 
 module Encoders where
 
 thNullaryParseJSONObjectWithSingleField :: Value -> Parser Nullary
 thNullaryParseJSONObjectWithSingleField = $(mkParseJSON optsObjectWithSingleField ''Nullary)
 
+#ifdef GHC_GENERICS
 gNullaryToJSONString :: Nullary -> Value
 gNullaryToJSONString = genericToJSON defaultOptions
 
 
 gNullaryParseJSONObjectWithSingleField :: Value -> Parser Nullary
 gNullaryParseJSONObjectWithSingleField = genericParseJSON optsObjectWithSingleField
+#endif
 
 
 --------------------------------------------------------------------------------
 thSomeTypeParseJSONObjectWithSingleField = $(mkParseJSON optsObjectWithSingleField ''SomeType)
 
 
+#ifdef GHC_GENERICS
 gSomeTypeToJSON2ElemArray :: ToJSON a => SomeType a -> Value
 gSomeTypeToJSON2ElemArray = genericToJSON opts2ElemArray
 
 
 gSomeTypeParseJSONObjectWithSingleField :: FromJSON a => Value -> Parser (SomeType a)
 gSomeTypeParseJSONObjectWithSingleField = genericParseJSON optsObjectWithSingleField
+#endif

File tests/Instances.hs

-{-# Language OverloadedStrings, RecordWildCards, StandaloneDeriving #-}
+{-# Language CPP, OverloadedStrings, RecordWildCards, StandaloneDeriving #-}
 {-# OPTIONS_GHC -fno-warn-orphans #-}
+#if __GLASGOW_HASKELL__ < 702
+{-# OPTIONS_GHC -fno-warn-missing-methods #-}
+#endif
 
 module Instances where
 

File tests/Properties.hs

-{-# LANGUAGE OverloadedStrings, RecordWildCards, ScopedTypeVariables #-}
+{-# LANGUAGE CPP, OverloadedStrings, RecordWildCards, ScopedTypeVariables #-}
 
 import Data.Aeson.Encode
 import Data.Aeson.Parser (value)
 import Data.Aeson.Types
 import Data.Attoparsec.Number
-import Data.Int
 import Test.Framework (Test, defaultMain, testGroup)
 import Test.Framework.Providers.QuickCheck2 (testProperty)
 import Test.QuickCheck (Arbitrary(..))
 import qualified Data.Attoparsec.Lazy as L
 import qualified Data.ByteString.Lazy.Char8 as L
 import qualified Data.Text as T
-import qualified Data.Map as Map
 import qualified Data.HashMap.Strict as H
 import Data.Time.Clock (UTCTime(..))
 import Data.Time (ZonedTime(..))
-import Types (Foo(..))
 import Instances ()
-import Types (Approx(..), OneConstructor(..), Product2, Product6, Sum4)
+import Types
 import Encoders
 import Properties.Deprecated (deprecatedTests)
+#ifdef GHC_GENERICS
+import Data.Int
+import qualified Data.Map as Map
+#endif
 
 
 encodeDouble :: Double -> Double -> Bool
 main :: IO ()
 main = defaultMain tests
 
+#ifdef GHC_GENERICS
 type P6 = Product6 Int Bool String (Approx Double) (Int, Approx Double) ()
 type S4 = Sum4 Int8 ZonedTime T.Text (Map.Map String Int)
+#endif
 
 --------------------------------------------------------------------------------
 -- Value properties
     , testProperty "DotNetTime" $ roundTripEq (undefined :: Approx DotNetTime)
     , testProperty "UTCTime" $ roundTripEq (undefined :: Approx UTCTime)
     , testProperty "ZonedTime" $ roundTripEq (undefined::ZonedTime)
+#ifdef GHC_GENERICS
     , testGroup "ghcGenerics" [
         testProperty "OneConstructor" $ roundTripEq OneConstructor
       , testProperty "Product2" $ roundTripEq (undefined :: Product2 Int Bool)
       , testProperty "Product6" $ roundTripEq (undefined :: P6)
       , testProperty "Sum4" $ roundTripEq (undefined :: S4)
       ]
+#endif
     ],
   testGroup "toFromJSON" [
       testProperty "Integer" (toFromJSON :: Integer -> Bool)
           ]
       ]
     ]
+#ifdef GHC_GENERICS
   , testGroup "GHC-generics" [
         testGroup "Nullary" [
             testProperty "string"                (isString                . gNullaryToJSONString)
           ]
       ]
     ]
+#endif
   ]

File tests/Types.hs

-{-# LANGUAGE DeriveDataTypeable, DeriveGeneric,
-    GeneralizedNewtypeDeriving #-}
+{-# LANGUAGE CPP, DeriveDataTypeable, GeneralizedNewtypeDeriving #-}
+#ifdef GHC_GENERICS
+{-# LANGUAGE DeriveGeneric, StandaloneDeriving #-}
+#endif
 
 module Types where
 
 import qualified Data.Map as Map
 import Data.Data
 import Data.Text
+#ifdef GHC_GENERICS
 import GHC.Generics
+#endif
 
 data Foo = Foo {
       fooInt :: Int
     -- This definition causes an infinite loop in genericTo and genericFrom!
     -- , fooMap :: Map.Map String Foo
     , fooMap :: Map.Map String (Text,Int)
-    } deriving (Show, Typeable, Data, Generic)
+    } deriving (Show, Typeable, Data)
 
 data UFoo = UFoo {
       _UFooInt :: Int
     , uFooInt :: Int
-    } deriving (Show, Eq, Data, Typeable, Generic)
+    } deriving (Show, Eq, Data, Typeable)
 
 data OneConstructor = OneConstructor
-                      deriving (Show, Eq, Typeable, Data, Generic)
+                      deriving (Show, Eq, Typeable, Data)
 
 data Product2 a b = Product2 a b
-                    deriving (Show, Eq, Typeable, Data, Generic)
+                    deriving (Show, Eq, Typeable, Data)
 
 data Product6 a b c d e f = Product6 a b c d e f
-                    deriving (Show, Eq, Typeable, Data, Generic)
+                    deriving (Show, Eq, Typeable, Data)
 
 data Sum4 a b c d = Alt1 a | Alt2 b | Alt3 c | Alt4 d
-                    deriving (Show, Eq, Typeable, Data, Generic)
+                    deriving (Show, Eq, Typeable, Data)
 
 class ApproxEq a where
     (=~) :: a -> a -> Bool
 
 newtype Approx a = Approx { fromApprox :: a }
-    deriving (Show, Data, Typeable, Generic, ApproxEq, Num)
+    deriving (Show, Data, Typeable, ApproxEq, Num)
 
 instance (ApproxEq a) => Eq (Approx a) where
     Approx a == Approx b = a =~ b
 
-data Nullary = C1 | C2 | C3 deriving (Eq, Show, Generic)
+data Nullary = C1 | C2 | C3 deriving (Eq, Show)
 
 data SomeType a = Nullary
                 | Unary Int
                 | Record { testOne   :: Double
                          , testTwo   :: Maybe Bool
                          , testThree :: Maybe a
-                         } deriving (Eq, Show, Generic)
+                         } deriving (Eq, Show)
+
+#ifdef GHC_GENERICS
+deriving instance Generic Foo
+deriving instance Generic UFoo
+deriving instance Generic OneConstructor
+deriving instance Generic (Product2 a b)
+deriving instance Generic (Product6 a b c d e f)
+deriving instance Generic (Sum4 a b c d)
+deriving instance Generic (Approx a)
+deriving instance Generic Nullary
+deriving instance Generic (SomeType a)
+#endif