Skip to content

Commit

Permalink
Some notes, kind of a checkpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
jphmrst committed Sep 27, 2023
1 parent 3de71f4 commit dff088a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
8 changes: 6 additions & 2 deletions src/Test/TLT/Assertion.hs
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,12 @@ infix 0 ~:, ~::, ~::-
-- > "2 not 3" ~: 2 @/=- 3 -- This test fails.
(~:) :: forall m n . MonadTLT m n => String -> Assertion m -> m ()
s ~: a = do
state <- liftTLT $ TLT $ get
assessment <- a
state <- liftTLT $ TLT get
{-
let -- interceptor :: m [TestFail] -> m [TestFail]
interceptor = tltStateInterceptor state
-}
assessment <- {- interceptor -} a
liftTLT $ TLT $ put $
state { tltStateAccum =
addResult (tltStateAccum state) $
Expand Down
13 changes: 7 additions & 6 deletions src/Test/TLT/Class.hs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Main state and monad definitions for the @TLT@ testing system. See
-}

{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE UndecidableInstances #-}
{-# LANGUAGE FunctionalDependencies #-}
{-# LANGUAGE KindSignatures #-}
Expand Down Expand Up @@ -53,7 +54,7 @@ interceptNothing = id
data TLTstate (m :: Type -> Type) = TLTstate {
tltStateOptions :: TLTopts,
tltStateAccum :: TRBuf,
tltInterceptor :: Interceptor m
tltStateInterceptor :: Interceptor m
}

-- |Monad transformer for TLT tests. This layer stores the results
Expand Down Expand Up @@ -127,7 +128,7 @@ runTLT (TLT t) = do
(_, state) <- runStateT t $ TLTstate {
tltStateOptions = defaultOpts,
tltStateAccum = Top 0 0 [],
tltInterceptor = interceptNothing
tltStateInterceptor = interceptNothing
}
return (tltStateOptions state, closeTRBuf $ tltStateAccum state)

Expand Down Expand Up @@ -184,15 +185,15 @@ inGroup name group = do
-- | Call prior to a series of TLT tests to detect general errors.
-- Requires that the underlying computation be `MonadIO`.
withIOErrorsByTLT ::
(MonadTLT m n, MonadIO n) => (n [TestFail] -> IO [TestFail]) -> m ()
withIOErrorsByTLT runner = liftTLT $ TLT $ do
MonadIO m => (m [TestFail] -> IO [TestFail]) -> TLT m ()
withIOErrorsByTLT runner = TLT $ do
state <- get
put $ state { tltInterceptor = interceptExceptions runner }
put $ state { tltStateInterceptor = interceptExceptions runner }

-- | Call prior to a series of TLT tests to detect general errors.
-- Requires that the underlying computation be `MonadIO`.
interceptExceptions ::
(MonadIO m) => (m [TestFail] -> IO [TestFail]) -> Interceptor m
MonadIO m => (m [TestFail] -> IO [TestFail]) -> Interceptor m
interceptExceptions runner a =
liftIO $ catch (runner a) $
\e -> return $ [Erred $ show $ (e :: SomeException)]
Expand Down

0 comments on commit dff088a

Please sign in to comment.