cereal-conduit 0.7.3 → 0.8.0
raw patch · 5 files changed
+111/−95 lines, 5 filesdep ~basedep ~conduitdep ~resourcetPVP ok
version bump matches the API change (PVP)
Dependency ranges changed: base, conduit, resourcet
API changes (from Hackage documentation)
- Data.Conduit.Cereal: conduitGet :: MonadThrow m => Get o -> Conduit ByteString m o
+ Data.Conduit.Cereal: conduitGet :: MonadThrow m => Get o -> ConduitT ByteString o m ()
- Data.Conduit.Cereal: conduitGet2 :: MonadThrow m => Get o -> Conduit ByteString m o
+ Data.Conduit.Cereal: conduitGet2 :: MonadThrow m => Get o -> ConduitT ByteString o m ()
- Data.Conduit.Cereal: conduitPut :: Monad m => Putter a -> Conduit a m ByteString
+ Data.Conduit.Cereal: conduitPut :: Monad m => Putter a -> ConduitT a ByteString m ()
- Data.Conduit.Cereal: sinkGet :: MonadThrow m => Get r -> Consumer ByteString m r
+ Data.Conduit.Cereal: sinkGet :: MonadThrow m => Get r -> ConduitT ByteString o m r
- Data.Conduit.Cereal: sourcePut :: Monad m => Put -> Producer m ByteString
+ Data.Conduit.Cereal: sourcePut :: Monad m => Put -> ConduitT i ByteString m ()
- Data.Conduit.Cereal.Internal: mkConduitGet :: Monad m => ConduitErrorHandler m o -> Get o -> Conduit ByteString m o
+ Data.Conduit.Cereal.Internal: mkConduitGet :: Monad m => ConduitErrorHandler m o -> Get o -> ConduitT ByteString o m ()
- Data.Conduit.Cereal.Internal: mkSinkGet :: Monad m => SinkErrorHandler m r -> SinkTerminationHandler m r -> Get r -> Consumer ByteString m r
+ Data.Conduit.Cereal.Internal: mkSinkGet :: Monad m => SinkErrorHandler m r -> SinkTerminationHandler m r -> Get r -> ConduitT ByteString o m r
- Data.Conduit.Cereal.Internal: type ConduitErrorHandler m o = String -> Conduit ByteString m o
+ Data.Conduit.Cereal.Internal: type ConduitErrorHandler m o = String -> ConduitT ByteString o m ()
- Data.Conduit.Cereal.Internal: type SinkErrorHandler m r = String -> Consumer ByteString m r
+ Data.Conduit.Cereal.Internal: type SinkErrorHandler m r = forall o. String -> ConduitT ByteString o m r
- Data.Conduit.Cereal.Internal: type SinkTerminationHandler m r = (ByteString -> Result r) -> Consumer ByteString m r
+ Data.Conduit.Cereal.Internal: type SinkTerminationHandler m r = forall o. (ByteString -> Result r) -> ConduitT ByteString o m r
Files
- ChangeLog.md +4/−0
- Data/Conduit/Cereal.hs +15/−15
- Data/Conduit/Cereal/Internal.hs +15/−15
- Test/Main.hs +73/−60
- cereal-conduit.cabal +4/−5
ChangeLog.md view
@@ -1,3 +1,7 @@+## 0.8.0++* Upgrade to conduit 1.3.0+ ## 0.7.3 * Provide `conduitGet2`
Data/Conduit/Cereal.hs view
@@ -19,10 +19,10 @@ ) where import Control.Exception.Base-import Control.Monad.Trans.Resource (MonadThrow, monadThrow)+import Control.Monad.Trans.Resource (MonadThrow, throwM) import qualified Data.ByteString as BS import qualified Data.ByteString.Lazy as LBS-import qualified Data.Conduit as C+import Data.Conduit (ConduitT, leftover, await, yield) import qualified Data.Conduit.List as CL import Data.Serialize hiding (get, put) import Data.Typeable@@ -35,29 +35,29 @@ instance Exception GetException -- | Run a 'Get' repeatedly on the input stream, producing an output stream of whatever the 'Get' outputs.-conduitGet :: MonadThrow m => Get o -> C.Conduit BS.ByteString m o+conduitGet :: MonadThrow m => Get o -> ConduitT BS.ByteString o m () conduitGet = mkConduitGet errorHandler- where errorHandler msg = monadThrow $ GetException msg+ where errorHandler msg = throwM $ GetException msg {-# DEPRECATED conduitGet "Please switch to conduitGet2, see comment on that function" #-} -- | Convert a 'Get' into a 'Sink'. The 'Get' will be streamed bytes until it returns 'Done' or 'Fail'. -- -- If 'Get' succeed it will return the data read and unconsumed part of the input stream. -- If the 'Get' fails due to deserialization error or early termination of the input stream it raise an error.-sinkGet :: MonadThrow m => Get r -> C.Consumer BS.ByteString m r+sinkGet :: MonadThrow m => Get r -> ConduitT BS.ByteString o m r sinkGet = mkSinkGet errorHandler terminationHandler- where errorHandler msg = monadThrow $ GetException msg+ where errorHandler msg = throwM $ GetException msg terminationHandler f = case f BS.empty of- Fail msg _ -> monadThrow $ GetException msg- Done r lo -> C.leftover lo >> return r- Partial _ -> monadThrow $ GetException "Failed reading: Internal error: unexpected Partial."+ Fail msg _ -> throwM $ GetException msg+ Done r lo -> leftover lo >> return r+ Partial _ -> throwM $ GetException "Failed reading: Internal error: unexpected Partial." -- | Convert a 'Put' into a 'Source'. Runs in constant memory.-sourcePut :: Monad m => Put -> C.Producer m BS.ByteString+sourcePut :: Monad m => Put -> ConduitT i BS.ByteString m () sourcePut put = CL.sourceList $ LBS.toChunks $ runPutLazy put -- | Run a 'Putter' repeatedly on the input stream, producing a concatenated 'ByteString' stream.-conduitPut :: Monad m => Putter a -> C.Conduit a m BS.ByteString+conduitPut :: Monad m => Putter a -> ConduitT a BS.ByteString m () conduitPut p = CL.map $ runPut . p -- | Reapply @Get o@ to a stream of bytes as long as more data is available,@@ -82,7 +82,7 @@ -- no data left to be consumed in the stream. -- -- @since 0.7.3-conduitGet2 :: MonadThrow m => Get o -> C.Conduit BS.ByteString m o+conduitGet2 :: MonadThrow m => Get o -> ConduitT BS.ByteString o m () conduitGet2 get = awaitNE >>= start where@@ -91,7 +91,7 @@ awaitNE = loop where- loop = C.await >>= maybe (return BS.empty) check+ loop = await >>= maybe (return BS.empty) check check bs | BS.null bs = loop | otherwise = return bs@@ -100,7 +100,7 @@ | BS.null bs = return () | otherwise = result (runGetPartial get bs) - result (Fail msg _) = monadThrow (GetException msg)+ result (Fail msg _) = throwM (GetException msg) -- This will feed an empty ByteString into f at end of stream, which is how -- we indicate to cereal that there is no data left. If we wanted to be -- more pedantic, we could ensure that cereal only ever consumes a single@@ -108,7 +108,7 @@ -- giving us anyway. result (Partial f) = awaitNE >>= result . f result (Done x rest) = do- C.yield x+ yield x if BS.null rest then awaitNE >>= start else start rest
Data/Conduit/Cereal/Internal.hs view
@@ -12,35 +12,35 @@ import Control.Monad (forever, when) import qualified Data.ByteString as BS-import qualified Data.Conduit as C+import Data.Conduit (ConduitT, await, leftover, yield) import Data.Serialize hiding (get, put) -- | What should we do if the Get fails?-type ConduitErrorHandler m o = String -> C.Conduit BS.ByteString m o-type SinkErrorHandler m r = String -> C.Consumer BS.ByteString m r+type ConduitErrorHandler m o = String -> ConduitT BS.ByteString o m ()+type SinkErrorHandler m r = forall o. String -> ConduitT BS.ByteString o m r -- | What should we do if the stream is done before the Get is done?-type SinkTerminationHandler m r = (BS.ByteString -> Result r) -> C.Consumer BS.ByteString m r+type SinkTerminationHandler m r = forall o. (BS.ByteString -> Result r) -> ConduitT BS.ByteString o m r -- | Construct a conduitGet with the specified 'ErrorHandler' mkConduitGet :: Monad m => ConduitErrorHandler m o -> Get o- -> C.Conduit BS.ByteString m o+ -> ConduitT BS.ByteString o m () mkConduitGet errorHandler get = consume True (runGetPartial get) [] BS.empty where pull f b s- | BS.null s = C.await >>= maybe (when (not $ null b) (C.leftover $ BS.concat $ reverse b)) (pull f b)+ | BS.null s = await >>= maybe (when (not $ null b) (leftover $ BS.concat $ reverse b)) (pull f b) | otherwise = consume False f b s consume initial f b s = case f s of Fail msg _ -> do- when (not $ null b) (C.leftover $ BS.concat $ reverse consumed)+ when (not $ null b) (leftover $ BS.concat $ reverse consumed) errorHandler msg Partial p -> pull p consumed BS.empty Done a s' -> case initial of -- this only works because the Get will either _always_ consume no input, or _never_ consume no input.- True -> forever $ C.yield a- False -> C.yield a >> pull (runGetPartial get) [] s'--- False -> C.yield a >> C.leftover s' >> mkConduitGet errorHandler get+ True -> forever $ yield a+ False -> yield a >> pull (runGetPartial get) [] s'+-- False -> yield a >> leftover s' >> mkConduitGet errorHandler get where consumed = s : b -- | Construct a sinkGet with the specified 'ErrorHandler' and 'TerminationHandler'@@ -48,17 +48,17 @@ => SinkErrorHandler m r -> SinkTerminationHandler m r -> Get r- -> C.Consumer BS.ByteString m r+ -> ConduitT BS.ByteString o m r mkSinkGet errorHandler terminationHandler get = consume (runGetPartial get) [] BS.empty where pull f b s- | BS.null s = C.await >>= \ x -> case x of- Nothing -> when (not $ null b) (C.leftover $ BS.concat $ reverse b) >> terminationHandler f+ | BS.null s = await >>= \ x -> case x of+ Nothing -> when (not $ null b) (leftover $ BS.concat $ reverse b) >> terminationHandler f Just a -> pull f b a | otherwise = consume f b s consume f b s = case f s of Fail msg _ -> do- when (not $ null b) (C.leftover $ BS.concat $ reverse consumed)+ when (not $ null b) (leftover $ BS.concat $ reverse consumed) errorHandler msg Partial p -> pull p consumed BS.empty- Done r s' -> when (not $ BS.null s') (C.leftover s') >> return r+ Done r s' -> when (not $ BS.null s') (leftover s') >> return r where consumed = s : b
Test/Main.hs view
@@ -2,27 +2,29 @@ {-# LANGUAGE RankNTypes #-} {-# LANGUAGE Rank2Types #-} {-# LANGUAGE OverloadedStrings #-}+{-# OPTIONS_GHC -fno-warn-warnings-deprecations #-} -- Due to usage of conduitGet below import Control.Applicative (many, optional) import Control.Exception.Base-import Control.Monad.Identity-import Control.Monad.Trans.Resource import Test.HUnit-import qualified Data.Conduit as C+import Data.Conduit (ConduitT, (.|), runConduit, yield, await, runConduitPure) import qualified Data.Conduit.List as CL import Data.Serialize import qualified Data.ByteString as BS+import qualified Data.ByteString.Char8 as S8 import qualified Data.List as L import Data.Word import System.Exit --import Test.Framework.Providers.HUnit import Data.Conduit.Cereal-import Data.Conduit.Cereal.Internal +import Data.Conduit.Cereal.Internal -- For the sake of these tests, all SomeExceptions are equal+{- instance Eq SomeException where- a == b = True+ _ == _ = True+-} twoItemGet :: Get Word8 twoItemGet = do@@ -44,44 +46,44 @@ sinktest1 :: Test sinktest1 = TestCase (assertEqual "Handles starting with empty bytestring" (Right 1)- (runIdentity $ runExceptionT $ (CL.sourceList [BS.pack [], BS.pack [1]]) C.$$ (sinkGet getWord8)))+ (showLeft (runConduit ((CL.sourceList [BS.pack [], BS.pack [1]]) .| (sinkGet getWord8))))) sinktest2 :: Test sinktest2 = TestCase (assertEqual "Handles empty bytestring in middle" (Right [1, 3])- (runIdentity $ runExceptionT $ (CL.sourceList [BS.pack [1], BS.pack [], BS.pack [3]]) C.$$ (sinkGet (do+ (showLeft (runConduit (CL.sourceList [BS.pack [1], BS.pack [], BS.pack [3]] .| (sinkGet (do x <- getWord8 y <- getWord8- return [x, y]))))+ return [x, y])))))) sinktest3 :: Test sinktest3 = TestCase (assertBool "Handles no data"- (case runIdentity $ runExceptionT $ (CL.sourceList []) C.$$ (sinkGet getWord8) of+ (case runConduit $ return () .| sinkGet getWord8 of Right _ -> False Left _ -> True)) sinktest4 :: Test sinktest4 = TestCase (assertEqual "Consumes no data" (Right ())- (runIdentity $ runExceptionT $ (CL.sourceList [BS.pack [1]]) C.$$ (sinkGet $ return ())))+ (showLeft $ runConduit (CL.sourceList [BS.pack [1]] .| (sinkGet $ return ())))) sinktest5 :: Test sinktest5 = TestCase (assertEqual "Empty list" (Right ())- (runIdentity $ runExceptionT $ (CL.sourceList []) C.$$ (sinkGet $ return ())))+ (showLeft $ runConduit ((CL.sourceList []) .| (sinkGet $ return ())))) sinktest6 :: Test sinktest6 = TestCase (assertEqual "Leftover input works" (Right (1, BS.pack [2, 3, 4, 5]))- (runIdentity $ runExceptionT $ (CL.sourceList [BS.pack [1, 2, 3], BS.pack [4, 5]]) C.$$ (do+ (showLeft $ runConduit ((CL.sourceList [BS.pack [1, 2, 3], BS.pack [4, 5]]) .| (do output <- sinkGet getWord8 output' <- CL.consume- return (output, BS.concat output'))))+ return (output, BS.concat output'))))) --- Current sink implementation will terminate the pipe in case of error. +-- Current sink implementation will terminate the pipe in case of error. -- One may need non-terminating version like one defined below to get access to Leftovers -sinkGetMaybe :: Get Word8 -> C.Consumer BS.ByteString (ExceptionT Identity) Word8+sinkGetMaybe :: Get Word8 -> ConduitT BS.ByteString o (Either SomeException) Word8 sinkGetMaybe = mkSinkGet errorHandler terminationHandler where errorHandler _ = return 34 terminationHandler _ = return 114@@ -89,139 +91,145 @@ sinktest7 :: Test sinktest7 = TestCase (assertEqual "Leftover input with failure works" (Right (34, BS.pack [1, 2]))- (runIdentity $ runExceptionT $ (CL.sourceList [BS.pack [1, 2]]) C.$$ (do+ (showLeft $ runConduit ((CL.sourceList [BS.pack [1, 2]]) .| (do output <- sinkGetMaybe (getWord8 >> fail "" :: Get Word8) output' <- CL.consume- return (output, BS.concat output'))))+ return (output, BS.concat output'))))) sinktest8 :: Test sinktest8 = TestCase (assertEqual "Leftover with incomplete input works" (Right (114, BS.singleton 1))- (runIdentity $ runExceptionT $ (CL.sourceList [BS.singleton 1]) C.$$ (do+ (showLeft $ runConduit ((CL.sourceList [BS.singleton 1]) .| (do output <- sinkGetMaybe twoItemGet output' <- CL.consume- return (output, BS.concat output'))))+ return (output, BS.concat output'))))) sinktest9 :: Test sinktest9 = TestCase (assertEqual "Properly terminate Partials" (Right [0..255])- (runIdentity $ runExceptionT $ mapM_ (C.yield . BS.singleton) [0..255] C.$$ sinkGet (many getWord8)))+ (showLeft (runConduit (mapM_ (yield . BS.singleton) [0..255] .| sinkGet (many getWord8))))) conduittest1 :: Test conduittest1 = TestCase (assertEqual "Handles starting with empty bytestring" (Right [])- (runIdentity $ runExceptionT $ (CL.sourceList [BS.pack [], BS.pack [1]]) C.$= conduitGet twoItemGet C.$$ CL.consume))+ (showLeft (runConduit ((CL.sourceList [BS.pack [], BS.pack [1]]) .| conduitGet twoItemGet .| CL.consume)))) conduittest2 :: Test conduittest2 = TestCase (assertEqual "Works when the get is split across items" (Right [3])- (runIdentity $ runExceptionT $ (CL.sourceList [BS.pack [1], BS.pack [2]]) C.$= conduitGet twoItemGet C.$$ CL.consume))+ (showLeft (runConduit ((CL.sourceList [BS.pack [1], BS.pack [2]]) .| conduitGet twoItemGet .| CL.consume)))) conduittest3 :: Test conduittest3 = TestCase (assertEqual "Works when empty bytestring in middle of get" (Right [3])- (runIdentity $ runExceptionT $ (CL.sourceList [BS.pack [1], BS.pack [], BS.pack [2]]) C.$= conduitGet twoItemGet C.$$ CL.consume))+ (showLeft (runConduit ((CL.sourceList [BS.pack [1], BS.pack [], BS.pack [2]]) .| conduitGet twoItemGet .| CL.consume)))) conduittest4 :: Test conduittest4 = TestCase (assertEqual "Works when empty bytestring at end of get" (Right [3])- (runIdentity $ runExceptionT $ (CL.sourceList [BS.pack [1, 2], BS.pack []]) C.$= conduitGet twoItemGet C.$$ CL.consume))+ (showLeft (runConduit ((CL.sourceList [BS.pack [1, 2], BS.pack []]) .| conduitGet twoItemGet .| CL.consume)))) conduittest5 :: Test conduittest5 = TestCase (assertEqual "Works when multiple gets are in an item" (Right [3, 7])- (runIdentity $ runExceptionT $ (CL.sourceList [BS.pack [1, 2, 3, 4]]) C.$= conduitGet twoItemGet C.$$ CL.consume))+ (showLeft (runConduit ((CL.sourceList [BS.pack [1, 2, 3, 4]]) .| conduitGet twoItemGet .| CL.consume)))) conduittest6 :: Test conduittest6 = TestCase (assertEqual "Works with leftovers" (Right [3])- (runIdentity $ runExceptionT $ (CL.sourceList [BS.pack [1, 2, 3]]) C.$= conduitGet twoItemGet C.$$ CL.consume))+ (showLeft (runConduit ((CL.sourceList [BS.pack [1, 2, 3]]) .| conduitGet twoItemGet .| CL.consume)))) conduittest7 :: Test conduittest7 = let c = 10 in TestCase (assertEqual "Works with infinite lists" (Right $ L.replicate c ())- (runIdentity $ runExceptionT $ (CL.sourceList [BS.pack [1, 2, 3]]) C.$= conduitGet (return ()) C.$$ CL.take c))+ (showLeft (runConduit ((CL.sourceList [BS.pack [1, 2, 3]]) .| conduitGet (return ()) .| CL.take c)))) conduittest8 :: Test conduittest8 = let c = 10 in TestCase (assertEqual "Works with empty source and infinite lists" (Right $ L.replicate c ())- (runIdentity $ runExceptionT $ (CL.sourceList []) C.$= conduitGet (return ()) C.$$ CL.take c))+ (showLeft (runConduit ((CL.sourceList []) .| conduitGet (return ()) .| CL.take c)))) conduittest9 :: Test-conduittest9 = let c = 10 in TestCase (assertEqual "Works with two well-placed items"+conduittest9 = TestCase (assertEqual "Works with two well-placed items" (Right [3, 7])- (runIdentity $ runExceptionT $ (CL.sourceList [BS.pack [1, 2], BS.pack [3, 4]]) C.$= conduitGet twoItemGet C.$$ CL.consume))+ (showLeft (runConduit ((CL.sourceList [BS.pack [1, 2], BS.pack [3, 4]]) .| conduitGet twoItemGet .| CL.consume)))) conduittest10 :: Test conduittest10 = TestCase (assertBool "Failure works"- (case runIdentity $ runExceptionT $ (CL.sourceList [BS.pack [1, 2], BS.pack [3, 4]]) C.$= conduitGet (getWord8 >> fail "omfg") C.$$ CL.consume of+ (case runConduit $ (CL.sourceList [BS.pack [1, 2], BS.pack [3, 4]]) .| conduitGet (getWord8 >> fail "omfg") .| CL.consume of Left _ -> True Right _ -> False)) conduittest11 :: Test conduittest11 = TestCase (assertBool "Immediate failure works"- (case runIdentity $ runExceptionT $ (CL.sourceList [BS.pack [1, 2], BS.pack [3, 4]]) C.$= conduitGet (fail "omfg") C.$$ CL.consume of+ (case runConduit $ (CL.sourceList [BS.pack [1, 2], BS.pack [3, 4]]) .| conduitGet (fail "omfg") .| CL.consume of Left _ -> True Right _ -> False)) conduittest12 :: Test conduittest12 = TestCase (assertBool "Immediate failure with empty input works"- (case runIdentity $ runExceptionT $ (CL.sourceList []) C.$= conduitGet (fail "omfg") C.$$ CL.consume of+ (case runConduit $ (CL.sourceList []) .| conduitGet (fail "omfg") .| CL.consume of Left _ -> True Right _ -> False)) conduittest13 :: Test conduittest13 = TestCase (assertEqual "Leftover success conduit input works" (Right [Right 12, Right 7, Left (BS.pack [5])])- (runIdentity $ runExceptionT $ (CL.sourceList [BS.pack [10, 2, 3], BS.pack [4, 5]]) C.$= fancyConduit C.$$ CL.consume))+ (showLeft (runConduit ((CL.sourceList [BS.pack [10, 2, 3], BS.pack [4, 5]]) .| fancyConduit .| CL.consume)))) where fancyConduit = do- conduitGet twoItemGet C.=$= CL.map (\ x -> Right x)+ conduitGet twoItemGet .| CL.map (\ x -> Right x) recurse- where recurse = C.await >>= maybe (return ()) (\ x -> C.yield (Left x) >> recurse)+ where recurse = await >>= maybe (return ()) (\ x -> yield (Left x) >> recurse) +showLeft :: Either SomeException a -> Either String a+showLeft (Left e) = Left (show e)+showLeft (Right x) = Right x+ conduittest14 :: Test conduittest14 = TestCase (assertEqual "Leftover coercing works" (Right [Left (BS.pack [10, 2])])- (runIdentity $ runExceptionT $ (CL.sourceList [BS.pack [10], BS.pack [2]]) C.$= fancyConduit C.$$ CL.consume))+ (showLeft (runConduit ((CL.sourceList [BS.pack [10], BS.pack [2]]) .| fancyConduit .| CL.consume)))) where fancyConduit = do- conduitGet threeItemGet C.=$= CL.map (\ x -> Right x)+ conduitGet threeItemGet .| CL.map (\ x -> Right x) recurse- where recurse = C.await >>= maybe (return ()) (\ x -> C.yield (Left x) >> recurse)+ where recurse = await >>= maybe (return ()) (\ x -> yield (Left x) >> recurse) conduittest15 :: Test conduittest15 = TestCase (assertEqual "Leftover premature end conduit input works" (Right ([], BS.singleton 1))- (runIdentity $ runExceptionT $ (CL.sourceList [BS.singleton 1]) C.$$ (do- output <- (conduitGet twoItemGet) C.=$ (CL.take 1)+ (showLeft (runConduit ((CL.sourceList [BS.singleton 1]) .| (do+ output <- (conduitGet twoItemGet) .| (CL.take 1) output' <- CL.consume- return (output, BS.concat output'))))+ return (output, BS.concat output')))))) conduittest16 :: Test conduittest16 = TestCase (assertEqual "Leftover failure conduit input works"- (Right [Left $ BS.pack [10, 11], Left $ BS.singleton 2])- (runIdentity $ runExceptionT $ (CL.sourceList [BS.pack [10, 11], BS.pack [2]]) C.$= fancyConduit C.$$ CL.consume))+ (Right [Left $ BS.pack [10, 11], Left $ BS.singleton 2]+ :: Either String [Either BS.ByteString Word8])+ (showLeft (runConduit ((CL.sourceList [BS.pack [10, 11], BS.pack [2]]) .| fancyConduit .| CL.consume)))) where fancyConduit = do- mkConduitGet (const $ return ()) (getWord8 >> fail "asdf" :: Get Word8) C.=$= CL.map (\ x -> Right x)+ mkConduitGet (const $ return ()) (getWord8 >> fail "asdf" :: Get Word8) .| CL.map (\ x -> Right x) recurse- where recurse = C.await >>= maybe (return ()) (\ x -> C.yield (Left x) >> recurse)+ where recurse = await >>= maybe (return ()) (\ x -> yield (Left x) >> recurse) conduittest17 :: Test conduittest17 = TestCase (assertEqual "Leftover failure conduit with broken input works"- (Right [Left $ BS.pack [10, 11], Left $ BS.singleton 12])- (runIdentity $ runExceptionT $ (CL.sourceList [BS.singleton 10, BS.singleton 11, BS.singleton 12]) C.$= fancyConduit C.$$ CL.consume))+ (Right [Left $ BS.pack [10, 11], Left $ BS.singleton 12]+ :: Either String [Either BS.ByteString Word8])+ (runConduit ((CL.sourceList [BS.singleton 10, BS.singleton 11, BS.singleton 12]) .| fancyConduit .| CL.consume))) where fancyConduit = do- mkConduitGet (const $ return ()) (twoItemGet >> fail "asdf" :: Get Word8) C.=$= CL.map (\ x -> Right x)+ mkConduitGet (const $ return ()) (twoItemGet >> fail "asdf" :: Get Word8) .| CL.map (\ x -> Right x) recurse- where recurse = C.await >>= maybe (return ()) (\ x -> C.yield (Left x) >> recurse)+ where recurse = await >>= maybe (return ()) (\ x -> yield (Left x) >> recurse) -- see https://github.com/snoyberg/conduit/issues/246 conduittest18 :: Test conduittest18 = TestCase $ assertEqual "Deals with Get that consumes everything"- (Right ["hello"])- (runIdentity $ runExceptionT- $ (C.yield "hello"- C.$= conduitGet2 slurp- C.$$ CL.consume))+ (Right [S8.pack "hello"])+ ( showLeft $ runConduit $+ (yield "hello"+ .| conduitGet2 slurp+ .| CL.consume)) slurp :: Get BS.ByteString slurp =@@ -246,18 +254,19 @@ puttest1 :: Test puttest1 = TestCase (assertEqual "conduitPut works" [BS.pack [0, 1]]- (runIdentity $ (CL.sourceList ['a']) C.$= (conduitPut putter) C.$$ CL.consume))+ (runConduitPure $ (CL.sourceList ['a']) .| (conduitPut putter) .| CL.consume)) puttest2 :: Test puttest2 = TestCase (assertEqual "multiple input conduitPut works" [BS.pack [0, 1], BS.pack [1, 2], BS.pack [2, 3]]- (runIdentity $ (CL.sourceList ['a', 'b', 'c']) C.$= (conduitPut putter) C.$$ CL.consume))+ (runConduitPure $ (CL.sourceList ['a', 'b', 'c']) .| (conduitPut putter) .| CL.consume)) puttest3 :: Test puttest3 = TestCase (assertEqual "empty input conduitPut works" []- (runIdentity $ (CL.sourceList []) C.$= (conduitPut putter) C.$$ CL.consume))+ (runConduitPure ((CL.sourceList []) .| (conduitPut putter) .| CL.consume))) +sinktests :: Test sinktests = TestList [ sinktest1 , sinktest2 , sinktest3@@ -269,6 +278,7 @@ , sinktest9 ] +conduittests :: Test conduittests = TestList [ conduittest1 , conduittest2 , conduittest3@@ -289,17 +299,20 @@ , conduittest18 ] +puttests :: Test puttests = TestList [ puttest1 , puttest2 , puttest3 ] +hunittests :: Test hunittests = TestList [sinktests, conduittests, puttests] --tests = hUnitTestToTests hunittests +main :: IO () main = do- counts <- runTestTT hunittests- if errors counts == 0 && failures counts == 0+ counts' <- runTestTT hunittests+ if errors counts' == 0 && failures counts' == 0 then exitSuccess else exitFailure
cereal-conduit.cabal view
@@ -1,5 +1,5 @@ name: cereal-conduit-version: 0.7.3+version: 0.8.0 license: BSD3 license-file: LICENSE author: Myles C. Maxfield <myles.maxfield@gmail.com>@@ -16,9 +16,9 @@ extra-source-files: README.md ChangeLog.md library- build-depends: base >= 4 && < 5- , conduit >= 1.0.0 && < 1.3- , resourcet >= 0.4 && < 1.2+ build-depends: base >= 4.9 && < 5+ , conduit >= 1.0.0 && < 1.4+ , resourcet >= 0.4 && < 1.3 , cereal >= 0.4.0.0 && < 0.6 , bytestring , transformers >= 0.2.0.0@@ -37,7 +37,6 @@ , bytestring --, test-framework-hunit , HUnit- , resourcet , mtl , transformers