Bryan O'Sullivan avatar Bryan O'Sullivan committed 9b36b7f

Firewall off tests for deprecated features

Comments (0)

Files changed (3)

                   Types
                   Options
                   Encoders
+                  Properties.Deprecated
 
   ghc-options:
     -Wall -threaded -rtsopts

tests/Properties.hs

 import Data.Aeson.Parser (value)
 import Data.Aeson.Types
 import Data.Attoparsec.Number
-import Data.Data (Data)
 import Data.Int
 import Test.Framework (Test, defaultMain, testGroup)
 import Test.Framework.Providers.QuickCheck2 (testProperty)
 import Test.QuickCheck (Arbitrary(..))
 import qualified Data.Vector as V
-import qualified Data.Aeson.Generic as G
 import qualified Data.Attoparsec.Lazy as L
 import qualified Data.ByteString.Lazy.Char8 as L
 import qualified Data.Text as T
 import qualified Data.HashMap.Strict as H
 import Data.Time.Clock (UTCTime(..))
 import Data.Time (ZonedTime(..))
-import Types (Foo(..), UFoo(..))
+import Types (Foo(..))
 import Instances ()
 import Types (Approx(..), OneConstructor(..), Product2, Product6, Sum4)
 import Encoders
+import Properties.Deprecated (deprecatedTests)
 
 
 encodeDouble :: Double -> Double -> Bool
 roundTripEq :: (Eq a, FromJSON a, ToJSON a) => a -> a -> Bool
 roundTripEq x y = roundTrip (==) x y
 
-genericTo :: (Data a, ToJSON a) => a -> a -> Bool
-genericTo _ v = G.toJSON v == toJSON v
-
-genericFrom :: (Eq a, Data a, ToJSON a) => a -> a -> Bool
-genericFrom _ v = G.fromJSON (toJSON v) == Success v
-
 toFromJSON :: (Arbitrary a, Eq a, FromJSON a, ToJSON a) => a -> Bool
 toFromJSON x = case fromJSON . toJSON $ x of
                 Error _ -> False
                 Success x' -> x == x'
 
-genericToFromJSON :: (Arbitrary a, Eq a, Data a) => a -> Bool
-genericToFromJSON x = case G.fromJSON . G.toJSON $ x of
-                Error _ -> False
-                Success x' -> x == x'
-
-regress_gh72 :: [(String, Maybe String)] -> Bool
-regress_gh72 ys = G.decode (G.encode m) == Just m
-    where m = Map.fromList ys
-
 modifyFailureProp :: String -> String -> Bool
 modifyFailureProp orig added =
     result == Error (added ++ orig)
 
 tests :: [Test]
 tests = [
-  testGroup "regression" [
-      testProperty "gh-72" regress_gh72
-  ],
   testGroup "encode" [
       testProperty "encodeDouble" encodeDouble
     , testProperty "encodeInteger" encodeInteger
     ],
-  testGroup "genericFrom" [
-      testProperty "Bool" $ genericFrom True
-    , testProperty "Double" $ genericFrom (1::Double)
-    , testProperty "Int" $ genericFrom (1::Int)
-    , testProperty "Foo" $ genericFrom (undefined::Foo)
-    , testProperty "Maybe" $ genericFrom (Just 1 :: Maybe Int)
-    ],
-  testGroup "genericTo" [
-      testProperty "Bool" $ genericTo True
-    , testProperty "Double" $ genericTo (1::Double)
-    , testProperty "Int" $ genericTo (1::Int)
-    , testProperty "Foo" $ genericTo (undefined::Foo)
-    , testProperty "Maybe" $ genericTo (Just 1 :: Maybe Int)
-    ],
   testGroup "roundTrip" [
       testProperty "Bool" $ roundTripEq True
     , testProperty "Double" $ roundTripEq (1 :: Approx Double)
     , testProperty "Either Integer Double" (toFromJSON :: Either Integer Double -> Bool)
     , testProperty "Either Integer Integer" (toFromJSON :: Either Integer Integer -> Bool)
     ],
-  testGroup "genericToFromJSON" [
-      testProperty "_UFoo" (genericToFromJSON :: UFoo -> Bool)
-    ],
+  testGroup "deprecated" deprecatedTests,
   testGroup "failure messages" [
       testProperty "modify failure" modifyFailureProp
     ],

tests/Properties/Deprecated.hs

+-- This module is only for testing deprecated features, so we can
+-- silence compiler warnings selectively.
+
+{-# LANGUAGE OverloadedStrings, RecordWildCards, ScopedTypeVariables #-}
+{-# OPTIONS_GHC -fno-warn-warnings-deprecations #-}
+
+module Properties.Deprecated (deprecatedTests) where
+
+import Data.Aeson.Types
+import Data.Data (Data)
+import Test.Framework (Test, testGroup)
+import Test.Framework.Providers.QuickCheck2 (testProperty)
+import Test.QuickCheck (Arbitrary(..))
+import qualified Data.Aeson.Generic as G
+import qualified Data.Map as Map
+import Types (Foo(..), UFoo(..))
+import Instances ()
+
+
+genericTo :: (Data a, ToJSON a) => a -> a -> Bool
+genericTo _ v = G.toJSON v == toJSON v
+
+genericFrom :: (Eq a, Data a, ToJSON a) => a -> a -> Bool
+genericFrom _ v = G.fromJSON (toJSON v) == Success v
+
+genericToFromJSON :: (Arbitrary a, Eq a, Data a) => a -> Bool
+genericToFromJSON x = case G.fromJSON . G.toJSON $ x of
+                Error _ -> False
+                Success x' -> x == x'
+
+regress_gh72 :: [(String, Maybe String)] -> Bool
+regress_gh72 ys = G.decode (G.encode m) == Just m
+    where m = Map.fromList ys
+
+deprecatedTests :: [Test]
+deprecatedTests = [
+  testGroup "regression" [
+    testProperty "gh-72" regress_gh72
+  ],
+  testGroup "genericFrom" [
+      testProperty "Bool" $ genericFrom True
+    , testProperty "Double" $ genericFrom (1::Double)
+    , testProperty "Int" $ genericFrom (1::Int)
+    , testProperty "Foo" $ genericFrom (undefined::Foo)
+    , testProperty "Maybe" $ genericFrom (Just 1 :: Maybe Int)
+    ],
+  testGroup "genericTo" [
+      testProperty "Bool" $ genericTo True
+    , testProperty "Double" $ genericTo (1::Double)
+    , testProperty "Int" $ genericTo (1::Int)
+    , testProperty "Foo" $ genericTo (undefined::Foo)
+    , testProperty "Maybe" $ genericTo (Just 1 :: Maybe Int)
+    ],
+  testGroup "genericToFromJSON" [
+      testProperty "_UFoo" (genericToFromJSON :: UFoo -> Bool)
+    ]
+  ]
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.