Allow aeson 2.0 (#148)

Summary:
Only needed changes to the tests, the main library is untouched.

Also updates the stack.yaml to use GHC 9.0.2

Pull Request resolved: https://github.com/facebook/Haxl/pull/148

Reviewed By: simonmar

Differential Revision: D35500924

Pulled By: pepeiborra

fbshipit-source-id: 16619084c4f2d76c9495fd778401f8bab66e26d2
This commit is contained in:
Jan van Brügge 2022-04-11 03:11:20 -07:00 committed by Facebook GitHub Bot
parent ca65bb92d0
commit 626f8a6a66
6 changed files with 47 additions and 12 deletions

View File

@ -43,7 +43,7 @@ extra-source-files:
library
build-depends:
aeson >= 0.6 && < 1.6,
aeson >= 0.6 && < 2.1,
base >= 4.10 && < 5,
binary >= 0.7 && < 0.10,
bytestring >= 0.9 && < 0.11,

View File

@ -1,4 +1,4 @@
resolver: lts-8.15
resolver: lts-19.2
packages:
- '.'

12
stack.yaml.lock Normal file
View File

@ -0,0 +1,12 @@
# This file was autogenerated by Stack.
# You should not edit this file by hand.
# For more information, please see the documentation at:
# https://docs.haskellstack.org/en/stable/lock_files
packages: []
snapshots:
- completed:
size: 617368
url: https://raw.githubusercontent.com/commercialhaskell/stackage-snapshots/master/lts/19/2.yaml
sha256: e7e57649a12f6178d1158e4b6f1f1885ed56d210ae6174385271cecc9b1ea974
original: lts-19.2

View File

@ -7,6 +7,7 @@
{-# LANGUAGE NoImplicitPrelude #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE CPP #-}
module ProfileTests where
@ -23,6 +24,11 @@ import Control.Exception (evaluate)
import Data.Aeson
import Data.IORef
import qualified Data.HashMap.Strict as HashMap
#if MIN_VERSION_aeson(2,0,0)
import qualified Data.Aeson.KeyMap as KeyMap
#else
import qualified Data.HashMap.Strict as KeyMap
#endif
import Data.Int
import TestUtils
@ -53,7 +59,7 @@ collectsdata = do
slp <- sum <$> mapM (\x -> withLabel "baz" $ return x) [1..5]
-- do some non-trivial work that can't be lifted out
-- first sleep though in order to force a Blocked result
sleep slp `andThen` case fromJSON <$> HashMap.lookup "A" u of
sleep slp `andThen` case fromJSON <$> KeyMap.lookup "A" u of
Just (Success n) | sum [n .. 1000::Integer] > 0 -> return 5
_otherwise -> return (4::Int)
profCopy <- readIORef (profRef e)
@ -94,7 +100,7 @@ collectsLazyData = do
_x <- runHaxl e $ withLabel "bar" $ do
u <- env userEnv
withLabel "foo" $ do
let start = if HashMap.member "A" u
let start = if KeyMap.member "A" u
then 10
else 1
return $ sum [start..10000::Integer]

View File

@ -7,6 +7,7 @@
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE DeriveDataTypeable #-}
{-# LANGUAGE CPP #-}
module TestTypes
( UserEnv
@ -18,29 +19,40 @@ module TestTypes
import Data.Aeson
import Data.Binary (Binary)
import Data.Text (Text)
import qualified Data.Text as Text
import qualified Data.HashMap.Strict as HashMap
#if MIN_VERSION_aeson(2,0,0)
import qualified Data.Aeson.KeyMap as KeyMap
import Data.Aeson.Key (toText)
#else
import qualified Data.HashMap.Strict as KeyMap
#endif
import Data.Hashable
import Data.Typeable
import Haxl.Core
#if !MIN_VERSION_aeson(2,0,0)
type Key = Text.Text
toText :: Key -> Text.Text
toText = id
#endif
type UserEnv = Object
type Haxl a = GenHaxl UserEnv () a
type HaxlEnv = Env UserEnv ()
lookupInput :: FromJSON a => Text -> Haxl a
lookupInput :: FromJSON a => Key -> Haxl a
lookupInput field = do
mb_val <- env (HashMap.lookup field . userEnv)
mb_val <- env (KeyMap.lookup field . userEnv)
case mb_val of
Nothing ->
throw (NotFound (Text.concat ["field ", field, " was not found."]))
throw (NotFound (Text.concat ["field ", toText field, " was not found."]))
Just val ->
case fromJSON val of
Error str ->
throw (UnexpectedType (Text.concat
["field ", field, ": ", Text.pack str]))
["field ", toText field, ": ", Text.pack str]))
Success a -> return a

View File

@ -5,6 +5,7 @@
-- found in the LICENSE file.
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE CPP #-}
module TestUtils
( makeTestEnv
, expectResultWithEnv
@ -21,7 +22,11 @@ import Haxl.DataSource.ConcurrentIO
import Data.IORef
import Data.Aeson
import Test.HUnit
import qualified Data.HashMap.Strict as HashMap
#if MIN_VERSION_aeson(2,0,0)
import qualified Data.Aeson.KeyMap as KeyMap
#else
import qualified Data.HashMap.Strict as KeyMap
#endif
import Haxl.Core
@ -29,7 +34,7 @@ import Prelude()
import Haxl.Prelude
testinput :: Object
testinput = HashMap.fromList [
testinput = KeyMap.fromList [
"A" .= (1 :: Int),
"B" .= (2 :: Int),
"C" .= (3 :: Int),