on master help sign in
Add tests for before and after.
babd1a2pranaysashank
test/Streamly/Test/Prelude/Ahead.hs+1
@@ -126,6 +126,7 @@ main = hspec
126 aheadOps $ eliminationOpsOrdered S.fromFoldable "aheadly"
126 aheadOps $ eliminationOpsOrdered S.fromFoldable "aheadly"
127 aheadOps $ eliminationOpsOrdered folded "aheadly folded"
127 aheadOps $ eliminationOpsOrdered folded "aheadly folded"
128
128
129+ describe "Tests for exceptions" $ aheadOps $ exceptionOps "aheadly"
129 describe "Composed MonadThrow aheadly" $ composeWithMonadThrow S.aheadly
130 describe "Composed MonadThrow aheadly" $ composeWithMonadThrow S.aheadly
130
131
131 -- Ad-hoc tests
132 -- Ad-hoc tests
test/Streamly/Test/Prelude/Async.hs+1
@@ -101,6 +101,7 @@ main = hspec
101 describe "Async mappend time order check" $ parallelCheck asyncly mappend
101 describe "Async mappend time order check" $ parallelCheck asyncly mappend
102#endif
102#endif
103
103
104+ describe "Tests for exceptions" $ asyncOps $ exceptionOps "asyncly"
104 describe "Composed MonadThrow asyncly" $ composeWithMonadThrow asyncly
105 describe "Composed MonadThrow asyncly" $ composeWithMonadThrow asyncly
105
106
106 -- Ad-hoc tests
107 -- Ad-hoc tests
test/Streamly/Test/Prelude/Common.hs+29
@@ -66,6 +66,8 @@ module Streamly.Test.Prelude.Common
66 , zipMonadic
66 , zipMonadic
67 , zipAsyncApplicative
67 , zipAsyncApplicative
68 , zipAsyncMonadic
68 , zipAsyncMonadic
69+ -- * Exception operations
70+ , exceptionOps
69 -- * MonadThrow operations
71 -- * MonadThrow operations
70 , composeWithMonadThrow
72 , composeWithMonadThrow
71 -- * Cleanup tests
73 -- * Cleanup tests
@@ -1372,6 +1374,33 @@ parallelCheck t f = do
1372
1374
1373 where event n = S.yieldM (threadDelay (n * 200000)) >> return n
1375 where event n = S.yieldM (threadDelay (n * 200000)) >> return n
1374
1376
1377+-------------------------------------------------------------------------------
1378+-- Exception ops
1379+-------------------------------------------------------------------------------
1380+
1381+exceptionOps :: IsStream t => String -> (t IO Int -> SerialT IO Int) -> Spec
1382+exceptionOps desc t = do
1383+ prop (desc <> " before") $ beforeProp t
1384+ prop (desc <> " after") $ afterProp t
1385+
1386+beforeProp :: IsStream t => (t IO Int -> SerialT IO Int) -> [Int] -> Property
1387+beforeProp t vec = withMaxSuccess maxTestCount $
1388+ monadicIO $ do
1389+ ioRef <- run $ newIORef False
1390+ strm <- run $ S.toList . t $ S.before (writeIORef ioRef True) (S.fromList vec)
1391+ refValue <- run $ readIORef ioRef
1392+ assert refValue
1393+ assert $ sort strm == sort vec
1394+
1395+afterProp :: IsStream t => (t IO Int -> SerialT IO Int) -> [Int] -> Property
1396+afterProp t vec = withMaxSuccess maxTestCount $
1397+ monadicIO $ do
1398+ ioRef <- run $ newIORef False
1399+ strm <- run $ S.toList . t $ S.after (writeIORef ioRef True) (S.fromList vec)
1400+ refValue <- run $ readIORef ioRef
1401+ assert refValue
1402+ assert $ sort strm == sort vec
1403+
1375-------------------------------------------------------------------------------
1404-------------------------------------------------------------------------------
1376-- Compose with MonadThrow
1405-- Compose with MonadThrow
1377-------------------------------------------------------------------------------
1406-------------------------------------------------------------------------------
test/Streamly/Test/Prelude/Parallel.hs+1
@@ -105,6 +105,7 @@ main = hspec
105 describe "Parallel mappend time order check" $ parallelCheck parallely mappend
105 describe "Parallel mappend time order check" $ parallelCheck parallely mappend
106#endif
106#endif
107
107
108+ describe "Tests for exceptions" $ parallelOps $ exceptionOps "parallely"
108 describe "Composed MonadThrow parallely" $ composeWithMonadThrow parallely
109 describe "Composed MonadThrow parallely" $ composeWithMonadThrow parallely
109
110
110#ifdef DEVBUILD
111#ifdef DEVBUILD
test/Streamly/Test/Prelude/Serial.hs+2
@@ -583,6 +583,8 @@ main = hspec
583
583
584 describe "Tests for S.groupsBy" groupingOps
584 describe "Tests for S.groupsBy" groupingOps
585
585
586+ describe "Tests for exceptions" $ serialOps $ exceptionOps "serially"
587+
586 describe "Composed MonadThrow serially" $ composeWithMonadThrow serially
588 describe "Composed MonadThrow serially" $ composeWithMonadThrow serially
587
589
588 it "fromCallback" $ testFromCallback `shouldReturn` (50*101)
590 it "fromCallback" $ testFromCallback `shouldReturn` (50*101)
test/Streamly/Test/Prelude/WAsync.hs+1
@@ -109,6 +109,7 @@ main = hspec
109 -- describe "WAsync mappend time order check" $
109 -- describe "WAsync mappend time order check" $
110 -- parallelCheck wAsyncly mappend
110 -- parallelCheck wAsyncly mappend
111
111
112+ describe "Tests for exceptions" $ wAsyncOps $ exceptionOps "wAsyncly"
112 describe "Composed MonadThrow wAsyncly" $ composeWithMonadThrow wAsyncly
113 describe "Composed MonadThrow wAsyncly" $ composeWithMonadThrow wAsyncly
113
114
114 -- Ad-hoc tests
115 -- Ad-hoc tests
test/Streamly/Test/Prelude/WSerial.hs+1
@@ -153,4 +153,5 @@ main = hspec
153 describe "WSerial interleaved mappend ordering check" $
153 describe "WSerial interleaved mappend ordering check" $
154 interleaveCheck wSerially mappend
154 interleaveCheck wSerially mappend
155
155
156+ describe "Tests for exceptions" $ wSerialOps $ exceptionOps "wSerially"
156 describe "Composed MonadThrow wSerially" $ composeWithMonadThrow wSerially
157 describe "Composed MonadThrow wSerially" $ composeWithMonadThrow wSerially