module Convex.Tasty.Streaming.Types (
Event (..),
TestInfo (..),
TestOutcome (..),
FailureInfo (..),
MonitoringStats (..),
MonitoringLabelStat (..),
MonitoringClassStat (..),
MonitoringTableStat (..),
MonitoringTableEntry (..),
) where
import Convex.Tasty.Streaming.SrcLoc (SrcLocRange, groupRanges, ungroupRanges)
import Convex.Tasty.Streaming.TMSummary (ThreatModelSummary)
import Data.Aeson (FromJSON (..), ToJSON (..), Value, object, withObject, (.:), (.:?), (.=))
import Data.Aeson.Types (Pair)
import Data.Text (Text)
import GHC.Generics (Generic)
data TestInfo = TestInfo
{ TestInfo -> Int
tiId :: !Int
, TestInfo -> Text
tiName :: !Text
, TestInfo -> [Text]
tiPath :: ![Text]
, TestInfo -> Maybe SrcLocRange
tiSrcLoc :: !(Maybe SrcLocRange)
}
deriving (TestInfo -> TestInfo -> Bool
(TestInfo -> TestInfo -> Bool)
-> (TestInfo -> TestInfo -> Bool) -> Eq TestInfo
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: TestInfo -> TestInfo -> Bool
== :: TestInfo -> TestInfo -> Bool
$c/= :: TestInfo -> TestInfo -> Bool
/= :: TestInfo -> TestInfo -> Bool
Eq, Int -> TestInfo -> ShowS
[TestInfo] -> ShowS
TestInfo -> String
(Int -> TestInfo -> ShowS)
-> (TestInfo -> String) -> ([TestInfo] -> ShowS) -> Show TestInfo
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> TestInfo -> ShowS
showsPrec :: Int -> TestInfo -> ShowS
$cshow :: TestInfo -> String
show :: TestInfo -> String
$cshowList :: [TestInfo] -> ShowS
showList :: [TestInfo] -> ShowS
Show, (forall x. TestInfo -> Rep TestInfo x)
-> (forall x. Rep TestInfo x -> TestInfo) -> Generic TestInfo
forall x. Rep TestInfo x -> TestInfo
forall x. TestInfo -> Rep TestInfo x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. TestInfo -> Rep TestInfo x
from :: forall x. TestInfo -> Rep TestInfo x
$cto :: forall x. Rep TestInfo x -> TestInfo
to :: forall x. Rep TestInfo x -> TestInfo
Generic)
instance ToJSON TestInfo where
toJSON :: TestInfo -> Value
toJSON (TestInfo Int
i Text
n [Text]
p Maybe SrcLocRange
mloc) =
[Pair] -> Value
object ([Pair] -> Value) -> [Pair] -> Value
forall a b. (a -> b) -> a -> b
$
[ Key
"id" Key -> Int -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= Int
i
, Key
"name" Key -> Text -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= Text
n
, Key
"path" Key -> [Text] -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= [Text]
p
]
[Pair] -> [Pair] -> [Pair]
forall a. Semigroup a => a -> a -> a
<> [Pair] -> (SrcLocRange -> [Pair]) -> Maybe SrcLocRange -> [Pair]
forall b a. b -> (a -> b) -> Maybe a -> b
maybe [] (\SrcLocRange
l -> [Key
"srcLoc" Key -> SrcLocRange -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= SrcLocRange
l]) Maybe SrcLocRange
mloc
instance FromJSON TestInfo where
parseJSON :: Value -> Parser TestInfo
parseJSON = String -> (Object -> Parser TestInfo) -> Value -> Parser TestInfo
forall a. String -> (Object -> Parser a) -> Value -> Parser a
withObject String
"TestInfo" ((Object -> Parser TestInfo) -> Value -> Parser TestInfo)
-> (Object -> Parser TestInfo) -> Value -> Parser TestInfo
forall a b. (a -> b) -> a -> b
$ \Object
o ->
Int -> Text -> [Text] -> Maybe SrcLocRange -> TestInfo
TestInfo
(Int -> Text -> [Text] -> Maybe SrcLocRange -> TestInfo)
-> Parser Int
-> Parser (Text -> [Text] -> Maybe SrcLocRange -> TestInfo)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
o Object -> Key -> Parser Int
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"id"
Parser (Text -> [Text] -> Maybe SrcLocRange -> TestInfo)
-> Parser Text -> Parser ([Text] -> Maybe SrcLocRange -> TestInfo)
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o Object -> Key -> Parser Text
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"name"
Parser ([Text] -> Maybe SrcLocRange -> TestInfo)
-> Parser [Text] -> Parser (Maybe SrcLocRange -> TestInfo)
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o Object -> Key -> Parser [Text]
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"path"
Parser (Maybe SrcLocRange -> TestInfo)
-> Parser (Maybe SrcLocRange) -> Parser TestInfo
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o Object -> Key -> Parser (Maybe SrcLocRange)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"srcLoc"
data TestOutcome
= TestSuccess
| TestFailure !FailureInfo
deriving (TestOutcome -> TestOutcome -> Bool
(TestOutcome -> TestOutcome -> Bool)
-> (TestOutcome -> TestOutcome -> Bool) -> Eq TestOutcome
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: TestOutcome -> TestOutcome -> Bool
== :: TestOutcome -> TestOutcome -> Bool
$c/= :: TestOutcome -> TestOutcome -> Bool
/= :: TestOutcome -> TestOutcome -> Bool
Eq, Int -> TestOutcome -> ShowS
[TestOutcome] -> ShowS
TestOutcome -> String
(Int -> TestOutcome -> ShowS)
-> (TestOutcome -> String)
-> ([TestOutcome] -> ShowS)
-> Show TestOutcome
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> TestOutcome -> ShowS
showsPrec :: Int -> TestOutcome -> ShowS
$cshow :: TestOutcome -> String
show :: TestOutcome -> String
$cshowList :: [TestOutcome] -> ShowS
showList :: [TestOutcome] -> ShowS
Show, (forall x. TestOutcome -> Rep TestOutcome x)
-> (forall x. Rep TestOutcome x -> TestOutcome)
-> Generic TestOutcome
forall x. Rep TestOutcome x -> TestOutcome
forall x. TestOutcome -> Rep TestOutcome x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. TestOutcome -> Rep TestOutcome x
from :: forall x. TestOutcome -> Rep TestOutcome x
$cto :: forall x. Rep TestOutcome x -> TestOutcome
to :: forall x. Rep TestOutcome x -> TestOutcome
Generic)
data FailureInfo = FailureInfo
{ FailureInfo -> Text
fiReason :: !Text
, FailureInfo -> Text
fiMessage :: !Text
}
deriving (FailureInfo -> FailureInfo -> Bool
(FailureInfo -> FailureInfo -> Bool)
-> (FailureInfo -> FailureInfo -> Bool) -> Eq FailureInfo
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: FailureInfo -> FailureInfo -> Bool
== :: FailureInfo -> FailureInfo -> Bool
$c/= :: FailureInfo -> FailureInfo -> Bool
/= :: FailureInfo -> FailureInfo -> Bool
Eq, Int -> FailureInfo -> ShowS
[FailureInfo] -> ShowS
FailureInfo -> String
(Int -> FailureInfo -> ShowS)
-> (FailureInfo -> String)
-> ([FailureInfo] -> ShowS)
-> Show FailureInfo
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> FailureInfo -> ShowS
showsPrec :: Int -> FailureInfo -> ShowS
$cshow :: FailureInfo -> String
show :: FailureInfo -> String
$cshowList :: [FailureInfo] -> ShowS
showList :: [FailureInfo] -> ShowS
Show, (forall x. FailureInfo -> Rep FailureInfo x)
-> (forall x. Rep FailureInfo x -> FailureInfo)
-> Generic FailureInfo
forall x. Rep FailureInfo x -> FailureInfo
forall x. FailureInfo -> Rep FailureInfo x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. FailureInfo -> Rep FailureInfo x
from :: forall x. FailureInfo -> Rep FailureInfo x
$cto :: forall x. Rep FailureInfo x -> FailureInfo
to :: forall x. Rep FailureInfo x -> FailureInfo
Generic)
instance ToJSON FailureInfo where
toJSON :: FailureInfo -> Value
toJSON (FailureInfo Text
r Text
m) =
[Pair] -> Value
object
[ Key
"reason" Key -> Text -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= Text
r
, Key
"message" Key -> Text -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= Text
m
]
instance FromJSON FailureInfo where
parseJSON :: Value -> Parser FailureInfo
parseJSON = String
-> (Object -> Parser FailureInfo) -> Value -> Parser FailureInfo
forall a. String -> (Object -> Parser a) -> Value -> Parser a
withObject String
"FailureInfo" ((Object -> Parser FailureInfo) -> Value -> Parser FailureInfo)
-> (Object -> Parser FailureInfo) -> Value -> Parser FailureInfo
forall a b. (a -> b) -> a -> b
$ \Object
o ->
Text -> Text -> FailureInfo
FailureInfo
(Text -> Text -> FailureInfo)
-> Parser Text -> Parser (Text -> FailureInfo)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
o Object -> Key -> Parser Text
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"reason"
Parser (Text -> FailureInfo) -> Parser Text -> Parser FailureInfo
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o Object -> Key -> Parser Text
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"message"
data MonitoringLabelStat = MonitoringLabelStat
{ MonitoringLabelStat -> [Text]
mlsLabels :: ![Text]
, MonitoringLabelStat -> Int
mlsCount :: !Int
, MonitoringLabelStat -> Double
mlsPercent :: !Double
}
deriving (MonitoringLabelStat -> MonitoringLabelStat -> Bool
(MonitoringLabelStat -> MonitoringLabelStat -> Bool)
-> (MonitoringLabelStat -> MonitoringLabelStat -> Bool)
-> Eq MonitoringLabelStat
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: MonitoringLabelStat -> MonitoringLabelStat -> Bool
== :: MonitoringLabelStat -> MonitoringLabelStat -> Bool
$c/= :: MonitoringLabelStat -> MonitoringLabelStat -> Bool
/= :: MonitoringLabelStat -> MonitoringLabelStat -> Bool
Eq, Int -> MonitoringLabelStat -> ShowS
[MonitoringLabelStat] -> ShowS
MonitoringLabelStat -> String
(Int -> MonitoringLabelStat -> ShowS)
-> (MonitoringLabelStat -> String)
-> ([MonitoringLabelStat] -> ShowS)
-> Show MonitoringLabelStat
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> MonitoringLabelStat -> ShowS
showsPrec :: Int -> MonitoringLabelStat -> ShowS
$cshow :: MonitoringLabelStat -> String
show :: MonitoringLabelStat -> String
$cshowList :: [MonitoringLabelStat] -> ShowS
showList :: [MonitoringLabelStat] -> ShowS
Show, (forall x. MonitoringLabelStat -> Rep MonitoringLabelStat x)
-> (forall x. Rep MonitoringLabelStat x -> MonitoringLabelStat)
-> Generic MonitoringLabelStat
forall x. Rep MonitoringLabelStat x -> MonitoringLabelStat
forall x. MonitoringLabelStat -> Rep MonitoringLabelStat x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. MonitoringLabelStat -> Rep MonitoringLabelStat x
from :: forall x. MonitoringLabelStat -> Rep MonitoringLabelStat x
$cto :: forall x. Rep MonitoringLabelStat x -> MonitoringLabelStat
to :: forall x. Rep MonitoringLabelStat x -> MonitoringLabelStat
Generic)
instance ToJSON MonitoringLabelStat where
toJSON :: MonitoringLabelStat -> Value
toJSON (MonitoringLabelStat [Text]
labels Int
count Double
percent) =
[Pair] -> Value
object
[ Key
"labels" Key -> [Text] -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= [Text]
labels
, Key
"count" Key -> Int -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= Int
count
, Key
"percent" Key -> Double -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= Double
percent
]
instance FromJSON MonitoringLabelStat where
parseJSON :: Value -> Parser MonitoringLabelStat
parseJSON = String
-> (Object -> Parser MonitoringLabelStat)
-> Value
-> Parser MonitoringLabelStat
forall a. String -> (Object -> Parser a) -> Value -> Parser a
withObject String
"MonitoringLabelStat" ((Object -> Parser MonitoringLabelStat)
-> Value -> Parser MonitoringLabelStat)
-> (Object -> Parser MonitoringLabelStat)
-> Value
-> Parser MonitoringLabelStat
forall a b. (a -> b) -> a -> b
$ \Object
o ->
[Text] -> Int -> Double -> MonitoringLabelStat
MonitoringLabelStat
([Text] -> Int -> Double -> MonitoringLabelStat)
-> Parser [Text] -> Parser (Int -> Double -> MonitoringLabelStat)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
o Object -> Key -> Parser [Text]
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"labels"
Parser (Int -> Double -> MonitoringLabelStat)
-> Parser Int -> Parser (Double -> MonitoringLabelStat)
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o Object -> Key -> Parser Int
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"count"
Parser (Double -> MonitoringLabelStat)
-> Parser Double -> Parser MonitoringLabelStat
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o Object -> Key -> Parser Double
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"percent"
data MonitoringClassStat = MonitoringClassStat
{ MonitoringClassStat -> Text
mcsName :: !Text
, MonitoringClassStat -> Int
mcsCount :: !Int
, MonitoringClassStat -> Double
mcsPercent :: !Double
}
deriving (MonitoringClassStat -> MonitoringClassStat -> Bool
(MonitoringClassStat -> MonitoringClassStat -> Bool)
-> (MonitoringClassStat -> MonitoringClassStat -> Bool)
-> Eq MonitoringClassStat
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: MonitoringClassStat -> MonitoringClassStat -> Bool
== :: MonitoringClassStat -> MonitoringClassStat -> Bool
$c/= :: MonitoringClassStat -> MonitoringClassStat -> Bool
/= :: MonitoringClassStat -> MonitoringClassStat -> Bool
Eq, Int -> MonitoringClassStat -> ShowS
[MonitoringClassStat] -> ShowS
MonitoringClassStat -> String
(Int -> MonitoringClassStat -> ShowS)
-> (MonitoringClassStat -> String)
-> ([MonitoringClassStat] -> ShowS)
-> Show MonitoringClassStat
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> MonitoringClassStat -> ShowS
showsPrec :: Int -> MonitoringClassStat -> ShowS
$cshow :: MonitoringClassStat -> String
show :: MonitoringClassStat -> String
$cshowList :: [MonitoringClassStat] -> ShowS
showList :: [MonitoringClassStat] -> ShowS
Show, (forall x. MonitoringClassStat -> Rep MonitoringClassStat x)
-> (forall x. Rep MonitoringClassStat x -> MonitoringClassStat)
-> Generic MonitoringClassStat
forall x. Rep MonitoringClassStat x -> MonitoringClassStat
forall x. MonitoringClassStat -> Rep MonitoringClassStat x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. MonitoringClassStat -> Rep MonitoringClassStat x
from :: forall x. MonitoringClassStat -> Rep MonitoringClassStat x
$cto :: forall x. Rep MonitoringClassStat x -> MonitoringClassStat
to :: forall x. Rep MonitoringClassStat x -> MonitoringClassStat
Generic)
instance ToJSON MonitoringClassStat where
toJSON :: MonitoringClassStat -> Value
toJSON (MonitoringClassStat Text
name Int
count Double
percent) =
[Pair] -> Value
object
[ Key
"name" Key -> Text -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= Text
name
, Key
"count" Key -> Int -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= Int
count
, Key
"percent" Key -> Double -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= Double
percent
]
instance FromJSON MonitoringClassStat where
parseJSON :: Value -> Parser MonitoringClassStat
parseJSON = String
-> (Object -> Parser MonitoringClassStat)
-> Value
-> Parser MonitoringClassStat
forall a. String -> (Object -> Parser a) -> Value -> Parser a
withObject String
"MonitoringClassStat" ((Object -> Parser MonitoringClassStat)
-> Value -> Parser MonitoringClassStat)
-> (Object -> Parser MonitoringClassStat)
-> Value
-> Parser MonitoringClassStat
forall a b. (a -> b) -> a -> b
$ \Object
o ->
Text -> Int -> Double -> MonitoringClassStat
MonitoringClassStat
(Text -> Int -> Double -> MonitoringClassStat)
-> Parser Text -> Parser (Int -> Double -> MonitoringClassStat)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
o Object -> Key -> Parser Text
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"name"
Parser (Int -> Double -> MonitoringClassStat)
-> Parser Int -> Parser (Double -> MonitoringClassStat)
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o Object -> Key -> Parser Int
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"count"
Parser (Double -> MonitoringClassStat)
-> Parser Double -> Parser MonitoringClassStat
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o Object -> Key -> Parser Double
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"percent"
data MonitoringTableEntry = MonitoringTableEntry
{ MonitoringTableEntry -> Text
mteValue :: !Text
, MonitoringTableEntry -> Int
mteCount :: !Int
}
deriving (MonitoringTableEntry -> MonitoringTableEntry -> Bool
(MonitoringTableEntry -> MonitoringTableEntry -> Bool)
-> (MonitoringTableEntry -> MonitoringTableEntry -> Bool)
-> Eq MonitoringTableEntry
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: MonitoringTableEntry -> MonitoringTableEntry -> Bool
== :: MonitoringTableEntry -> MonitoringTableEntry -> Bool
$c/= :: MonitoringTableEntry -> MonitoringTableEntry -> Bool
/= :: MonitoringTableEntry -> MonitoringTableEntry -> Bool
Eq, Int -> MonitoringTableEntry -> ShowS
[MonitoringTableEntry] -> ShowS
MonitoringTableEntry -> String
(Int -> MonitoringTableEntry -> ShowS)
-> (MonitoringTableEntry -> String)
-> ([MonitoringTableEntry] -> ShowS)
-> Show MonitoringTableEntry
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> MonitoringTableEntry -> ShowS
showsPrec :: Int -> MonitoringTableEntry -> ShowS
$cshow :: MonitoringTableEntry -> String
show :: MonitoringTableEntry -> String
$cshowList :: [MonitoringTableEntry] -> ShowS
showList :: [MonitoringTableEntry] -> ShowS
Show, (forall x. MonitoringTableEntry -> Rep MonitoringTableEntry x)
-> (forall x. Rep MonitoringTableEntry x -> MonitoringTableEntry)
-> Generic MonitoringTableEntry
forall x. Rep MonitoringTableEntry x -> MonitoringTableEntry
forall x. MonitoringTableEntry -> Rep MonitoringTableEntry x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. MonitoringTableEntry -> Rep MonitoringTableEntry x
from :: forall x. MonitoringTableEntry -> Rep MonitoringTableEntry x
$cto :: forall x. Rep MonitoringTableEntry x -> MonitoringTableEntry
to :: forall x. Rep MonitoringTableEntry x -> MonitoringTableEntry
Generic)
instance ToJSON MonitoringTableEntry where
toJSON :: MonitoringTableEntry -> Value
toJSON (MonitoringTableEntry Text
value Int
count) =
[Pair] -> Value
object
[ Key
"value" Key -> Text -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= Text
value
, Key
"count" Key -> Int -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= Int
count
]
instance FromJSON MonitoringTableEntry where
parseJSON :: Value -> Parser MonitoringTableEntry
parseJSON = String
-> (Object -> Parser MonitoringTableEntry)
-> Value
-> Parser MonitoringTableEntry
forall a. String -> (Object -> Parser a) -> Value -> Parser a
withObject String
"MonitoringTableEntry" ((Object -> Parser MonitoringTableEntry)
-> Value -> Parser MonitoringTableEntry)
-> (Object -> Parser MonitoringTableEntry)
-> Value
-> Parser MonitoringTableEntry
forall a b. (a -> b) -> a -> b
$ \Object
o ->
Text -> Int -> MonitoringTableEntry
MonitoringTableEntry
(Text -> Int -> MonitoringTableEntry)
-> Parser Text -> Parser (Int -> MonitoringTableEntry)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
o Object -> Key -> Parser Text
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"value"
Parser (Int -> MonitoringTableEntry)
-> Parser Int -> Parser MonitoringTableEntry
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o Object -> Key -> Parser Int
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"count"
data MonitoringTableStat = MonitoringTableStat
{ MonitoringTableStat -> Text
mtsName :: !Text
, MonitoringTableStat -> [MonitoringTableEntry]
mtsEntries :: ![MonitoringTableEntry]
}
deriving (MonitoringTableStat -> MonitoringTableStat -> Bool
(MonitoringTableStat -> MonitoringTableStat -> Bool)
-> (MonitoringTableStat -> MonitoringTableStat -> Bool)
-> Eq MonitoringTableStat
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: MonitoringTableStat -> MonitoringTableStat -> Bool
== :: MonitoringTableStat -> MonitoringTableStat -> Bool
$c/= :: MonitoringTableStat -> MonitoringTableStat -> Bool
/= :: MonitoringTableStat -> MonitoringTableStat -> Bool
Eq, Int -> MonitoringTableStat -> ShowS
[MonitoringTableStat] -> ShowS
MonitoringTableStat -> String
(Int -> MonitoringTableStat -> ShowS)
-> (MonitoringTableStat -> String)
-> ([MonitoringTableStat] -> ShowS)
-> Show MonitoringTableStat
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> MonitoringTableStat -> ShowS
showsPrec :: Int -> MonitoringTableStat -> ShowS
$cshow :: MonitoringTableStat -> String
show :: MonitoringTableStat -> String
$cshowList :: [MonitoringTableStat] -> ShowS
showList :: [MonitoringTableStat] -> ShowS
Show, (forall x. MonitoringTableStat -> Rep MonitoringTableStat x)
-> (forall x. Rep MonitoringTableStat x -> MonitoringTableStat)
-> Generic MonitoringTableStat
forall x. Rep MonitoringTableStat x -> MonitoringTableStat
forall x. MonitoringTableStat -> Rep MonitoringTableStat x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. MonitoringTableStat -> Rep MonitoringTableStat x
from :: forall x. MonitoringTableStat -> Rep MonitoringTableStat x
$cto :: forall x. Rep MonitoringTableStat x -> MonitoringTableStat
to :: forall x. Rep MonitoringTableStat x -> MonitoringTableStat
Generic)
instance ToJSON MonitoringTableStat where
toJSON :: MonitoringTableStat -> Value
toJSON (MonitoringTableStat Text
name [MonitoringTableEntry]
entries) =
[Pair] -> Value
object
[ Key
"name" Key -> Text -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= Text
name
, Key
"entries" Key -> [MonitoringTableEntry] -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= [MonitoringTableEntry]
entries
]
instance FromJSON MonitoringTableStat where
parseJSON :: Value -> Parser MonitoringTableStat
parseJSON = String
-> (Object -> Parser MonitoringTableStat)
-> Value
-> Parser MonitoringTableStat
forall a. String -> (Object -> Parser a) -> Value -> Parser a
withObject String
"MonitoringTableStat" ((Object -> Parser MonitoringTableStat)
-> Value -> Parser MonitoringTableStat)
-> (Object -> Parser MonitoringTableStat)
-> Value
-> Parser MonitoringTableStat
forall a b. (a -> b) -> a -> b
$ \Object
o ->
Text -> [MonitoringTableEntry] -> MonitoringTableStat
MonitoringTableStat
(Text -> [MonitoringTableEntry] -> MonitoringTableStat)
-> Parser Text
-> Parser ([MonitoringTableEntry] -> MonitoringTableStat)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
o Object -> Key -> Parser Text
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"name"
Parser ([MonitoringTableEntry] -> MonitoringTableStat)
-> Parser [MonitoringTableEntry] -> Parser MonitoringTableStat
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o Object -> Key -> Parser [MonitoringTableEntry]
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"entries"
data MonitoringStats = MonitoringStats
{ MonitoringStats -> Int
msNumTests :: !Int
, MonitoringStats -> Int
msNumDiscarded :: !Int
, MonitoringStats -> [MonitoringLabelStat]
msLabels :: ![MonitoringLabelStat]
, MonitoringStats -> [MonitoringClassStat]
msClasses :: ![MonitoringClassStat]
, MonitoringStats -> [MonitoringTableStat]
msTables :: ![MonitoringTableStat]
}
deriving (MonitoringStats -> MonitoringStats -> Bool
(MonitoringStats -> MonitoringStats -> Bool)
-> (MonitoringStats -> MonitoringStats -> Bool)
-> Eq MonitoringStats
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: MonitoringStats -> MonitoringStats -> Bool
== :: MonitoringStats -> MonitoringStats -> Bool
$c/= :: MonitoringStats -> MonitoringStats -> Bool
/= :: MonitoringStats -> MonitoringStats -> Bool
Eq, Int -> MonitoringStats -> ShowS
[MonitoringStats] -> ShowS
MonitoringStats -> String
(Int -> MonitoringStats -> ShowS)
-> (MonitoringStats -> String)
-> ([MonitoringStats] -> ShowS)
-> Show MonitoringStats
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> MonitoringStats -> ShowS
showsPrec :: Int -> MonitoringStats -> ShowS
$cshow :: MonitoringStats -> String
show :: MonitoringStats -> String
$cshowList :: [MonitoringStats] -> ShowS
showList :: [MonitoringStats] -> ShowS
Show, (forall x. MonitoringStats -> Rep MonitoringStats x)
-> (forall x. Rep MonitoringStats x -> MonitoringStats)
-> Generic MonitoringStats
forall x. Rep MonitoringStats x -> MonitoringStats
forall x. MonitoringStats -> Rep MonitoringStats x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. MonitoringStats -> Rep MonitoringStats x
from :: forall x. MonitoringStats -> Rep MonitoringStats x
$cto :: forall x. Rep MonitoringStats x -> MonitoringStats
to :: forall x. Rep MonitoringStats x -> MonitoringStats
Generic)
instance ToJSON MonitoringStats where
toJSON :: MonitoringStats -> Value
toJSON (MonitoringStats Int
numTests Int
numDiscarded [MonitoringLabelStat]
labels [MonitoringClassStat]
classes [MonitoringTableStat]
tables) =
[Pair] -> Value
object
[ Key
"numTests" Key -> Int -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= Int
numTests
, Key
"numDiscarded" Key -> Int -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= Int
numDiscarded
, Key
"labels" Key -> [MonitoringLabelStat] -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= [MonitoringLabelStat]
labels
, Key
"classes" Key -> [MonitoringClassStat] -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= [MonitoringClassStat]
classes
, Key
"tables" Key -> [MonitoringTableStat] -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= [MonitoringTableStat]
tables
]
instance FromJSON MonitoringStats where
parseJSON :: Value -> Parser MonitoringStats
parseJSON = String
-> (Object -> Parser MonitoringStats)
-> Value
-> Parser MonitoringStats
forall a. String -> (Object -> Parser a) -> Value -> Parser a
withObject String
"MonitoringStats" ((Object -> Parser MonitoringStats)
-> Value -> Parser MonitoringStats)
-> (Object -> Parser MonitoringStats)
-> Value
-> Parser MonitoringStats
forall a b. (a -> b) -> a -> b
$ \Object
o ->
Int
-> Int
-> [MonitoringLabelStat]
-> [MonitoringClassStat]
-> [MonitoringTableStat]
-> MonitoringStats
MonitoringStats
(Int
-> Int
-> [MonitoringLabelStat]
-> [MonitoringClassStat]
-> [MonitoringTableStat]
-> MonitoringStats)
-> Parser Int
-> Parser
(Int
-> [MonitoringLabelStat]
-> [MonitoringClassStat]
-> [MonitoringTableStat]
-> MonitoringStats)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
o Object -> Key -> Parser Int
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"numTests"
Parser
(Int
-> [MonitoringLabelStat]
-> [MonitoringClassStat]
-> [MonitoringTableStat]
-> MonitoringStats)
-> Parser Int
-> Parser
([MonitoringLabelStat]
-> [MonitoringClassStat]
-> [MonitoringTableStat]
-> MonitoringStats)
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o Object -> Key -> Parser Int
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"numDiscarded"
Parser
([MonitoringLabelStat]
-> [MonitoringClassStat]
-> [MonitoringTableStat]
-> MonitoringStats)
-> Parser [MonitoringLabelStat]
-> Parser
([MonitoringClassStat] -> [MonitoringTableStat] -> MonitoringStats)
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o Object -> Key -> Parser [MonitoringLabelStat]
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"labels"
Parser
([MonitoringClassStat] -> [MonitoringTableStat] -> MonitoringStats)
-> Parser [MonitoringClassStat]
-> Parser ([MonitoringTableStat] -> MonitoringStats)
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o Object -> Key -> Parser [MonitoringClassStat]
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"classes"
Parser ([MonitoringTableStat] -> MonitoringStats)
-> Parser [MonitoringTableStat] -> Parser MonitoringStats
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o Object -> Key -> Parser [MonitoringTableStat]
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"tables"
data Event
= SuiteStarted
{ Event -> Maybe Text
esPackageRoot :: !(Maybe Text)
, Event -> [TestInfo]
esTests :: ![TestInfo]
, Event -> [SrcLocRange]
edCoverageIndex :: ![SrcLocRange]
}
| TestStarted
{ Event -> Int
etId :: !Int
}
| TestProgress
{ Event -> Int
epId :: !Int
, Event -> Text
epMessage :: !Text
, Event -> Float
epPercent :: !Float
}
| TestDone
{ Event -> Int
edId :: !Int
, Event -> TestOutcome
edOutcome :: !TestOutcome
, Event -> Double
edDuration :: !Double
, Event -> Text
edDescription :: !Text
, Event -> Maybe ThreatModelSummary
edThreatModel :: !(Maybe ThreatModelSummary)
, Event -> Maybe MonitoringStats
edMonitoringStats :: !(Maybe MonitoringStats)
}
| TestTrace
{ Event -> Int
ettTestId :: !Int
, Event -> Text
ettCategory :: !Text
, Event -> [SrcLocRange]
ettCovered :: ![SrcLocRange]
, Event -> Value
ettTrace :: !Value
}
| SuiteDone
{ Event -> Int
esPassed :: !Int
, Event -> Int
esFailed :: !Int
, Event -> Double
esDuration :: !Double
}
deriving (Event -> Event -> Bool
(Event -> Event -> Bool) -> (Event -> Event -> Bool) -> Eq Event
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Event -> Event -> Bool
== :: Event -> Event -> Bool
$c/= :: Event -> Event -> Bool
/= :: Event -> Event -> Bool
Eq, Int -> Event -> ShowS
[Event] -> ShowS
Event -> String
(Int -> Event -> ShowS)
-> (Event -> String) -> ([Event] -> ShowS) -> Show Event
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> Event -> ShowS
showsPrec :: Int -> Event -> ShowS
$cshow :: Event -> String
show :: Event -> String
$cshowList :: [Event] -> ShowS
showList :: [Event] -> ShowS
Show, (forall x. Event -> Rep Event x)
-> (forall x. Rep Event x -> Event) -> Generic Event
forall x. Rep Event x -> Event
forall x. Event -> Rep Event x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. Event -> Rep Event x
from :: forall x. Event -> Rep Event x
$cto :: forall x. Rep Event x -> Event
to :: forall x. Rep Event x -> Event
Generic)
instance ToJSON Event where
toJSON :: Event -> Value
toJSON (SuiteStarted Maybe Text
mRoot [TestInfo]
ts [SrcLocRange]
ci) =
[Pair] -> Value
object ([Pair] -> Value) -> [Pair] -> Value
forall a b. (a -> b) -> a -> b
$
[ Key
"event" Key -> Text -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= (Text
"suite_started" :: Text)
, Key
"tests" Key -> [TestInfo] -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= [TestInfo]
ts
, Key
"coverageIndex" Key -> [SrcLocRanges] -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= [SrcLocRange] -> [SrcLocRanges]
groupRanges [SrcLocRange]
ci
]
[Pair] -> [Pair] -> [Pair]
forall a. Semigroup a => a -> a -> a
<> [Pair] -> (Text -> [Pair]) -> Maybe Text -> [Pair]
forall b a. b -> (a -> b) -> Maybe a -> b
maybe [] (\Text
r -> [Key
"packageRoot" Key -> Text -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= Text
r]) Maybe Text
mRoot
toJSON (TestStarted Int
i) =
[Pair] -> Value
object
[ Key
"event" Key -> Text -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= (Text
"test_started" :: Text)
, Key
"id" Key -> Int -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= Int
i
]
toJSON (TestProgress Int
i Text
msg Float
pct) =
[Pair] -> Value
object
[ Key
"event" Key -> Text -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= (Text
"test_progress" :: Text)
, Key
"id" Key -> Int -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= Int
i
, Key
"message" Key -> Text -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= Text
msg
, Key
"percent" Key -> Float -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= Float
pct
]
toJSON (TestDone Int
i TestOutcome
outcome Double
dur Text
desc Maybe ThreatModelSummary
mTm Maybe MonitoringStats
mMonitoring) =
[Pair] -> Value
object ([Pair] -> Value) -> [Pair] -> Value
forall a b. (a -> b) -> a -> b
$
[ Key
"event" Key -> Text -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= (Text
"test_done" :: Text)
, Key
"id" Key -> Int -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= Int
i
, Key
"duration" Key -> Double -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= Double
dur
, Key
"description" Key -> Text -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= Text
desc
]
[Pair] -> [Pair] -> [Pair]
forall a. Semigroup a => a -> a -> a
<> TestOutcome -> [Pair]
forall {e} {a}. KeyValue e a => TestOutcome -> [a]
outcomeFields TestOutcome
outcome
[Pair] -> [Pair] -> [Pair]
forall a. Semigroup a => a -> a -> a
<> Maybe ThreatModelSummary -> [Pair]
threatModelFields Maybe ThreatModelSummary
mTm
[Pair] -> [Pair] -> [Pair]
forall a. Semigroup a => a -> a -> a
<> Maybe MonitoringStats -> [Pair]
monitoringFields Maybe MonitoringStats
mMonitoring
where
outcomeFields :: TestOutcome -> [a]
outcomeFields TestOutcome
TestSuccess = [Key
"success" Key -> Bool -> a
forall v. ToJSON v => Key -> v -> a
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= Bool
True]
outcomeFields (TestFailure FailureInfo
fi) =
[ Key
"success" Key -> Bool -> a
forall v. ToJSON v => Key -> v -> a
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= Bool
False
, Key
"failure" Key -> FailureInfo -> a
forall v. ToJSON v => Key -> v -> a
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= FailureInfo
fi
]
threatModelFields :: Maybe ThreatModelSummary -> [Pair]
threatModelFields :: Maybe ThreatModelSummary -> [Pair]
threatModelFields = [Pair]
-> (ThreatModelSummary -> [Pair])
-> Maybe ThreatModelSummary
-> [Pair]
forall b a. b -> (a -> b) -> Maybe a -> b
maybe [] (\ThreatModelSummary
s -> [Key
"threat_model" Key -> ThreatModelSummary -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= ThreatModelSummary
s])
monitoringFields :: Maybe MonitoringStats -> [Pair]
monitoringFields :: Maybe MonitoringStats -> [Pair]
monitoringFields = [Pair]
-> (MonitoringStats -> [Pair]) -> Maybe MonitoringStats -> [Pair]
forall b a. b -> (a -> b) -> Maybe a -> b
maybe [] (\MonitoringStats
s -> [Key
"monitoring_stats" Key -> MonitoringStats -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= MonitoringStats
s])
toJSON (TestTrace Int
i Text
cat [SrcLocRange]
cov Value
trace) =
[Pair] -> Value
object
[ Key
"event" Key -> Text -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= (Text
"test_trace" :: Text)
, Key
"id" Key -> Int -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= Int
i
, Key
"category" Key -> Text -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= Text
cat
, Key
"trace" Key -> Value -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= Value
trace
, Key
"covered" Key -> [SrcLocRanges] -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= [SrcLocRange] -> [SrcLocRanges]
groupRanges [SrcLocRange]
cov
]
toJSON (SuiteDone Int
p Int
f Double
dur) =
[Pair] -> Value
object
[ Key
"event" Key -> Text -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= (Text
"suite_done" :: Text)
, Key
"passed" Key -> Int -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= Int
p
, Key
"failed" Key -> Int -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= Int
f
, Key
"duration" Key -> Double -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= Double
dur
]
instance FromJSON Event where
parseJSON :: Value -> Parser Event
parseJSON = String -> (Object -> Parser Event) -> Value -> Parser Event
forall a. String -> (Object -> Parser a) -> Value -> Parser a
withObject String
"Event" ((Object -> Parser Event) -> Value -> Parser Event)
-> (Object -> Parser Event) -> Value -> Parser Event
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
Text
tag :: Text <- Object
o Object -> Key -> Parser Text
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"event"
case Text
tag of
Text
"suite_started" ->
Maybe Text -> [TestInfo] -> [SrcLocRange] -> Event
SuiteStarted
(Maybe Text -> [TestInfo] -> [SrcLocRange] -> Event)
-> Parser (Maybe Text)
-> Parser ([TestInfo] -> [SrcLocRange] -> Event)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
o Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"packageRoot"
Parser ([TestInfo] -> [SrcLocRange] -> Event)
-> Parser [TestInfo] -> Parser ([SrcLocRange] -> Event)
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o Object -> Key -> Parser [TestInfo]
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"tests"
Parser ([SrcLocRange] -> Event)
-> Parser [SrcLocRange] -> Parser Event
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ([SrcLocRanges] -> [SrcLocRange]
ungroupRanges ([SrcLocRanges] -> [SrcLocRange])
-> Parser [SrcLocRanges] -> Parser [SrcLocRange]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
o Object -> Key -> Parser [SrcLocRanges]
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"coverageIndex")
Text
"test_started" ->
Int -> Event
TestStarted (Int -> Event) -> Parser Int -> Parser Event
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
o Object -> Key -> Parser Int
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"id"
Text
"test_progress" ->
Int -> Text -> Float -> Event
TestProgress
(Int -> Text -> Float -> Event)
-> Parser Int -> Parser (Text -> Float -> Event)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
o Object -> Key -> Parser Int
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"id"
Parser (Text -> Float -> Event)
-> Parser Text -> Parser (Float -> Event)
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o Object -> Key -> Parser Text
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"message"
Parser (Float -> Event) -> Parser Float -> Parser Event
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o Object -> Key -> Parser Float
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"percent"
Text
"test_done" -> do
Int
eid <- Object
o Object -> Key -> Parser Int
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"id"
Double
dur <- Object
o Object -> Key -> Parser Double
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"duration"
Text
desc <- Object
o Object -> Key -> Parser Text
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"description"
Bool
success <- Object
o Object -> Key -> Parser Bool
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"success"
TestOutcome
outcome <-
if Bool
success
then TestOutcome -> Parser TestOutcome
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure TestOutcome
TestSuccess
else FailureInfo -> TestOutcome
TestFailure (FailureInfo -> TestOutcome)
-> Parser FailureInfo -> Parser TestOutcome
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
o Object -> Key -> Parser FailureInfo
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"failure"
Maybe ThreatModelSummary
mTm <- Object
o Object -> Key -> Parser (Maybe ThreatModelSummary)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"threat_model"
Maybe MonitoringStats
mMonitoring <- Object
o Object -> Key -> Parser (Maybe MonitoringStats)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"monitoring_stats"
Event -> Parser Event
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Int
-> TestOutcome
-> Double
-> Text
-> Maybe ThreatModelSummary
-> Maybe MonitoringStats
-> Event
TestDone Int
eid TestOutcome
outcome Double
dur Text
desc Maybe ThreatModelSummary
mTm Maybe MonitoringStats
mMonitoring)
Text
"test_trace" ->
Int -> Text -> [SrcLocRange] -> Value -> Event
TestTrace
(Int -> Text -> [SrcLocRange] -> Value -> Event)
-> Parser Int -> Parser (Text -> [SrcLocRange] -> Value -> Event)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
o Object -> Key -> Parser Int
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"id"
Parser (Text -> [SrcLocRange] -> Value -> Event)
-> Parser Text -> Parser ([SrcLocRange] -> Value -> Event)
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o Object -> Key -> Parser Text
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"category"
Parser ([SrcLocRange] -> Value -> Event)
-> Parser [SrcLocRange] -> Parser (Value -> Event)
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ([SrcLocRanges] -> [SrcLocRange]
ungroupRanges ([SrcLocRanges] -> [SrcLocRange])
-> Parser [SrcLocRanges] -> Parser [SrcLocRange]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
o Object -> Key -> Parser [SrcLocRanges]
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"covered")
Parser (Value -> Event) -> Parser Value -> Parser Event
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o Object -> Key -> Parser Value
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"trace"
Text
"suite_done" ->
Int -> Int -> Double -> Event
SuiteDone
(Int -> Int -> Double -> Event)
-> Parser Int -> Parser (Int -> Double -> Event)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
o Object -> Key -> Parser Int
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"passed"
Parser (Int -> Double -> Event)
-> Parser Int -> Parser (Double -> Event)
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o Object -> Key -> Parser Int
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"failed"
Parser (Double -> Event) -> Parser Double -> Parser Event
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o Object -> Key -> Parser Double
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"duration"
Text
other -> String -> Parser Event
forall a. String -> Parser a
forall (m :: * -> *) a. MonadFail m => String -> m a
fail (String
"Unknown event tag: " String -> ShowS
forall a. Semigroup a => a -> a -> a
<> Text -> String
forall a. Show a => a -> String
show Text
other)