Skip to content

Commit 626f8a6

Browse files
jvanbrueggefacebook-github-bot
authored andcommitted
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: #148 Reviewed By: simonmar Differential Revision: D35500924 Pulled By: pepeiborra fbshipit-source-id: 16619084c4f2d76c9495fd778401f8bab66e26d2
1 parent ca65bb9 commit 626f8a6

File tree

6 files changed

+47
-12
lines changed

6 files changed

+47
-12
lines changed

haxl.cabal

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ extra-source-files:
4343
library
4444

4545
build-depends:
46-
aeson >= 0.6 && < 1.6,
46+
aeson >= 0.6 && < 2.1,
4747
base >= 4.10 && < 5,
4848
binary >= 0.7 && < 0.10,
4949
bytestring >= 0.9 && < 0.11,

stack.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
resolver: lts-8.15
1+
resolver: lts-19.2
22

33
packages:
44
- '.'

stack.yaml.lock

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

tests/ProfileTests.hs

+8-2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
{-# LANGUAGE NoImplicitPrelude #-}
88
{-# LANGUAGE OverloadedStrings #-}
99
{-# LANGUAGE RecordWildCards #-}
10+
{-# LANGUAGE CPP #-}
1011

1112
module ProfileTests where
1213

@@ -23,6 +24,11 @@ import Control.Exception (evaluate)
2324
import Data.Aeson
2425
import Data.IORef
2526
import qualified Data.HashMap.Strict as HashMap
27+
#if MIN_VERSION_aeson(2,0,0)
28+
import qualified Data.Aeson.KeyMap as KeyMap
29+
#else
30+
import qualified Data.HashMap.Strict as KeyMap
31+
#endif
2632
import Data.Int
2733

2834
import TestUtils
@@ -53,7 +59,7 @@ collectsdata = do
5359
slp <- sum <$> mapM (\x -> withLabel "baz" $ return x) [1..5]
5460
-- do some non-trivial work that can't be lifted out
5561
-- first sleep though in order to force a Blocked result
56-
sleep slp `andThen` case fromJSON <$> HashMap.lookup "A" u of
62+
sleep slp `andThen` case fromJSON <$> KeyMap.lookup "A" u of
5763
Just (Success n) | sum [n .. 1000::Integer] > 0 -> return 5
5864
_otherwise -> return (4::Int)
5965
profCopy <- readIORef (profRef e)
@@ -94,7 +100,7 @@ collectsLazyData = do
94100
_x <- runHaxl e $ withLabel "bar" $ do
95101
u <- env userEnv
96102
withLabel "foo" $ do
97-
let start = if HashMap.member "A" u
103+
let start = if KeyMap.member "A" u
98104
then 10
99105
else 1
100106
return $ sum [start..10000::Integer]

tests/TestTypes.hs

+18-6
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
{-# LANGUAGE OverloadedStrings #-}
88
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
99
{-# LANGUAGE DeriveDataTypeable #-}
10+
{-# LANGUAGE CPP #-}
1011

1112
module TestTypes
1213
( UserEnv
@@ -18,29 +19,40 @@ module TestTypes
1819

1920
import Data.Aeson
2021
import Data.Binary (Binary)
21-
import Data.Text (Text)
2222
import qualified Data.Text as Text
23-
import qualified Data.HashMap.Strict as HashMap
23+
#if MIN_VERSION_aeson(2,0,0)
24+
import qualified Data.Aeson.KeyMap as KeyMap
25+
import Data.Aeson.Key (toText)
26+
#else
27+
import qualified Data.HashMap.Strict as KeyMap
28+
#endif
2429
import Data.Hashable
2530
import Data.Typeable
2631

2732
import Haxl.Core
2833

34+
#if !MIN_VERSION_aeson(2,0,0)
35+
type Key = Text.Text
36+
37+
toText :: Key -> Text.Text
38+
toText = id
39+
#endif
40+
2941
type UserEnv = Object
3042
type Haxl a = GenHaxl UserEnv () a
3143
type HaxlEnv = Env UserEnv ()
3244

33-
lookupInput :: FromJSON a => Text -> Haxl a
45+
lookupInput :: FromJSON a => Key -> Haxl a
3446
lookupInput field = do
35-
mb_val <- env (HashMap.lookup field . userEnv)
47+
mb_val <- env (KeyMap.lookup field . userEnv)
3648
case mb_val of
3749
Nothing ->
38-
throw (NotFound (Text.concat ["field ", field, " was not found."]))
50+
throw (NotFound (Text.concat ["field ", toText field, " was not found."]))
3951
Just val ->
4052
case fromJSON val of
4153
Error str ->
4254
throw (UnexpectedType (Text.concat
43-
["field ", field, ": ", Text.pack str]))
55+
["field ", toText field, ": ", Text.pack str]))
4456
Success a -> return a
4557

4658

tests/TestUtils.hs

+7-2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
-- found in the LICENSE file.
66

77
{-# LANGUAGE OverloadedStrings #-}
8+
{-# LANGUAGE CPP #-}
89
module TestUtils
910
( makeTestEnv
1011
, expectResultWithEnv
@@ -21,15 +22,19 @@ import Haxl.DataSource.ConcurrentIO
2122
import Data.IORef
2223
import Data.Aeson
2324
import Test.HUnit
24-
import qualified Data.HashMap.Strict as HashMap
25+
#if MIN_VERSION_aeson(2,0,0)
26+
import qualified Data.Aeson.KeyMap as KeyMap
27+
#else
28+
import qualified Data.HashMap.Strict as KeyMap
29+
#endif
2530

2631
import Haxl.Core
2732

2833
import Prelude()
2934
import Haxl.Prelude
3035

3136
testinput :: Object
32-
testinput = HashMap.fromList [
37+
testinput = KeyMap.fromList [
3338
"A" .= (1 :: Int),
3439
"B" .= (2 :: Int),
3540
"C" .= (3 :: Int),

0 commit comments

Comments
 (0)