summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoman Smrž <roman.smrz@seznam.cz>2026-11-22 09:02:05 +0100
committerRoman Smrž <roman.smrz@seznam.cz>2026-11-27 20:34:52 +0100
commit2b576ca2c8965d112647f56ed96020266247a37a (patch)
treec8d39506491e904d472b36a6327cc6fa1d13a88f
parentf5a5f2c57f57ce5780f56f854bd6e6e1f8896699 (diff)
Turn exceptions to test errorsHEADmaster
-rw-r--r--src/Run/Monad.hs19
1 files changed, 15 insertions, 4 deletions
diff --git a/src/Run/Monad.hs b/src/Run/Monad.hs
index 0651792..3fda255 100644
--- a/src/Run/Monad.hs
+++ b/src/Run/Monad.hs
@@ -16,6 +16,7 @@ module Run.Monad (
import Control.Concurrent
import Control.Concurrent.STM
+import Control.Exception qualified as CE
import Control.Monad
import Control.Monad.Except
import Control.Monad.Reader
@@ -39,7 +40,6 @@ newtype TestRun a = TestRun { fromTestRun :: ReaderT ( SingleTestEnv, TestState
( Functor, Applicative, Monad
, MonadReader ( SingleTestEnv, TestState )
, MonadWriter [ SomeObject TestRun ]
- , MonadIO
)
data GlobalTestEnv = GlobalTestEnv
@@ -122,6 +122,20 @@ instance MonadError Failed TestRun where
catchError (TestRun act) handler = TestRun $ catchError act $ fromTestRun . handler
+instance MonadIO TestRun where
+ liftIO act = do
+ TestRun (liftIO (CE.try @CE.SomeException act)) >>= \case
+ Right x -> return x
+ Left err
+ | Just async <- CE.fromException @CE.SomeAsyncException err
+ -> TestRun (liftIO (CE.throwIO async))
+ | otherwise
+ -> do
+ -- avoid call to this liftIO and potential throw-catch cycle from the write
+ out <- getOutput
+ TestRun (liftIO (flip runReaderT out $ outLine OutputError Nothing $ T.pack $ show err))
+ throwError Failed
+
instance MonadEval TestRun where
askGlobalDefs = asks (tsGlobals . snd)
askDictionary = asks (tsLocals . snd)
@@ -130,9 +144,6 @@ instance MonadEval TestRun where
instance MonadOutput TestRun where
getOutput = asks $ teOutput . teGlobal . fst
-instance MonadPIO TestRun where
- postpone = liftIO
-
finally :: MonadError e m => m a -> m b -> m a
finally act handler = do