summaryrefslogtreecommitdiff
path: root/src/Run.hs
diff options
context:
space:
mode:
authorRoman Smrž <roman.smrz@seznam.cz>2023-10-23 21:05:55 +0200
committerRoman Smrž <roman.smrz@seznam.cz>2023-10-23 21:05:55 +0200
commit224366e2c668784952ab613c7640d7017ce60990 (patch)
treeebbad4d9d53119c6f1b0f74ada973efa8ac06a86 /src/Run.hs
parentff5c3f5a91e249694f3b76109027cf9d0c717a7c (diff)
Flush command
Changelog: Add 'flush' command
Diffstat (limited to 'src/Run.hs')
-rw-r--r--src/Run.hs13
1 files changed, 13 insertions, 0 deletions
diff --git a/src/Run.hs b/src/Run.hs
index 04fa9ee..a40641b 100644
--- a/src/Run.hs
+++ b/src/Run.hs
@@ -10,6 +10,7 @@ import Control.Monad
import Control.Monad.Except
import Control.Monad.Reader
+import Data.Either
import Data.Map qualified as M
import Data.Maybe
import Data.Set qualified as S
@@ -151,6 +152,10 @@ evalSteps = mapM_ $ \case
p <- eval pname
expect line p expr captures $ evalSteps inner
+ Flush pname expr -> do
+ p <- eval pname
+ flush p expr
+
Guard line expr -> do
testStepGuard line expr
@@ -304,6 +309,14 @@ expect (SourceLine sline) p expr tvars inner = do
Nothing -> exprFailed (T.pack "expect") (SourceLine sline) (Just $ procName p) expr
+flush :: Process -> Maybe (Expr Regex) -> TestRun ()
+flush p mbexpr = do
+ mbre <- sequence $ fmap eval mbexpr
+ atomicallyTest $ do
+ writeTVar (procOutput p) =<< case mbre of
+ Nothing -> return []
+ Just re -> filter (isLeft . regexMatch re) <$> readTVar (procOutput p)
+
testStepGuard :: SourceLine -> Expr Bool -> TestRun ()
testStepGuard sline expr = do
x <- eval expr