@@ -1415,7 +1415,7 @@ bracketProp t vec =
1415 (\ioref ->
1415 (\ioref ->
1417 (\a -> writeIORef ioref 2 >> return a)
1417 (\a -> writeIORef ioref 2 >> return a)
1418− (S.fromList []))
1418+ (S.fromList vec))
1419 refValue <- run $ readIORef ioRef
1419 refValue <- run $ readIORef ioRef
1420 assert $ refValue == 1
1420 assert $ refValue == 1
@@ -1460,6 +1460,75 @@ bracketExceptionProp t =
1460 refValue <- run $ readIORef ioRef
1460 refValue <- run $ readIORef ioRef
1461 assert $ refValue == 1
1461 assert $ refValue == 1
1463+finallyProp :: (IsStream t) => (t IO Int -> SerialT IO Int) -> [Int] -> Property
1465+ withMaxSuccess maxTestCount $
1467+ ioRef <- run $ newIORef (0 :: Int)
1471+ (writeIORef ioRef 1)
1472+ (S.mapM (\a -> writeIORef ioRef 2 >> return a) (S.fromList vec))
1473+ refValue <- run $ readIORef ioRef
1474+ assert $ refValue == 1
1476+-- XXX This test fails
1477+_finallyPartialStreamProp ::
1478+ (IsStream t) => (t IO Int -> SerialT IO Int) -> [Int] -> Property
1479+_finallyPartialStreamProp t vec =
1480+ forAll (choose (0, length vec)) $ \len -> do
1481+ withMaxSuccess maxTestCount $
1483+ ioRef <- run $ newIORef (0 :: Int)
1488+ (writeIORef ioRef 1)
1490+ (\a -> writeIORef ioRef 2 >> return a)
1493+ refValue <- run $ readIORef ioRef
1494+ assert $ refValue == 1
1496+finallyExceptionProp ::
1497+ (IsStream t, MonadThrow (t IO))
1498+ => (t IO Int -> SerialT IO Int)
1500+finallyExceptionProp t =
1501+ withMaxSuccess maxTestCount $
1503+ ioRef <- run $ newIORef (0 :: Int)
1506+ try . S.drain . t $
1508+ (writeIORef ioRef 1)
1509+ (throwM (ExampleException "E") <> S.nil)
1510+ assert $ res == Left (ExampleException "E")
1511+ refValue <- run $ readIORef ioRef
1512+ assert $ refValue == 1
1515+ (IsStream t, MonadThrow (t IO))
1516+ => (t IO Int -> SerialT IO Int)
1519+ withMaxSuccess maxTestCount $
1521+ ioRef <- run $ newIORef (0 :: Int)
1524+ try . S.drain . t $
1526+ (writeIORef ioRef 1)
1527+ (throwM (ExampleException "E") <> S.nil)
1528+ assert $ res == Left (ExampleException "E")
1529+ refValue <- run $ readIORef ioRef
1530+ assert $ refValue == 1
1463exceptionOps ::
1532exceptionOps ::
1464 (IsStream t, MonadThrow (t IO))
1533 (IsStream t, MonadThrow (t IO))
1465 => String
1534 => String
@@ -1471,6 +1540,10 @@ exceptionOps desc t = do
1471 prop (desc <> " bracket end of stream") $ bracketProp t
1540 prop (desc <> " bracket end of stream") $ bracketProp t
1472 -- prop (desc <> " bracket partial stream") $ bracketPartialStreamProp t
1541 -- prop (desc <> " bracket partial stream") $ bracketPartialStreamProp t
1473 prop (desc <> " bracket exception in stream") $ bracketExceptionProp t
1542 prop (desc <> " bracket exception in stream") $ bracketExceptionProp t
1543+ prop (desc <> " onException") $ onExceptionProp t
1544+ prop (desc <> " finally end of stream") $ finallyProp t
1545+ -- prop (desc <> " finally partial stream") $ finallyPartialStreamProp t
1546+ prop (desc <> " finally exception in stream") $ finallyExceptionProp t
1475-------------------------------------------------------------------------------
1548-------------------------------------------------------------------------------
1476-- Compose with MonadThrow
1549-- Compose with MonadThrow