on master help sign in
Make test suite require generics support
12ab143Bryan O'Sullivan
aeson.cabal−1
@@ -141,7 +141,6 @@ test-suite tests
141 Types
141 Types
142
142
143 ghc-options: -Wall -threaded -rtsopts
143 ghc-options: -Wall -threaded -rtsopts
144− cpp-options: -DGHC_GENERICS
145
144
146 build-depends:
145 build-depends:
147 HUnit,
146 HUnit,
tests/Encoders.hs+1−5
@@ -1,4 +1,4 @@
1−{-# Language CPP, TemplateHaskell #-}
1+{-# Language TemplateHaskell #-}
2
2
3module Encoders where
3module Encoders where
4
4
@@ -38,7 +38,6 @@ thNullaryToJSONObjectWithSingleField = $(mkToJSON optsObjectWithSingleField ''Nu
38thNullaryParseJSONObjectWithSingleField :: Value -> Parser Nullary
38thNullaryParseJSONObjectWithSingleField :: Value -> Parser Nullary
39thNullaryParseJSONObjectWithSingleField = $(mkParseJSON optsObjectWithSingleField ''Nullary)
39thNullaryParseJSONObjectWithSingleField = $(mkParseJSON optsObjectWithSingleField ''Nullary)
40
40
41−#ifdef GHC_GENERICS
42gNullaryToJSONString :: Nullary -> Value
41gNullaryToJSONString :: Nullary -> Value
43gNullaryToJSONString = genericToJSON defaultOptions
42gNullaryToJSONString = genericToJSON defaultOptions
44
43
@@ -65,7 +64,6 @@ gNullaryToJSONObjectWithSingleField = genericToJSON optsObjectWithSingleField
65
64
66gNullaryParseJSONObjectWithSingleField :: Value -> Parser Nullary
65gNullaryParseJSONObjectWithSingleField :: Value -> Parser Nullary
67gNullaryParseJSONObjectWithSingleField = genericParseJSON optsObjectWithSingleField
66gNullaryParseJSONObjectWithSingleField = genericParseJSON optsObjectWithSingleField
68−#endif
69
67
70
68
71--------------------------------------------------------------------------------
69--------------------------------------------------------------------------------
@@ -95,7 +93,6 @@ thSomeTypeParseJSONObjectWithSingleField :: FromJSON a => Value -> Parser (SomeT
95thSomeTypeParseJSONObjectWithSingleField = $(mkParseJSON optsObjectWithSingleField ''SomeType)
93thSomeTypeParseJSONObjectWithSingleField = $(mkParseJSON optsObjectWithSingleField ''SomeType)
96
94
97
95
98−#ifdef GHC_GENERICS
99gSomeTypeToJSON2ElemArray :: ToJSON a => SomeType a -> Value
96gSomeTypeToJSON2ElemArray :: ToJSON a => SomeType a -> Value
100gSomeTypeToJSON2ElemArray = genericToJSON opts2ElemArray
97gSomeTypeToJSON2ElemArray = genericToJSON opts2ElemArray
101
98
@@ -115,4 +112,3 @@ gSomeTypeToJSONObjectWithSingleField = genericToJSON optsObjectWithSingleField
115
112
116gSomeTypeParseJSONObjectWithSingleField :: FromJSON a => Value -> Parser (SomeType a)
113gSomeTypeParseJSONObjectWithSingleField :: FromJSON a => Value -> Parser (SomeType a)
117gSomeTypeParseJSONObjectWithSingleField = genericParseJSON optsObjectWithSingleField
114gSomeTypeParseJSONObjectWithSingleField = genericParseJSON optsObjectWithSingleField
118−#endif
tests/Instances.hs+1−4
@@ -1,8 +1,5 @@
1−{-# Language CPP, OverloadedStrings, RecordWildCards, StandaloneDeriving #-}
1+{-# Language OverloadedStrings, RecordWildCards, StandaloneDeriving #-}
2{-# OPTIONS_GHC -fno-warn-orphans #-}
2{-# OPTIONS_GHC -fno-warn-orphans #-}
3−#if __GLASGOW_HASKELL__ < 702
4−{-# OPTIONS_GHC -fno-warn-missing-methods #-}
5−#endif
6
3
7module Instances where
4module Instances where
8
5
tests/Properties.hs−9
@@ -25,11 +25,8 @@ import Encoders
25import Properties.Deprecated (deprecatedTests)
25import Properties.Deprecated (deprecatedTests)
26import System.IO
26import System.IO
27import System.IO.Unsafe (unsafePerformIO)
27import System.IO.Unsafe (unsafePerformIO)
28−
29−#ifdef GHC_GENERICS
30import Data.Int
28import Data.Int
31import qualified Data.Map as Map
29import qualified Data.Map as Map
32−#endif
33
30
34#if !MIN_VERSION_time(1,5,0)
31#if !MIN_VERSION_time(1,5,0)
35import System.Locale (defaultTimeLocale, dateTimeFmt)
32import System.Locale (defaultTimeLocale, dateTimeFmt)
@@ -153,10 +150,8 @@ main = do
153 comparisonTest <- encoderComparisonTests
150 comparisonTest <- encoderComparisonTests
154 defaultMain (comparisonTest : tests)
151 defaultMain (comparisonTest : tests)
155
152
156−#ifdef GHC_GENERICS
157type P6 = Product6 Int Bool String (Approx Double) (Int, Approx Double) ()
153type P6 = Product6 Int Bool String (Approx Double) (Int, Approx Double) ()
158type S4 = Sum4 Int8 ZonedTime T.Text (Map.Map String Int)
154type S4 = Sum4 Int8 ZonedTime T.Text (Map.Map String Int)
159−#endif
160
155
161--------------------------------------------------------------------------------
156--------------------------------------------------------------------------------
162-- Value properties
157-- Value properties
@@ -207,14 +202,12 @@ tests = [
207 , testProperty "DotNetTime" $ roundTripEq (undefined :: DotNetTime)
202 , testProperty "DotNetTime" $ roundTripEq (undefined :: DotNetTime)
208 , testProperty "UTCTime" $ roundTripEq (undefined :: UTCTime)
203 , testProperty "UTCTime" $ roundTripEq (undefined :: UTCTime)
209 , testProperty "ZonedTime" $ roundTripEq (undefined :: ZonedTime)
204 , testProperty "ZonedTime" $ roundTripEq (undefined :: ZonedTime)
210−#ifdef GHC_GENERICS
211 , testGroup "ghcGenerics" [
205 , testGroup "ghcGenerics" [
212 testProperty "OneConstructor" $ roundTripEq OneConstructor
206 testProperty "OneConstructor" $ roundTripEq OneConstructor
213 , testProperty "Product2" $ roundTripEq (undefined :: Product2 Int Bool)
207 , testProperty "Product2" $ roundTripEq (undefined :: Product2 Int Bool)
214 , testProperty "Product6" $ roundTripEq (undefined :: P6)
208 , testProperty "Product6" $ roundTripEq (undefined :: P6)
215 , testProperty "Sum4" $ roundTripEq (undefined :: S4)
209 , testProperty "Sum4" $ roundTripEq (undefined :: S4)
216 ]
210 ]
217−#endif
218 ],
211 ],
219 testGroup "toFromJSON" [
212 testGroup "toFromJSON" [
220 testProperty "Integer" (toFromJSON :: Integer -> Bool)
213 testProperty "Integer" (toFromJSON :: Integer -> Bool)
@@ -254,7 +247,6 @@ tests = [
254 ]
247 ]
255 ]
248 ]
256 ]
249 ]
257−#ifdef GHC_GENERICS
258 , testGroup "GHC-generics" [
250 , testGroup "GHC-generics" [
259 testGroup "Nullary" [
251 testGroup "Nullary" [
260 testProperty "string" (isString . gNullaryToJSONString)
252 testProperty "string" (isString . gNullaryToJSONString)
@@ -291,7 +283,6 @@ tests = [
291 ]
283 ]
292 ]
284 ]
293 ]
285 ]
294−#endif
295 ]
286 ]
296
287
297
288
tests/Types.hs+1−7
@@ -1,16 +1,12 @@
1−{-# LANGUAGE CPP, DeriveDataTypeable, GeneralizedNewtypeDeriving #-}
1+{-# LANGUAGE DeriveDataTypeable, GeneralizedNewtypeDeriving #-}
2−#ifdef GHC_GENERICS
3{-# LANGUAGE DeriveGeneric, StandaloneDeriving #-}
2{-# LANGUAGE DeriveGeneric, StandaloneDeriving #-}
4−#endif
5
3
6module Types where
4module Types where
7
5
8import qualified Data.Map as Map
6import qualified Data.Map as Map
9import Data.Data
7import Data.Data
10import Data.Text
8import Data.Text
11−#ifdef GHC_GENERICS
12import GHC.Generics
9import GHC.Generics
13−#endif
14
10
15data Foo = Foo {
11data Foo = Foo {
16 fooInt :: Int
12 fooInt :: Int
@@ -57,7 +53,6 @@ data SomeType a = Nullary
57 , testThree :: Maybe a
53 , testThree :: Maybe a
58 } deriving (Eq, Show)
54 } deriving (Eq, Show)
59
55
60−#ifdef GHC_GENERICS
61deriving instance Generic Foo
56deriving instance Generic Foo
62deriving instance Generic UFoo
57deriving instance Generic UFoo
63deriving instance Generic OneConstructor
58deriving instance Generic OneConstructor
@@ -67,4 +62,3 @@ deriving instance Generic (Sum4 a b c d)
67deriving instance Generic (Approx a)
62deriving instance Generic (Approx a)
68deriving instance Generic Nullary
63deriving instance Generic Nullary
69deriving instance Generic (SomeType a)
64deriving instance Generic (SomeType a)
70−#endif