Commit 876c9146 authored by Camil Staps's avatar Camil Staps 🐧

Merge branch '19-platform-needs-a-test-framework' into 'master'

Resolve "Platform needs a test framework"

Closes #19

See merge request !103
parents 5455d800 994a66dd
Pipeline #9367 passed with stage
in 1 minute and 48 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.
* 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
}
/**
* 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
}
/**
* 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 //* The test passed
| Failed //* The test failed
| Skipped //* The test was not executed, but should be executed and pass for future versions
derive JSONEncode StartEvent, EndEvent
derive JSONDecode StartEvent, EndEvent
implementation module Testing.TestEvents
import Text.JSON, Control.Monad, StdFunc, StdTuple, StdList, Data.Maybe, Control.Applicative
JSONEncode{|StartEvent|} _ startEvent = [ JSONObject [ ("name", JSONString startEvent.StartEvent.name)
, ("event", JSONString "start")
]
]
JSONDecode{|StartEvent|} _ [JSONObject objFields : rest] = (mbEvent, rest)
where
mbEvent :: Maybe StartEvent
mbEvent = getField "name" >>= \name ->
getField "event" >>= \event ->
if (event == "start")
(pure {StartEvent | name = name})
mzero
getField :: String -> Maybe a | JSONDecode{|*|} a
getField fieldName = case filter ((==) fieldName o fst) objFields of
[(_, jsonNode)] -> fromJSON jsonNode
_ -> mzero
JSONDecode{|StartEvent|} _ _ = (Nothing, [])
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 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