Skip to content

Commit b5373bd

Browse files
committed
minor pretty printing
1 parent a2e3084 commit b5373bd

File tree

2 files changed

+14
-13
lines changed

2 files changed

+14
-13
lines changed

quickcheck-dynamic/src/Test/QuickCheck/StateModel.hs

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ instance {-# OVERLAPPING #-} IsPerformResult Void a where
211211
instance {-# OVERLAPPABLE #-} (EitherIsh e a ~ Either e a) => IsPerformResult e a where
212212
performResultToEither = id
213213

214-
class (forall a. Show (Action state a), Monad m) => RunModel state m where
214+
class (forall a. Show (Action state a), Show (Error state m), Monad m) => RunModel state m where
215215
-- | The type of errors that actions can throw. If this is defined as anything
216216
-- other than `Void` `perform` is required to return `Either (Error state) a`
217217
-- instead of `a`.
@@ -377,7 +377,7 @@ instance StateModel state => Show (Actions state) where
377377
showWithUsed :: StateModel state => VarContext -> Actions state -> String
378378
showWithUsed ctx (Actions as) =
379379
let as' = WithUsedVars (combineContexts ctx $ usedVariables (Actions as)) <$> as
380-
in intercalate "\n" $ zipWith (++) ("do " : repeat " ") (map show as' ++ ["pure ()"])
380+
in intercalate "\n" $ zipWith (++) ("do " : repeat " ") (map show as' ++ ["pure ()" | null as'])
381381

382382
usedVariables :: forall state. StateModel state => Actions state -> VarContext
383383
usedVariables (Actions as) = go initialAnnotatedState as
@@ -683,11 +683,11 @@ commonActions ParallelActions{linearActions = Actions steps, ..} =
683683

684684
threadAActions :: ParallelActions state -> [Step state]
685685
threadAActions ParallelActions{linearActions = Actions steps, ..} =
686-
[ step | step@(v := _) <- steps, elem (unsafeVarIndex v) threadATags ]
686+
[ v := s{polarity = PosPolarity} | v := s <- steps, elem (unsafeVarIndex v) threadATags ]
687687

688688
threadBActions :: ParallelActions state -> [Step state]
689689
threadBActions ParallelActions{linearActions = Actions steps, ..} =
690-
[ step | step@(v := _) <- steps, elem (unsafeVarIndex v) threadBTags ]
690+
[ v := s{polarity = PosPolarity} | v := s <- steps, elem (unsafeVarIndex v) threadBTags ]
691691

692692
instance StateModel state => Show (ParallelActions state) where
693693
show pas =
@@ -793,12 +793,13 @@ runParActions :: ( StateModel state
793793
, ForkYou m
794794
) => ParallelActions state -> PropertyM m ()
795795
runParActions pas = do
796-
monitor $ counterexample "-- Monitoring main thread"
797796
(trC, env) <- run $ runTracing mempty $ commonActions pas
798797
joinA <- run $ forkThread $ runTracing env (threadAActions pas)
799798
joinB <- run $ forkThread $ runTracing env (threadBActions pas)
800799
(trA, _) <- run joinA
801800
(trB, _) <- run joinB
801+
monitor $ counterexample "-- Monitoring main thread"
802+
monitorTrace mempty trC
802803
monitor $ counterexample "-- Monitoring thread A"
803804
monitorTrace env trA
804805
monitor $ counterexample "-- Monitoring thread B"
@@ -811,8 +812,11 @@ runParActions pas = do
811812
monitorTrace :: forall state m. (StateModel state, RunModelPar state m)
812813
=> Env -> Trace state m -> PropertyM m ()
813814
monitorTrace _env [] = pure ()
814-
monitorTrace env (TraceStep r v step : tr) = do
815-
monitor $ monitoringPar @state @m (polarAction step) (lookUpVar env) r
815+
monitorTrace env (TraceStep r v act : tr) = do
816+
let showR (Right x) = show x
817+
showR (Left err) = "fail " ++ showsPrec 10 err ""
818+
monitor $ counterexample (showR r ++ " <- " ++ show (polarAction act))
819+
monitor $ monitoringPar @state @m (polarAction act) (lookUpVar env) r
816820
monitorTrace env' tr
817821
where
818822
env' | Right val <- r = (v :== val) : env

quickcheck-dynamic/test/Spec/DynamicLogic/RegistryModel.hs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -109,17 +109,17 @@ instance StateModel RegState where
109109
type RegM = ReaderT Registry IO
110110

111111
instance RunModel RegState RegM where
112-
type Error RegState RegM = SomeException
112+
type Error RegState RegM = String
113113

114114
perform _ Spawn _ = do
115115
tid <- lift $ forkIO (threadDelay 10000000)
116116
pure $ Right tid
117117
perform _ (Register name tid) env = do
118118
reg <- ask
119-
lift $ try $ register reg name (env tid)
119+
lift $ fmap (either (Left . displayException . toException @SomeException) Right) $ try $ register reg name (env tid)
120120
perform _ (Unregister name) _ = do
121121
reg <- ask
122-
lift $ try $ unregister reg name
122+
lift $ fmap (either (Left . displayException . toException @SomeException) Right) $ try $ unregister reg name
123123
perform _ (WhereIs name) _ = do
124124
reg <- ask
125125
res <- lift $ whereis reg name
@@ -158,9 +158,6 @@ instance RunModelPar RegState RegM where
158158
pure $ isLeft res
159159
postconditionOnFailurePar _ _ _ _ = pure True
160160

161-
monitoringPar act@(showDictAction -> ShowDict) _ res =
162-
QC.counterexample (show res ++ " <- " ++ show act)
163-
164161
data ShowDict a where
165162
ShowDict :: Show a => ShowDict a
166163

0 commit comments

Comments
 (0)