@@ -26,8 +26,11 @@ module Control.Monad.IOSim (
26
26
traceEvents ,
27
27
traceResult ,
28
28
selectTraceEvents ,
29
+ selectTraceEvents' ,
29
30
selectTraceEventsDynamic ,
31
+ selectTraceEventsDynamic' ,
30
32
selectTraceEventsSay ,
33
+ selectTraceEventsSay' ,
31
34
printTraceEventsSay ,
32
35
-- * Eventlog
33
36
EventlogEvent (.. ),
@@ -68,6 +71,19 @@ selectTraceEvents fn = go
68
71
go (TraceDeadlock _ threads) = throw (FailureDeadlock threads)
69
72
go (TraceMainReturn _ _ _) = []
70
73
74
+ selectTraceEvents'
75
+ :: (TraceEvent -> Maybe b )
76
+ -> Trace a
77
+ -> [b ]
78
+ selectTraceEvents' fn = go
79
+ where
80
+ go (Trace _ _ _ ev trace) = case fn ev of
81
+ Just x -> x : go trace
82
+ Nothing -> go trace
83
+ go (TraceMainException _ _ _) = []
84
+ go (TraceDeadlock _ _) = []
85
+ go (TraceMainReturn _ _ _) = []
86
+
71
87
-- | Select all the traced values matching the expected type. This relies on
72
88
-- the sim's dynamic trace facility.
73
89
--
@@ -80,6 +96,16 @@ selectTraceEventsDynamic = selectTraceEvents fn
80
96
fn (EventLog dyn) = fromDynamic dyn
81
97
fn _ = Nothing
82
98
99
+ -- | Like 'selectTraceEventsDynamic' but returns partial trace if an excpetion
100
+ -- is found in it.
101
+ --
102
+ selectTraceEventsDynamic' :: forall a b . Typeable b => Trace a -> [b ]
103
+ selectTraceEventsDynamic' = selectTraceEvents' fn
104
+ where
105
+ fn :: TraceEvent -> Maybe b
106
+ fn (EventLog dyn) = fromDynamic dyn
107
+ fn _ = Nothing
108
+
83
109
-- | Get a trace of 'EventSay'.
84
110
--
85
111
-- For convenience, this throws exceptions for abnormal sim termination.
@@ -91,6 +117,16 @@ selectTraceEventsSay = selectTraceEvents fn
91
117
fn (EventSay s) = Just s
92
118
fn _ = Nothing
93
119
120
+ -- | Like 'selectTraceEventsSay' but return partial trace if an exception is
121
+ -- found in it.
122
+ --
123
+ selectTraceEventsSay' :: Trace a -> [String ]
124
+ selectTraceEventsSay' = selectTraceEvents' fn
125
+ where
126
+ fn :: TraceEvent -> Maybe String
127
+ fn (EventSay s) = Just s
128
+ fn _ = Nothing
129
+
94
130
-- | Print all 'EventSay' to the console.
95
131
--
96
132
-- For convenience, this throws exceptions for abnormal sim termination.
0 commit comments