Skip to content
This repository was archived by the owner on Jun 18, 2021. It is now read-only.

Commit 589109f

Browse files
edskomrBliss
andcommitted
Avoid unnecessary use of run
The top-level of a QSM test typically looks something like this: ```haskell forAllCommands ... $ \cmds -> QC.monadicIO $ do (hist, prop) <- .... runCommands ... prettyCommands ... ``` The problem is that `runCommands` lives in `PropertyM`. This makes it impossible to do any kind of bracketing. Fortunately, it turns out that this use of `PropertyM` is actually not needed at all. In this commit, I add `runCommands'`, which lives in `m`. To avoid breaking backwards compatibility, `runCommands` still lives in `PropertyM` and is a combination of `run` and `runCommands'`. This will allow us to do something like: ```haskell forAllCommands ... $ \cmds -> QC.monadicIO $ do (hist, prop) <- .... run (bracket ... $ \r -> runCommands' .. r .. ) ... prettyCommands ... ``` Co-authored-by: Thomas Winant <[email protected]> Signed-off-by: Edsko de Vries <[email protected]>
1 parent 5feea58 commit 589109f

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

src/Test/StateMachine/Sequential.hs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ module Test.StateMachine.Sequential
3535
, ShouldShrink(..)
3636
, initValidateEnv
3737
, runCommands
38+
, runCommands'
3839
, getChanContents
3940
, Check(..)
4041
, executeCommands
@@ -325,9 +326,16 @@ runCommands :: (Show (cmd Concrete), Show (resp Concrete))
325326
=> StateMachine model cmd m resp
326327
-> Commands cmd resp
327328
-> PropertyM m (History cmd resp, model Concrete, Reason)
328-
runCommands sm@StateMachine { initModel, cleanup } = run . go
329-
where
330-
go cmds = mask $ \restore -> do
329+
runCommands sm cmds = run $ runCommands' sm cmds
330+
331+
runCommands' :: (Show (cmd Concrete), Show (resp Concrete))
332+
=> (Rank2.Traversable cmd, Rank2.Foldable resp)
333+
=> (MonadMask m, MonadIO m)
334+
=> StateMachine model cmd m resp
335+
-> Commands cmd resp
336+
-> m (History cmd resp, model Concrete, Reason)
337+
runCommands' sm@StateMachine { initModel, cleanup } cmds =
338+
mask $ \restore -> do
331339
hchan <- restore newTChanIO
332340
(reason, (_, _, _, model)) <- restore
333341
(runStateT

0 commit comments

Comments
 (0)