Skip to content

Commit

Permalink
Fix compatibility with older and newer ghc:
Browse files Browse the repository at this point in the history
* Disable doctests for ghc-8.0 and older.

* Make some flags conditional

* Fix compatibility with new aeson

* Take care of a build warning
  • Loading branch information
lehins committed Dec 27, 2021
1 parent 9f5288a commit 34867e5
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 20 deletions.
12 changes: 5 additions & 7 deletions .github/workflows/haskell.yml
Expand Up @@ -33,9 +33,9 @@ jobs:
ghc: 8.10.7
- resolver: nightly # reports a problem with happy?!
ghc: 9.0.1
# exclude:
# - resolver: lts-18
# os: windows-latest # Too buggy, occasional ghc crashes
exclude:
- resolver: lts-18
os: windows-latest # Too buggy, occasional ghc crashes

env:
STACK_YAML: stack.yaml
Expand Down Expand Up @@ -84,7 +84,6 @@ jobs:
COVERALLS_TOKEN: ${{ secrets.COVERALLS_TOKEN }}
run: |
set -ex
echo "STACK_ROOT: ${{ steps.setup-haskell-cabal.outputs.stack-root }}"
[ -n "${{ matrix.stack-yaml }}" ] && STACK_YAML=${{ matrix.stack-yaml }}
curl -sSL https://raw.githubusercontent.com/lehins/utils/5d9b17f2f084ce54978dbd71974970483063a540/haskell/git-modtime/git-modtime.hs -o git-modtime.hs
mkdir -p .stack-work
Expand Down Expand Up @@ -118,14 +117,13 @@ jobs:
fail-fast: false
matrix:
include:
- { cabal: "3.4", os: ubuntu-latest, ghc: "7.10.3" }
- { cabal: "3.6", os: ubuntu-latest, ghc: "8.0.2" }
- { cabal: "3.6", os: ubuntu-latest, ghc: "8.2.2" }
- { cabal: "3.6", os: ubuntu-latest, ghc: "9.0.1" }
- { cabal: "3.6", os: ubuntu-latest, ghc: "9.2.1" }
- { cabal: "3.6", os: windows-latest, ghc: "8.0.2" } # OOM on tests
- { cabal: "3.6", os: windows-latest, ghc: "8.0.2" }
- { cabal: "3.6", os: windows-latest, ghc: "8.2.2" }
- { cabal: "3.6", os: windows-latest, ghc: "9.0.1" } # OOM on tests
- { cabal: "3.6", os: windows-latest, ghc: "9.0.1" }
- { cabal: "3.6", os: windows-latest, ghc: "9.2.1" }
- { cabal: "3.6", os: macOS-latest, ghc: "8.0.2" }
- { cabal: "3.6", os: macOS-latest, ghc: "8.2.2" }
Expand Down
13 changes: 7 additions & 6 deletions conduit-aeson.cabal
Expand Up @@ -29,7 +29,7 @@ library
other-modules:
build-depends: aeson >= 1.0
, attoparsec
, base >= 4.8 && < 5
, base >= 4.9 && < 5
, bytestring
, conduit
, conduit-extra
Expand All @@ -47,11 +47,12 @@ test-suite doctests
hs-source-dirs: tests
main-is: doctests.hs
build-depends: base
, attoparsec
, bytestring
, conduit
, conduit-aeson
, doctest-parallel
if impl(ghc >= 8.2)
build-depends: attoparsec
, bytestring
, conduit
, conduit-aeson
, doctest-parallel
default-language: Haskell2010
ghc-options: -Wall
-Wincomplete-record-updates
Expand Down
10 changes: 6 additions & 4 deletions src/Data/Conduit/Aeson.hs
Expand Up @@ -43,20 +43,22 @@ import Data.Attoparsec.ByteString as Atto
import qualified Data.Attoparsec.ByteString.Char8 as Atto8
import Data.Bifunctor (first)
import qualified Data.ByteString as BS
import Data.Coerce
import Data.Conduit.Attoparsec
import qualified Data.Text as T
#if MIN_VERSION_aeson(1,5,0)
import Data.Coerce
#endif

-- | Various reason for failed parsing.
--
-- @since 0.1.0
data ParserError
= AttoParserError ParseError
-- ^ Attoparse parser failure
-- ^ Attoparsec parser failure
| AesonParserError String
-- ^ Aeson parser failure
| NotTerminatedInput
-- ^ Failure when input was not properly terminated and end of input was reached.
-- ^ Parser failure when end of input was reached without proper termination.
deriving Show
instance Exception ParserError

Expand Down Expand Up @@ -266,7 +268,7 @@ delimiterParser dp t =
expectTermination =
Atto8.peekChar >>= \case
Just c
| c /= t -> fail $ "Unexpected delimiter: " <> show c
| c /= t -> fail $ "Unexpected delimiter: " ++ show c
_ -> pure ()

-- | Consume @'['@ with all preceeding space characters
Expand Down
8 changes: 5 additions & 3 deletions tests/Data/Conduit/AesonSpec.hs
Expand Up @@ -30,8 +30,10 @@ sizedArbitraryValue n
number = Number <$> (scientific <$> arbitrary <*> arbitrary)
string = String <$> arbitrary
array = Array . fromList <$> arbitrary
object' = Object . fromList <$> arbitrary
object' = listToObject <$> arbitrary

listToObject :: [(String, Value)] -> Value
listToObject xs = object [(fromString k, v) | (k, v) <- xs]

spec :: Spec
spec = do
Expand All @@ -41,9 +43,9 @@ spec = do
runConduit
(sourceLazy (encode (Array (fromList xs))) .| conduitArray .| sinkList)
xs' `shouldBe` xs
prop "conduitObject" $ \(ls :: [(T.Text, Value)]) -> do
prop "conduitObject" $ \(ls :: [(String, Value)]) -> do
let xs = Map.fromList ls
xs' <-
runConduit
(sourceLazy (encode (Object (fromList (Map.toList xs)))) .| conduitObject .| sinkList)
(sourceLazy (encode (listToObject (Map.toAscList xs))) .| conduitObject .| sinkList)
Map.fromList xs' `shouldBe` xs
11 changes: 11 additions & 0 deletions tests/doctests.hs
@@ -1,7 +1,18 @@
{-# LANGUAGE CPP #-}

module Main where

#if __GLASGOW_HASKELL__ >= 802
import Test.DocTest (mainFromCabal)
import System.Environment (getArgs)

main :: IO ()
main = mainFromCabal "conduit-aeson" =<< getArgs
#else

import System.IO

main :: IO ()
main = hPutStrLn stderr "GHC version older than 8.2 are not supported"

#endif

0 comments on commit 34867e5

Please sign in to comment.