2022-04-01 03:48:48 +00:00
|
|
|
{-# LANGUAGE ScopedTypeVariables #-}
|
|
|
|
{-# LANGUAGE TypeApplications #-}
|
2019-10-29 18:47:13 +00:00
|
|
|
|
2019-10-29 18:15:52 +00:00
|
|
|
module Main where
|
|
|
|
|
2022-04-01 03:48:48 +00:00
|
|
|
import Prelude hiding (ioError)
|
2019-10-29 18:47:13 +00:00
|
|
|
|
|
|
|
import Control.Carrier.Lift (runM)
|
2022-04-01 03:48:48 +00:00
|
|
|
import qualified Control.Carrier.State.Strict as State
|
2019-10-29 18:47:13 +00:00
|
|
|
import Control.Effect.Exception
|
|
|
|
import Control.Effect.State
|
2022-04-01 03:48:48 +00:00
|
|
|
import qualified Test.Tasty as Tasty
|
|
|
|
import qualified Test.Tasty.HUnit as HUnit
|
2019-10-29 18:47:13 +00:00
|
|
|
|
|
|
|
problematic :: (Has (Lift IO) sig m, Has (State Char) sig m) => m ()
|
|
|
|
problematic =
|
|
|
|
let throws = modify @Char succ *> throwIO (userError "should explode") `finally` put @Char 'x'
|
|
|
|
in throws `catch` (\(_ :: IOException) -> pure ())
|
|
|
|
|
|
|
|
testStateDropsWrites :: Tasty.TestTree
|
|
|
|
testStateDropsWrites = HUnit.testCase "State.Strict drops writes" $ do
|
2020-07-13 15:15:51 +00:00
|
|
|
result <- State.execState 'a' problematic
|
2019-10-29 18:47:13 +00:00
|
|
|
result HUnit.@?= 'a' -- writes are lost
|
|
|
|
|
|
|
|
tests :: Tasty.TestTree
|
|
|
|
tests = Tasty.testGroup "Control.Carrier.Exception"
|
|
|
|
[ Tasty.testGroup "finally"
|
|
|
|
[ testStateDropsWrites
|
|
|
|
]
|
|
|
|
]
|
|
|
|
|
2019-10-29 18:15:52 +00:00
|
|
|
main :: IO ()
|
2019-10-29 18:47:13 +00:00
|
|
|
main = Tasty.defaultMain tests
|