on master help sign in
Add tests for before and after.
commitbabd1a2974485a527a43fa9ec55e01107fd2925a authorpranaysashank <pranaysashank@composewell.com> dateThu 26 Nov 2020, 10:58 (6 years ago) parent5fe15b9
7 files changed+36
test/Streamly/Test/Prelude/Ahead.hs+1 test/Streamly/Test/Prelude/Async.hs+1 test/Streamly/Test/Prelude/Common.hs+29 test/Streamly/Test/Prelude/Parallel.hs+1 test/Streamly/Test/Prelude/Serial.hs+2 test/Streamly/Test/Prelude/WAsync.hs+1 test/Streamly/Test/Prelude/WSerial.hs+1
test/Streamly/Test/Prelude/Ahead.hs+1
@@ -126,6 +126,7 @@ main = hspec
126126 aheadOps $ eliminationOpsOrdered S.fromFoldable "aheadly"
127127 aheadOps $ eliminationOpsOrdered folded "aheadly folded"
128128
129+ describe "Tests for exceptions" $ aheadOps $ exceptionOps "aheadly"
129130 describe "Composed MonadThrow aheadly" $ composeWithMonadThrow S.aheadly
130131
131132 -- Ad-hoc tests
test/Streamly/Test/Prelude/Async.hs+1
@@ -101,6 +101,7 @@ main = hspec
101101 describe "Async mappend time order check" $ parallelCheck asyncly mappend
102102#endif
103103
104+ describe "Tests for exceptions" $ asyncOps $ exceptionOps "asyncly"
104105 describe "Composed MonadThrow asyncly" $ composeWithMonadThrow asyncly
105106
106107 -- Ad-hoc tests
test/Streamly/Test/Prelude/Common.hs+29
@@ -66,6 +66,8 @@ module Streamly.Test.Prelude.Common
6666 , zipMonadic
6767 , zipAsyncApplicative
6868 , zipAsyncMonadic
69+ -- * Exception operations
70+ , exceptionOps
6971 -- * MonadThrow operations
7072 , composeWithMonadThrow
7173 -- * Cleanup tests
@@ -1372,6 +1374,33 @@ parallelCheck t f = do
13721374
13731375 where event n = S.yieldM (threadDelay (n * 200000)) >> return n
13741376
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+
13751404-------------------------------------------------------------------------------
13761405-- Compose with MonadThrow
13771406-------------------------------------------------------------------------------
test/Streamly/Test/Prelude/Parallel.hs+1
@@ -105,6 +105,7 @@ main = hspec
105105 describe "Parallel mappend time order check" $ parallelCheck parallely mappend
106106#endif
107107
108+ describe "Tests for exceptions" $ parallelOps $ exceptionOps "parallely"
108109 describe "Composed MonadThrow parallely" $ composeWithMonadThrow parallely
109110
110111#ifdef DEVBUILD
test/Streamly/Test/Prelude/Serial.hs+2
@@ -583,6 +583,8 @@ main = hspec
583583
584584 describe "Tests for S.groupsBy" groupingOps
585585
586+ describe "Tests for exceptions" $ serialOps $ exceptionOps "serially"
587+
586588 describe "Composed MonadThrow serially" $ composeWithMonadThrow serially
587589
588590 it "fromCallback" $ testFromCallback `shouldReturn` (50*101)
test/Streamly/Test/Prelude/WAsync.hs+1
@@ -109,6 +109,7 @@ main = hspec
109109 -- describe "WAsync mappend time order check" $
110110 -- parallelCheck wAsyncly mappend
111111
112+ describe "Tests for exceptions" $ wAsyncOps $ exceptionOps "wAsyncly"
112113 describe "Composed MonadThrow wAsyncly" $ composeWithMonadThrow wAsyncly
113114
114115 -- Ad-hoc tests
test/Streamly/Test/Prelude/WSerial.hs+1
@@ -153,4 +153,5 @@ main = hspec
153153 describe "WSerial interleaved mappend ordering check" $
154154 interleaveCheck wSerially mappend
155155
156+ describe "Tests for exceptions" $ wSerialOps $ exceptionOps "wSerially"
156157 describe "Composed MonadThrow wSerially" $ composeWithMonadThrow wSerially