Commit eea22acb authored by Steffen Michels's avatar Steffen Michels

add test event types & JSON instances

parent 28c03539
Pipeline #9331 passed with stage
in 2 minutes and 16 seconds
definition module Testing.TestEvents
/**
* This module provides types representing events occurring during a test run.
* Each Clean testing framework should report such events on StdOut, as JSON
* representation of the event types provided here. The test runners
* (https://gitlab.science.ru.nl/clean-and-itasks/clean-test) process the
* events further.
*/
from Text.JSON import generic JSONEncode, generic JSONDecode, :: JSONNode, :: Maybe
/**
* Event emitted when a test is started.
* A Specialised JSONEncode instance is used for this type, which
* has to be adapted in case the type definition is changed!
*/
:: StartEvent = { name :: !String
}
/**
* Event emitted after a test has finished.
*/
:: EndEvent = { name :: !String
, event :: !EndEventType
, message :: !String
}
/**
* Indicating the type an end event, indicating whether the test was
* successful or not.
* Specialised JSONEncode/JSONDecode instances are used for this type, which
* have to be adapted in case the type definition is changed!
*/
:: EndEventType = Passed | Failed | Skipped
derive JSONEncode StartEvent, EndEvent
derive JSONDecode StartEvent, EndEvent
implementation module Testing.TestEvents
import Text.JSON
JSONEncode{|StartEvent|} _ startEvent = [ JSONObject [ ("name", JSONString startEvent.StartEvent.name)
, ("event", JSONString "start")
]
]
JSONEncode{|EndEventType|} _ eType = [JSONString eTypeStr]
where
eTypeStr = case eType of
Passed -> "passed"
Failed -> "failed"
Skipped -> "skipped"
JSONDecode{|EndEventType|} _ [JSONString eTypeStr : rest] = (mbEType, rest)
where
mbEType = case eTypeStr of
"passed" -> Just Passed
"failed" -> Just Failed
"skipped" -> Just Skipped
_ -> Nothing
JSONDecode{|EndEventType|} _ nodes = (Nothing, nodes)
derive JSONEncode EndEvent
derive JSONDecode StartEvent, EndEvent
......@@ -154,5 +154,6 @@ import qualified Text.Unicode.Encodings.UTF8
import qualified Text.Unicode.UChar
import qualified Text.URI
import qualified Text.XML
import qualified Testing.TestEvents
Start = "Hello World!"
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