polysemy/test/InterceptSpec.hs
2019-07-15 12:40:42 -04:00

26 lines
669 B
Haskell

module InterceptSpec where
import Polysemy
import Polysemy.Resource
import Polysemy.Trace
import Test.Hspec
withTraceLogging :: Members '[Trace] r => Sem r a -> Sem r a
withTraceLogging = intercept $ \case
Trace msg -> do
trace $ "logged " <> msg
trace msg
spec :: Spec
spec = describe "intercept" $ do
it "should weave through embedded computations" $ do
let (msgs, ()) = run
. runTraceList
. runResource
. withTraceLogging $ do
trace "outside"
bracket (pure ()) pure (const $ trace "inside")
msgs `shouldBe` ["logged outside", "outside", "logged inside", "inside"]