Verified Commit 60386dc5 authored by Camil Staps's avatar Camil Staps 🚀

Add optional module name to TestEvents

parent b3c4de5a
......@@ -24,14 +24,16 @@ from Text.GenJSON import generic JSONEncode, generic JSONDecode, :: JSONNode, ::
* Specialised JSONEncode/JSONDecode instances are used for this type, which
* have to be adapted in case the type definition is changed!
*/
:: StartEvent = { name :: !String //* The test's name
:: StartEvent = { name :: !String //* The test's name
, module_name :: !Maybe String //* The module to which the test belongs
}
/**
* Event emitted after a test has finished.
*/
:: EndEvent = { name :: !String //* The test's name
, event :: !EndEventType //* The event's type, indicating success
, message :: !String //* Message providing an explanation for the result
:: EndEvent = { name :: !String //* The test's name
, module_name :: !Maybe String //* The module to which the test belongs
, event :: !EndEventType //* The event's type, indicating success
, message :: !String //* Message providing an explanation for the result
}
/**
......
......@@ -13,10 +13,13 @@ JSONDecode{|TestEvent|} b json = case JSONDecode{|*|} b json of
(Just ee, json) -> (Just (EndEvent ee), json)
(Nothing, json) -> (Nothing, json)
JSONEncode{|StartEvent|} _ startEvent = [ JSONObject [ ("name", JSONString startEvent.StartEvent.name)
, ("event", JSONString "start")
]
]
JSONEncode{|StartEvent|} _ startEvent = [ JSONObject
[ ("name", JSONString startEvent.StartEvent.name)
, ("event", JSONString "start")
: case startEvent.StartEvent.module_name of
Nothing -> []
Just m -> [("module",JSONString m)]
]]
JSONDecode{|StartEvent|} _ [JSONObject objFields : rest] = (mbEvent, rest)
where
......@@ -24,7 +27,7 @@ where
mbEvent = getField "name" >>= \name ->
getField "event" >>= \event ->
if (event == "start")
(pure {StartEvent | name = name})
(pure {StartEvent | name = name, module_name = getField "module"})
mzero
getField :: String -> Maybe a | JSONDecode{|*|} a
......@@ -35,7 +38,10 @@ JSONEncode{|EndEvent|} _ endEvent = [JSONObject
[ ("name", JSONString endEvent.EndEvent.name)
, ("message", JSONString endEvent.message)
, ("event", JSONString (typeToString endEvent.event))
: case endEvent.event of
: case endEvent.EndEvent.module_name of
Nothing -> []
Just m -> [("module",JSONString m)]
++ case endEvent.event of
Failed (Just r) -> [("failReason", case JSONEncode{|*|} False r of
[JSONArray r] -> JSONArray r
r -> JSONArray r)]
......@@ -54,7 +60,7 @@ where
getField "name" >>= \name ->
getField "event" >>= \event ->
getField "message" >>= \message ->
let e = {name=name, message=message, event=Passed} in case event of
let e = {name=name, message=message, event=Passed, module_name=getField "module"} in case event of
"passed" -> pure e
"failed" -> pure {e & event = Failed $ getField "failReason"}
"skipped" -> pure {e & event=Skipped}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment